React Reference ยท Built-in DOM Components
The React meta element
Reference for the React meta element: render description, Open Graph and viewport tags from any component, with React moving them into the document head.
<meta> carries information about the page: its description, character set, viewport behavior, social-sharing preview and more. In React 19, a <meta> rendered from any component is moved into the document <head>. A page component can therefore declare <meta name="description"> next to the content it describes, and the tag goes away when the component unmounts.
Meta tags are written exactly as in HTML, with React's camelCase for two attributes: charSet and httpEquiv. The element is void, so it is always self-closed in JSX.
function ArticlePage({ article }) { return ( <article> <meta name="description" content={article.summary} /> <h1>{article.title}</h1> </article> ); }
Try it
Syntax
<meta name="description" content="..." /> <meta property="og:title" content="..." /> <meta charSet="utf-8" /> <meta httpEquiv="refresh" content="30" />
| Name | Description |
|---|---|
name |
The kind of metadata: description, viewport, robots, theme-color, author and so on. |
content |
The value for name, property, or httpEquiv. |
property |
Used by Open Graph tags such as og:title, og:image. |
charSet |
The document character encoding. Normally already set by the HTML shell. |
httpEquiv |
Pragma directives such as refresh or content-security-policy. |
media |
A media query for theme-color and similar tags. |
itemProp |
Microdata. A meta with itemProp is not hoisted; it stays where it is rendered. |
Returns: a HTMLMetaElement in document.head.
Edge cases: React does not deduplicate <meta> tags. If two components both render <meta name="description">, both go to the head, and crawlers will see two.
Usage notes
- One description per page. Render it from one place: the page-level component. A layout that always renders a description plus a page that adds its own results in two tags.
- Keep dynamic values stable on the server. Metadata is part of the first HTML only when it is rendered on the server (or prerendered). Tags added only after client-side data loading are invisible to crawlers that do not run JavaScript.
- Not for the shell.
viewportandcharSetbelong in the static HTML template. Declaring them in a component works but is later than needed. - Limits of social previews. Link-preview bots read the raw HTML and do not run JavaScript, so they need Open Graph tags in the server-rendered HTML.
- Microdata. A
<meta itemProp="..." content="...">describes the surroundingitemScopeand stays in place, inside its container. - Cleanup is automatic. When the component unmounts, React removes the tag it added.
- Order. Tags land in the head in the order they mount. Do not depend on order between sibling components.
- Alternatives. Frameworks provide metadata functions with merging and deduplication. They cover the cases React deliberately leaves alone.
Related
<title>,<link>,<script>, Hoisted title, meta and link- Lessons: JSX in depth, useEffect