How do layouts work in Blazor, and what are the roles of @layout, LayoutComponentBase, and the @Body placeholder?

Last updated 5 July 2026

Layouts let you define shared shell markup (nav, header, footer) once and wrap page content inside it: a layout is a component that inherits LayoutComponentBase and renders its page via @Body, while pages opt in with @layout.

  • LayoutComponentBase: The base class every layout inherits; it supplies a Body parameter of type RenderFragment.

  • @Body: The placeholder in the layout markup where the routed page's content is rendered.

  • @layout: A directive placed in a page (or in _Imports.razor for a whole folder) to select which layout wraps it.

  • Applying layouts globally: The Router's RouteView takes a DefaultLayout, so pages without an explicit @layout still get one.

  • Nesting: A layout can itself declare @layout to nest inside another layout.

[lang:razor] @* MainLayout.razor *@ @inherits LayoutComponentBase <nav>...</nav> <main>@Body</main> @* SomePage.razor *@ @page "/some" @layout MainLayout

  • https://www.telerik.com/blogs/blazor-basics-working-blazor-layouts
  • https://chrissainty.com/blazor-bites-layouts/
  • https://learn.microsoft.com/en-us/aspnet/core/blazor/components/layouts?view=aspnetcore-10.0
  • https://www.learnblazor.com/layouts
  • https://www.luisllamas.es/en/blazor-layouts-master-templates/
  • https://blazor-university.com/layouts/nested-layouts/
All Blazor interview questions