How to Set Page Title in Remix: Simple Guide
In Remix, set the page title by exporting a
meta function from your route module that returns an object with a title property. Remix uses this to render the <title> tag inside the HTML <head> automatically.Syntax
To set the page title in Remix, export a meta function from your route file. This function returns an object with a title key whose value is the string you want as the page title.
Remix uses this meta function to insert the <title> tag inside the HTML <head> when rendering the page.
javascript
export const meta = () => { return { title: "Your Page Title Here" }; };
Example
This example shows a simple Remix route that sets the page title to "Welcome to Remix" using the meta export.
javascript
import { json } from "@remix-run/node"; export const meta = () => { return { title: "Welcome to Remix" }; }; export const loader = () => { return json({ message: "Hello from Remix!" }); }; export default function Index() { return <h1>Hello from Remix!</h1>; }
Output
<title>Welcome to Remix</title>
<h1>Hello from Remix!</h1>
Common Pitfalls
Not exporting the meta function: Without exporting meta, Remix won't set the page title automatically.
Returning incorrect structure: The meta function must return an object with a title key, not a string or array.
Overriding title in nested routes: Nested routes can override titles by exporting their own meta functions, so be mindful of route hierarchy.
javascript
/* Wrong way: returning a string instead of an object */ export const meta = () => "My Title"; /* Right way: returning an object with title key */ export const meta = () => ({ title: "My Title" });
Quick Reference
export const meta = () => ({ title: "Page Title" });sets the page title.- Use this in each route file to customize titles per page.
- Remix automatically injects the
<title>tag in the HTML<head>. - For dynamic titles, you can use loader data inside
metaby exportingmetaas a function with parameters.
Key Takeaways
Always export a meta function returning an object with a title key to set the page title in Remix.
The meta function runs on the server and controls the HTML tag automatically.
Nested routes can override titles by exporting their own meta functions.
Return an object from meta, not a string or other type.
Use loader data in meta for dynamic page titles if needed.