Skip to content
Tutorials Center
My learning

Topics

React Reference ยท Built-in DOM Components

The React title element

Reference for the React title element: render it in any component to set document.title, pass a single string, and understand what happens with several titles.

In React 19 you can render <title> from any component and React moves it into the document's <head> for you. Before this, you set document.title by hand in an effect, or used a library. Now the component that owns a page can declare its own title as part of its JSX, next to the content it describes.

The title follows the component's life. It appears when the component mounts, updates when its props or state change, and disappears when the component unmounts. In a server render, the title is placed in the head of the streamed or prerendered HTML so crawlers and the first paint see it.

JSX
function ProductPage({ name }) {
  return (
    <article>
      <title>{`${name} | Shop`}</title>
      <h1>{name}</h1>
    </article>
  );
}

Try it

A title that follows state
The newest mounted title wins

Syntax

JSX
<title>{string}</title>
Name Description
children The title text. A single string, or a number. Build it with a template literal.

<title> also accepts the global attributes, but they are rarely useful. An itemProp title, or a <title> inside an <svg>, is not hoisted: it stays where it is, because inside SVG it is the accessible name of the graphic.

Returns: nothing in the component's own DOM position. The element lands in document.head.

Edge cases: passing several children, as in <title>Page {n}</title>, gives React an array of two items, and the client renders an empty title element. Always pass one string: a template literal such as {`Page ${n}`}.

Usage notes

  • One string only. JSX splits Page {n} into separate pieces, and the title ends up empty. Use a template literal or string concatenation.
  • Several titles are allowed. React does not merge or deduplicate them. In the current implementation the newest mounted <title> goes first in the head, and document.title reads the first one, so the most recently mounted wins. When it unmounts, the earlier title is current again. This makes nested overrides work, but do not depend on it for two siblings that mount together.
  • Not hoisted in some places. A title with itemProp, or inside <svg>, is rendered where it is.
  • Server rendering. When the server renders a whole document (<html>), the title is placed in the <head> of the HTML, so crawlers and the first paint see it without client JavaScript. Rendering only a fragment puts the title in front of the markup.
  • Hydration. The server-rendered title must match the client's, or React reports a mismatch.
  • Accessibility and SEO. A distinct, specific title per page matters for screen-reader users (it is announced on load) and for search results. Put the most important words first.
  • Old approach. useEffect(() => { document.title = ... }, []) still works but is later than the first paint and invisible to crawlers that do not run JavaScript. Prefer <title> where your React version supports it.
  • Framework helpers. Many frameworks offer their own metadata API (for example, a file-based or function-based one). Those can be a better fit than hand-placing <title> in components.