---
title: Control head content in ASP.NET Core Blazor apps
author: guardrex
description: Learn how to control head content in Blazor apps, including how to set the page title from a component.
monikerRange: '>= aspnetcore-6.0'
ms.author: riande
ms.custom: mvc
ms.date: 11/12/2024
uid: blazor/components/control-head-content
---
# Control `
` content in ASP.NET Core Blazor apps
[!INCLUDE[](~/includes/not-latest-version.md)]
Razor components can modify the HTML `` element content of a page, including setting the page's title (`` element) and modifying metadata (`` elements).
## Control `` content in a Razor component
Specify the page's title with the component, which enables rendering an HTML `` element to a [`HeadOutlet` component](#headoutlet-component).
Specify `` element content with the component, which provides content to a [`HeadOutlet` component](#headoutlet-component).
The following example sets the page's title and description using Razor.
`ControlHeadContent.razor`:
:::moniker range=">= aspnetcore-9.0"
:::code language="razor" source="~/../blazor-samples/9.0/BlazorSample_BlazorWebApp/Components/Pages/ControlHeadContent.razor":::
:::moniker-end
:::moniker range=">= aspnetcore-8.0 < aspnetcore-9.0"
:::code language="razor" source="~/../blazor-samples/8.0/BlazorSample_BlazorWebApp/Components/Pages/ControlHeadContent.razor":::
:::moniker-end
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
:::code language="razor" source="~/../blazor-samples/7.0/BlazorSample_WebAssembly/Pages/control-head-content/ControlHeadContent.razor":::
:::moniker-end
:::moniker range="< aspnetcore-7.0"
:::code language="razor" source="~/../blazor-samples/6.0/BlazorSample_WebAssembly/Pages/control-head-content/ControlHeadContent.razor":::
:::moniker-end
:::moniker range="< aspnetcore-7.0"
## Control `` content during prerendering
*This section applies to prerendered Blazor WebAssembly apps and Blazor Server apps.*
When Razor components are prerendered, the use of a layout page (`_Layout.cshtml`) is required to control `` content with the and components. The reason for this requirement is that components that control `` content must be rendered before the layout with the component. **This order of rendering is required to control head content.**
If the shared `_Layout.cshtml` file doesn't have a [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper) for a component, add it to the `` elements.
In a **required**, shared `_Layout.cshtml` file of a Blazor Server app or Razor Pages/MVC app that embeds components into pages or views:
```cshtml
```
In a **required**, shared `_Layout.cshtml` file of a prerendered hosted Blazor WebAssembly app:
```cshtml
```
:::moniker-end
## Set a page title for components via a layout
Set the page title in a [layout component](xref:blazor/components/layouts):
```razor
@inherits LayoutComponentBase
Page Title
...
```
## `HeadOutlet` component
The component renders content provided by and components.
:::moniker range=">= aspnetcore-8.0"
In a Blazor Web App created from the project template, the component in `App.razor` renders `` content:
```razor
...
```
:::moniker-end
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
In Blazor Server apps created from the Blazor Server project template, a [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper) renders `` content for the component in `Pages/_Host.cshtml`:
```cshtml
...
```
:::moniker-end
:::moniker range="< aspnetcore-7.0"
In Blazor Server apps created from the Blazor Server project template, a [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper) renders `` content for the component in `Pages/_Layout.cshtml`:
```cshtml
...
```
:::moniker-end
In an app created from the Blazor WebAssembly project template, the component is added to the collection of the in the client-side `Program` file:
```csharp
builder.RootComponents.Add("head::after");
```
When the [`::after` pseudo-selector](https://developer.mozilla.org/docs/Web/CSS/::after) is specified, the contents of the root component are appended to the existing head contents instead of replacing the content. This allows the app to retain static head content in `wwwroot/index.html` without having to repeat the content in the app's Razor components.
:::moniker range=">= aspnetcore-8.0"
## Set a default page title in a Blazor Web App
Set the page title in the `App` component (`App.razor`):
```razor
...
Page Title
```
:::moniker-end
## Not found page title in a Blazor WebAssembly app
:::moniker range=">= aspnetcore-8.0"
In Blazor apps created from the Blazor WebAssembly Standalone App project template, the `NotFound` component template in the `App` component (`App.razor`) sets the page title to `Not found`.
:::moniker-end
:::moniker range="< aspnetcore-8.0"
In Blazor apps created from a Blazor project template, the `NotFound` component template in the `App` component (`App.razor`) sets the page title to `Not found`.
:::moniker-end
`App.razor`:
```razor
Not found
...
```
## Additional resources
* [Control headers in C# code at startup](xref:blazor/fundamentals/startup#control-headers-in-c-code)
* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples) ([how to download](xref:blazor/fundamentals/index#sample-apps))
Mozilla MDN Web Docs documentation:
* [What's in the head? Metadata in HTML](https://developer.mozilla.org/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML)
* [``: The Document Metadata (Header) element](https://developer.mozilla.org/docs/Web/HTML/Element/head)
* [``: The Document Title element](https://developer.mozilla.org/docs/Web/HTML/Element/title)
* [``: The metadata element](https://developer.mozilla.org/docs/Web/HTML/Element/meta)