# Document Metadata

> The document metadata support in React allows rendering `<title>`, `<meta>` and `<link>` tags directly inside components.

## How do I set the page title and meta tags in React?

The built-in support for rendering `<title>`, `<meta>` and `<link>` tags anywhere in the component tree. React automatically hoists them to the `<head>` of the document, both on the client and during server rendering.

- Topic: Basics
- Type: concept

## Example

Wrong:

```jsx
function Post({ post }) {
  useEffect(() => {
    document.title = post.title;
  }, [post.title]);
  return <article>{post.body}</article>;
}
```

Right:

```jsx
function Post({ post }) {
  return (
    <article>
      <title>{post.title}</title>
      <meta name="description" content={post.excerpt} />
      {post.body}
    </article>
  );
}
```

React hoists `<title>` and `<meta>` into `<head>`, so they also work in server-rendered HTML, where Effects never run.

## Common mistakes

- Writing `<title>Hello {name}</title>`, which gives the title several children and triggers a warning.

## Key points

- `<title>`, `<meta>` and `<link>` render inside components, without third-party head libraries or `document.title` effects.
- `<title>` gets a single string, e.g. one template literal, not text mixed with JSX expressions.
- Stylesheet `<link>` tags set `precedence` so React hoists and orders them.

## Interview questions

### Do I still need a head management library in React?

For simple titles and meta tags, no. A library or framework API still helps with merging and overriding tags across nested routes.

### Can I render a stylesheet link inside a component?

Yes. With a `precedence` prop, React hoists the `<link>` to `<head>`, deduplicates it and waits for it to load before showing the content.

## Related cards

- [`<title>`](https://wonderium.dev/html/title.md)
- [`<meta>`](https://wonderium.dev/html/meta.md)
- [`<link>`](https://wonderium.dev/html/link.md)
- [SEO](https://wonderium.dev/web/seo.md)
- [OpenGraph](https://wonderium.dev/web/opengraph.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/document-metadata
- Last updated: 2026-11-25
