Skip to content
Tutorials Center
My learning

Topics

React Reference ยท react-dom Resource and Form APIs

Hoisted title, meta and link in React

Reference for React 19 document metadata: render title, meta and link tags in any component and React moves them into the head. Rules, limits and pitfalls.

In React 19 you can render <title>, <meta> and <link> elements from any component, next to the content they describe, and React places them in the document's <head>. This is called hoisting. The page title belongs to the page component, the description to the same component, the canonical URL too; there is no need for a separate head-management library or an effect that writes to document.title.

It works on the client, with server rendering and with streaming. When the component unmounts (say, the user navigates to another page), the tags it contributed are removed or replaced, so the head always matches what is on screen.

JSX
function BlogPost({ post }) {
  return (
    <article>
      <title>{post.title}</title>
      <meta name="description" content={post.summary} />
      <link rel="canonical" href={post.url} />
      <h1>{post.title}</h1>
    </article>
  );
}

Try it

Each page sets its own head

Switch pages: the title and description change, and the canonical link appears only on the About page, because the tags follow the component that rendered them.

What is hoisted and what stays

The report lists title, meta name, link canonical and script async as moved to the head; the itemProp meta, the stylesheet that has an onLoad handler and the plain <style> remain where you wrote them.

Syntax

JSX
<title>Text only</title>
<meta name="..." content="..." />
<link rel="..." href="..." />
Element Rule
<title> Hoisted. The children must be a single string (or number). Build it with a template literal.
<meta> Hoisted, unless it has itemProp (microdata describes the surrounding content, so it stays).
<link> Hoisted, unless it has itemProp, onLoad, onError, or is a stylesheet without precedence. rel="stylesheet" with precedence has extra behavior; see Stylesheet precedence.
<script async src> Hoisted and deduplicated by src. A script without async is not.
<style> Hoisted only with both href and precedence. Otherwise it stays.

Returns: these are ordinary JSX elements; nothing is returned.

Errors / edge cases: a <title> with several children, such as <title>Post {id}</title>, receives an array and ends up empty. Write <title>{Post ${id}}</title>.

Usage notes

  • One title. The browser uses the first <title> in the document. Rendering two at once leaves both in the head, so do it from one component per screen, normally the page component.
  • No de-duplication for meta. Two components that both render <meta name="description"> produce two tags. Decide which component owns each tag.
  • Updates and removal. Changing props updates the existing head tag in place. Unmounting the component removes its tags (except scripts, which cannot be un-run).
  • Server rendering: the tags are written into the head of the HTML stream, so crawlers and link-preview bots see them without running JavaScript, an important gain over effects that set document.title.
  • Not for the <html> or <body> attributes. Those still need your own code or framework.
  • Good fits: page titles, descriptions, canonical URLs, Open Graph tags (<meta property="og:title">), icons, and hreflang links.
  • Framework APIs such as Next.js metadata objects can replace this; use whichever your framework documents so the two do not fight.
  • Older React (before 19) ignored this; libraries such as React Helmet were needed.