Skip to content

Title & Meta

The Basics

Title & Meta

Since Inertia-powered JavaScript apps are rendered within the document <body>, they are unable to render markup to the document <head>, as it's outside of their scope. To help with this, Inertia ships with a <Head> component which can be used to set the page <title>, <meta> tags, and other <head> elements.

The <Head> component will only replace <head> elements that are not in your server-side root template.

The <Head> component is not available in the Svelte adapter, as Svelte already ships with its own <svelte:head> component.

Head Component

To add <head> elements to your page, use the <Head> component. Within this component, you can include the elements that you wish to add to the document <head>.

1import { Head } from '@inertiajs/vue3'
2 
3<Head>
4 <title>Your page title</title>
5 <meta name="description" content="Your page description">
6</Head>
1import { Head } from '@inertiajs/vue3'
2 
3<Head>
4 <title>Your page title</title>
5 <meta name="description" content="Your page description">
6</Head>
1import { Head } from "@inertiajs/react";
2 
3<Head>
4 <title>Your page title</title>
5 <meta name="description" content="Your page description" />
6</Head>;
1import { Head } from "@inertiajs/react";
2 
3<Head>
4 <title>Your page title</title>
5 <meta name="description" content="Your page description" />
6</Head>;
1<svelte:head>
2 <title>Your page title</title>
3 <meta name="description" content="Your page description" />
4</svelte:head>
1<svelte:head>
2 <title>Your page title</title>
3 <meta name="description" content="Your page description" />
4</svelte:head>

Title Shorthand

If you only need to add a <title> to the document <head>, you may simply pass the title as a prop to the <Head> component.

1import { Head } from '@inertiajs/vue3'
2 
3<Head title="Your page title" />
1import { Head } from '@inertiajs/vue3'
2 
3<Head title="Your page title" />
1import { Head } from "@inertiajs/react";
2 
3<Head title="Your page title" />;
1import { Head } from "@inertiajs/react";
2 
3<Head title="Your page title" />;
1// Not supported
1// Not supported

Title Callback

You can globally modify the page <title> using the title callback in the createInertiaApp setup method. Typically, this method is invoked in your application's main JavaScript file. A common use case for the title callback is automatically adding an app name before or after each page title.

1createInertiaApp({
2 title: (title) => `${title} - My App`,
3 // ...
4});
1createInertiaApp({
2 title: (title) => `${title} - My App`,
3 // ...
4});

The callback also receives the current page object as its second argument, which you may use to build titles from the page's props.

1createInertiaApp({
2 title: (title, page) => `${title} - ${page.props.appName}`,
3 // ...
4});
1createInertiaApp({
2 title: (title, page) => `${title} - ${page.props.appName}`,
3 // ...
4});

After defining the title callback, the callback will automatically be invoked when you set a title using the <Head> component.

1import { Head } from '@inertiajs/vue3'
2 
3<Head title="Home">
1import { Head } from '@inertiajs/vue3'
2 
3<Head title="Home">
1import { Head } from '@inertiajs/react'
2 
3<Head title="Home">
1import { Head } from '@inertiajs/react'
2 
3<Head title="Home">
1// Not supported
1// Not supported

In this example, this results in the following <title> tag.

1<title>Home - My App</title>
1<title>Home - My App</title>

The title callback will also be invoked when you set the title using a <title> tag within your <Head> component.

1import { Head } from '@inertiajs/vue3'
2 
3<Head>
4 <title>Home</title>
5</Head>
1import { Head } from '@inertiajs/vue3'
2 
3<Head>
4 <title>Home</title>
5</Head>
1import { Head } from "@inertiajs/react";
2 
3<Head>
4 <title>Home</title>
5</Head>;
1import { Head } from "@inertiajs/react";
2 
3<Head>
4 <title>Home</title>
5</Head>;
1// Not supported
1// Not supported

Multiple Head Instances

It's possible to have multiple instances of the <Head> component throughout your application. For example, your layout can set some default <Head> elements, and then your individual pages can override those defaults.

1// Layout.vue import { Head } from '@inertiajs/vue3'
2 
3<Head>
4 <title>My app</title>
5 <meta head-key="description" name="description" content="This is the default description" />
6 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7</Head>
8 
9// About.vue import { Head } from '@inertiajs/vue3'
10 
11<Head>
12 <title>About - My app</title>
13 <meta head-key="description" name="description" content="This is a page specific description" />
14</Head>
1// Layout.vue import { Head } from '@inertiajs/vue3'
2 
3<Head>
4 <title>My app</title>
5 <meta head-key="description" name="description" content="This is the default description" />
6 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7</Head>
8 
9// About.vue import { Head } from '@inertiajs/vue3'
10 
11<Head>
12 <title>About - My app</title>
13 <meta head-key="description" name="description" content="This is a page specific description" />
14</Head>
1// Layout.js
2 
3import { Head } from "@inertiajs/react";
4 
5<Head>
6 <title>My app</title>
7 <meta
8 head-key="description"
9 name="description"
10 content="This is the default description"
11 />
12 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
13</Head>;
14 
15// About.js
16 
17import { Head } from "@inertiajs/react";
18 
19<Head>
20 <title>About - My app</title>
21 <meta
22 head-key="description"
23 name="description"
24 content="This is a page specific description"
25 />
26</Head>;
1// Layout.js
2 
3import { Head } from "@inertiajs/react";
4 
5<Head>
6 <title>My app</title>
7 <meta
8 head-key="description"
9 name="description"
10 content="This is the default description"
11 />
12 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
13</Head>;
14 
15// About.js
16 
17import { Head } from "@inertiajs/react";
18 
19<Head>
20 <title>About - My app</title>
21 <meta
22 head-key="description"
23 name="description"
24 content="This is a page specific description"
25 />
26</Head>;
1// Not supported
1// Not supported

Inertia will only ever render one <title> tag; however, all other tags will be stacked since it's valid to have multiple instances of them. To avoid duplicate tags in your <head>, you can use the head-key property, which will make sure the tag is only rendered once. This is illustrated in the example above for the <meta name="description"> tag.

The code example above will render the following HTML.

1<head>
2 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
3 <title>About - My app</title>
4 <meta name="description" content="This is a page specific description" />
5</head>
1<head>
2 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
3 <title>About - My app</title>
4 <meta name="description" content="This is a page specific description" />
5</head>

Head Extension

When building a real application, it can sometimes be helpful to create a custom head component that extends Inertia's <Head> component. This gives you a place to set app-wide defaults, such as appending the app name to the page title.

1<!-- AppHead.vue -->
2 
3<script setup>
4import { Head } from "@inertiajs/vue3";
5 
6defineProps({ title: String });
7</script>
8 
9<template>
10 <Head :title="title ? `${title} - My App` : 'My App'">
11 <slot />
12 </Head>
13</template>
1<!-- AppHead.vue -->
2 
3<script setup>
4import { Head } from "@inertiajs/vue3";
5 
6defineProps({ title: String });
7</script>
8 
9<template>
10 <Head :title="title ? `${title} - My App` : 'My App'">
11 <slot />
12 </Head>
13</template>
1// AppHead.js
2 
3import { Head } from "@inertiajs/react";
4 
5const Site = ({ title, children }) => {
6 return (
7 <Head>
8 <title>{title ? `${title} - My App` : "My App"}</title>
9 {children}
10 </Head>
11 );
12};
13 
14export default Site;
1// AppHead.js
2 
3import { Head } from "@inertiajs/react";
4 
5const Site = ({ title, children }) => {
6 return (
7 <Head>
8 <title>{title ? `${title} - My App` : "My App"}</title>
9 {children}
10 </Head>
11 );
12};
13 
14export default Site;
1// Not supported
1// Not supported

Once you have created the custom component, you can just start using it in your pages.

1import AppHead from './AppHead'
2 
3<AppHead title="About" />
1import AppHead from './AppHead'
2 
3<AppHead title="About" />
1import AppHead from './AppHead'
2 
3<AppHead title="About">
1import AppHead from './AppHead'
2 
3<AppHead title="About">
1// Not supported
1// Not supported

Server-Side Head Elements

You may wish to include default head elements like <title> or <meta> tags in your root template. This creates two challenges: preventing duplicates when SSR is active, and ensuring the client-side <Head> component may replace them during navigation.

SSR Fallback

In Laravel PHP, the <x-inertia::head> Blade component accepts fallback content via its slot. This content is only rendered in the initial HTML when SSR is not active. When SSR is active, the <Head> component already provides these elements as part of the server-rendered response, so the fallback is skipped.

resources/views/app.blade.php
1<head>
2 @vite('resources/js/app.js')
3 <x-inertia::head>
4 <title>{{ config('app.name') }}</title>
5 <meta name="description" content="My application description">
6 </x-inertia::head>
7</head>
1<head>
2 @vite('resources/js/app.js')
3 <x-inertia::head>
4 <title>{{ config('app.name') }}</title>
5 <meta name="description" content="My application description">
6 </x-inertia::head>
7</head>

Server-Managed Head (Laravel Rust)

In Laravel Rust, you can manage document head metadata directly on the server using laravel::head. Your root template renders the head with {{ inertia_head }}, and createInertiaApp receives serverHead: true so Inertia updates the document head from the server-provided head prop on every navigation.

1use laravel::head::{self, Head};
2use laravel::inertia::{self, Page, props};
3 
4use crate::models::Product;
5 
6pub async fn show(product: Product) -> Page {
7 head::merge(Head::new().title(&product.name).description(&product.summary));
8 
9 inertia::render("Products/Show", props! { product })
10}
1use laravel::head::{self, Head};
2use laravel::inertia::{self, Page, props};
3 
4use crate::models::Product;
5 
6pub async fn show(product: Product) -> Page {
7 head::merge(Head::new().title(&product.name).description(&product.summary));
8 
9 inertia::render("Products/Show", props! { product })
10}

The data-inertia Attribute

The client-side <Head> component tracks the elements it manages by marking them with a data-inertia attribute. By default, it leaves any other tags in your root template untouched. Since there may only be one <title> tag, the <Head> component will always replace it. Other elements like <meta> and <link> may have multiple instances, so the component needs a way to identify which ones it should manage.

You may add the data-inertia attribute to elements in your root template to have the <Head> component adopt them. On the first client-side navigation, it will match these elements by key and replace or remove them as needed.

resources/views/app.blade.php
1<head>
2 @vite('resources/js/app.js')
3 <title>{{ config('app.name') }}</title>
4 <meta data-inertia="description" name="description" content="My application description">
5</head>
1<head>
2 @vite('resources/js/app.js')
3 <title>{{ config('app.name') }}</title>
4 <meta data-inertia="description" name="description" content="My application description">
5</head>
resources/views/app.html
1<head>
2 {{ vite("resources/js/app.tsx", "resources/js/pages/" ~ page.component ~ ".tsx") }}
3 <title>My App</title>
4 <meta data-inertia="description" name="description" content="My application description">
5</head>
1<head>
2 {{ vite("resources/js/app.tsx", "resources/js/pages/" ~ page.component ~ ".tsx") }}
3 <title>My App</title>
4 <meta data-inertia="description" name="description" content="My application description">
5</head>

The data-inertia value corresponds to the head-key property on your client-side <Head> elements.