HTMLMetaElement: media property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2022.

The HTMLMetaElement.media property enables specifying the media for theme-color metadata.

The theme-color property enables setting the color of the browser's toolbar or UI in browsers and operating systems that support this property. The media property enables setting different theme colors for different media values.

Value

A string.

Examples

Setting the theme color for dark mode

The following example creates a new <meta> element with a name attribute set to theme-color. The content attribute is set to #3c790a, the media attribute is set to prefers-color-scheme: dark, and the element is appended to the document <head>. When a user has specified a dark mode in their operating system, the media property can be used to set a different theme-color:

js
const meta = document.createElement("meta");
meta.name = "theme-color";
meta.content = "#3c790a";
meta.media = "(prefers-color-scheme: dark)";
document.head.appendChild(meta);

Setting theme colors by device size

Most meta properties can be used only once. However, theme-color can be used multiple times if unique media values are provided.

This example adds two meta elements with a theme-color; one for all devices and another for small screens. The order of matching the media query matters, so the more specific query should be added later in the document, as shown below:

js
// Add a theme-color for all devices
const meta1 = document.createElement("meta");
meta1.name = "theme-color";
meta1.content = "white";
document.head.appendChild(meta1);

// Add a theme-color for small devices
const meta2 = document.createElement("meta");
meta2.name = "theme-color";
meta2.media = "(width <= 600px)";
meta2.content = "black";
document.head.appendChild(meta2);

Specifications

Specification
HTML
# dom-meta-media

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
media
Chrome – Full support
Chrome 93 (Release date: 2021-08-31)
footnote Full support
Edge – Full support
Edge 93 (Release date: 2021-09-02)
footnote Full support
Firefox – Full support
Firefox 106 (Release date: 2022-10-18)
footnote Full support
Opera – Full support
Opera 79 (Release date: 2021-09-14)
footnote Full support
Safari – Full support
Safari 15 (Release date: 2021-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 93 (Release date: 2021-08-31)
footnote Full support
Firefox for Android – Full support
Firefox for Android 106 (Release date: 2022-10-18)
footnote Full support
Opera Android – Full support
Opera Android 66 (Release date: 2021-12-15)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
Samsung Internet – Full support
Samsung Internet 17 (Release date: 2022-05-04)
footnote Full support
WebView Android – Full support
WebView Android 93 (Release date: 2021-08-31)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15 (Release date: 2021-09-20)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also