Theme Color Meta Tag
with useThemeUI
Grab your theme from the context with useThemeUI
and use your framework's
method of adding a meta tag to use your framework’s method of adding a meta tag
to <head />
— react-helmet
in Gatsby
```jsximport { Helmet } from 'react-helmet'import { useThemeUI } from 'theme-ui'function Example() {const { theme } = useThemeUI()return (<Helmet><meta name="theme-color" content={theme.colors.primary} /></Helmet>)}```
next/head
in Next.jsimport Head from 'next/head'function Example() {const { theme } = useThemeUI()return (<div><Head><title>My page title</title><meta name="theme-color" content={theme.colors.background} /></Head><p>Hello world!</p></div>)}
using CSS Custom Properties
You can use custom CSS Properties added by theme-ui
to access the colors from
a static HTML file.
Edit the page on GitHub<metaname="theme-color"content="var(--theme-ui-colors-primary)"media="(prefers-color-scheme: light)"/><metaname="theme-color"content="var(--theme-ui-colors-background)"media="(prefers-color-scheme: dark)"/>