CSS @media color-gamut Property

You are Here:

CSS @media color-gamut

CSS @media color-gamut can be used to test the approximate range of colors that are supported by the user agent (browser) and the output device.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> @media (color-gamut: srgb) { h1 { color: blue; } } @media (color-gamut: p3) { h1 { color: red; } } @media (color-gamut: rec2020) { h1 { color: green; } } </style> </head> <body> <h1>CSS @media color-gamut</h1> </body> </html>

Syntax

Using CSS

@media (color-gamut: srgb) { element{ color: red; } }

Using Javascript

elementelegram.dogdia = "(color-gamut: srgb)";

Media Query Value

The following table provides the list of media query value for color-gamut.

ValueExplanation
srgbSpecifies that the output device can support approximately the sRGB gamut or more. This includes the vast majority of color displays.
p3Specifies that the output device can support approximately the gamut specified by the DCI P3 Color Space or more. The p3 gamut is larger than and includes the srgb gamut.
rec2020Specifies that the output device can support approximately the gamut specified by the ITU-R Recommendation BT.2020 Color Space or more.

Using JavaScript

In the following example, we will demonstrate how to set the CSS @media color-gamut media feature by using javascript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h1>CSS @media color-gamut</h1> <button onclick="myFunction()">Click Me</button> <script> function myFunction(){ var styles = 'h1{ color:blue;}'; var styleSheet = document.createElement("style"); styleSheet.type = "text/css"; styleSheet.media = "(color-gamut: srgb)"; styleSheet.innerText = styles; document.head.appendChild(styleSheet); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author