-
Notifications
You must be signed in to change notification settings - Fork 23.2k
29786 ship light dark #30244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
29786 ship light dark #30244
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
71e1443
added light-dark page
dletorey ada9881
Merge branch 'main' into 29786-ship-light-dark
dletorey 29dab16
corrected linting issue
dletorey 8468a3c
Merge branch 'main' into 29786-ship-light-dark
dletorey 474ceca
added light-dark() to see also on color-scheme page
dletorey 3e0b4b7
added the light-dark function to the CSS functions page
dletorey 9169b95
added the light-dark function to the CSS colors page
dletorey 031d6f6
added the content for light-dark function page
dletorey 55d9fd2
Merge branch 'mdn:main' into 29786-ship-light-dark
dletorey d831625
added the release note for light-dark()
dletorey 49ccfc7
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey af6d0c0
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 5ac2537
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 458a3f5
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 9014726
specifically stated it is a <color> function
dletorey 22814d9
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 07a9e8b
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 123b698
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 1d3df3e
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey d2a8f58
updated the example name in the results
dletorey 72bb911
updated the example name in the results
dletorey d43a2a0
Update files/en-us/web/css/css_functions/index.md
dletorey ef8d24f
Update files/en-us/web/css/color_value/index.md
dletorey f6fc089
Update files/en-us/web/css/color-scheme/index.md
dletorey fa1e876
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 84e3c9f
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 4785a8e
Merge branch '29786-ship-light-dark' of github.com:CodeRedDigital/con…
dletorey 8f1ba78
Merge branch 'main' into 29786-ship-light-dark
dletorey 0d7c42b
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey c0abd06
moved the color-scheme example and added a note to explain why it is …
dletorey f5b3f5d
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 5b7171b
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 9ee6ff7
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 1339a0e
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey da1a7a3
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey 48417c6
reversed the colors in the syntax example so for light the text color…
dletorey f979100
Merge branch 'main' into 29786-ship-light-dark
dletorey b9d0779
Merge branch 'main' into 29786-ship-light-dark
dletorey 5439c1f
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey f0498cd
Merge branch 'main' into 29786-ship-light-dark
dletorey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| --- | ||
| title: light-dark() | ||
| slug: Web/CSS/color_value/light-dark | ||
| page-type: css-function | ||
| browser-compat: css.types.color.light-dark | ||
| --- | ||
|
|
||
| {{CSSRef}} | ||
|
|
||
| The **`light-dark()`** [CSS](/en-US/docs/Web/CSS) [`<color>` function](/en-US/docs/Web/CSS/CSS_Functions#color_functions) enables setting two colors for a property - returning one of the two colors options by detecting if the developer has set a light or dark color scheme or the a user has requested light or dark color theme - without needing to encase the theme colors withing a [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme) [media feature](/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries#targeting_media_features) query. | ||
| Users are able to indicate their color-scheme preference through their operating system settings (e.g. light or dark mode) or their user agent settings. The `light-dark()` function enables providing two color values where any `<color>` value is accepted. The `light-dark()` CSS color function returns the first value if the user's preference is set to `light` or if no preference is set and the second value if the user's preference is set to `dark`. | ||
|
|
||
| To enable support for the `light-dark()` color function, the {{CSSXref("color-scheme")}} must have a value of `light dark`, usually set on the {{CSSXref(":root")}} [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes). | ||
|
|
||
| ```css | ||
| :root { | ||
| color-scheme: light dark; | ||
| } | ||
| body { | ||
| color: light-dark(#333b3c, #efefec); | ||
| background-color: light-dark(#efedea, #223a2c); | ||
| } | ||
| ``` | ||
|
|
||
| ## Syntax | ||
|
|
||
| ```css | ||
| /* Named color values */ | ||
| color: light-dark(black, white); | ||
|
|
||
| /* RGB color values */ | ||
| color: light-dark(rgb(0 0 0), rgb(255 255 255)); | ||
|
|
||
| /* Custom properties */ | ||
| color: light-dark(var(--light), var(--dark)); | ||
| ``` | ||
|
|
||
| ### Values | ||
|
|
||
| Functional notation: `light-dark(light-color, dark-color)` | ||
|
|
||
| - `light-color` | ||
|
|
||
| - : {{CSSXref("<color>")}} value to be set for light {{CSSXref("color-scheme")}}. | ||
|
|
||
| - `dark-color` | ||
| - : {{CSSXref("<color>")}} value to be set for dark {{CSSXref("color-scheme")}}. | ||
|
|
||
| ### Formal syntax | ||
|
|
||
| {{csssyntax}} | ||
|
|
||
| ## Example | ||
|
|
||
| ### Setting colors based on color scheme | ||
|
|
||
| By default, in supporting browsers, the color returned by the `light-dark()` color function depends on the user preference set through an operating system's settings (e.g., light or dark mode) or from a user agent setting. You can also change this setting in the browser's {{glossary("developer tools")}}. | ||
|
|
||
| #### HTML | ||
|
|
||
|
dletorey marked this conversation as resolved.
|
||
| We include three sections to enable targeting light colors, dark colors, and the colors selected based on the user's preferred color scheme. | ||
|
|
||
| ```html | ||
| <h1><code>light-dark()</code> CSS function</h1> | ||
| <section> | ||
| <h2>Automatic</h2> | ||
| <p>This section will react to the users system or user agent setting.</p> | ||
| </section> | ||
| <section class="light"> | ||
| <h2>Light</h2> | ||
| <p> | ||
| This section will be light due to the <code>color-scheme: light;</code>. | ||
| </p> | ||
| </section> | ||
| <section class="dark"> | ||
| <h2>Dark</h2> | ||
| <p>This section will be light due to the <code>color-scheme: dark;</code>.</p> | ||
| </section> | ||
| ``` | ||
|
|
||
| #### CSS | ||
|
|
||
|
dletorey marked this conversation as resolved.
|
||
| We include colors for both light and dark themes. We also define `color-scheme` for the document on the `:root` to enable the `light-dark()` color function for the entire document. | ||
|
dletorey marked this conversation as resolved.
|
||
|
|
||
| ```css-nolint | ||
| :root { | ||
| /* this has to be set to switch between light or dark */ | ||
| color-scheme: light dark; | ||
|
|
||
| --light-bg: ghostwhite; | ||
| --light-color: darkslategray; | ||
| --light-code: tomato; | ||
|
|
||
| --dark-bg: darkslategray; | ||
| --dark-color: ghostwhite; | ||
| --dark-code: gold; | ||
| } | ||
| * { | ||
| background-color: light-dark(var(--light-bg), var(--dark-bg)); | ||
| color: light-dark(var(--light-color), var(--dark-color)); | ||
| } | ||
| code { | ||
| color: light-dark(var(--light-code), var(--dark-code)); | ||
| } | ||
| ``` | ||
|
|
||
| In addition to enabling the `light-dark()` function, the `color-scheme` property enables overriding a user's color scheme for document sections. Forcing a page section to only use a light or dark color scheme can be done by setting the `color-scheme` property to `light` or `dark`. | ||
|
|
||
| > **Note:** Generally this should not be done, we are using it here for demonstation purposes. If the user has made a preference, you generally should not override their preferences. | ||
|
|
||
| ```css | ||
| .light { | ||
| /* forces light color-scheme */ | ||
| color-scheme: light; | ||
| } | ||
| .dark { | ||
| /* forces dark color-scheme */ | ||
| color-scheme: dark; | ||
| } | ||
| ``` | ||
|
|
||
| ```css hidden | ||
| section { | ||
| padding: 0.8rem; | ||
| } | ||
| ``` | ||
|
|
||
| #### Result | ||
|
|
||
| {{EmbedLiveSample("setting_colors_based_on_color_scheme", "100%", 500)}} | ||
|
|
||
| ## Specifications | ||
|
|
||
| {{Specifications}} | ||
|
|
||
| ## Browser compatibility | ||
|
|
||
| {{Compat}} | ||
|
|
||
| ## See also | ||
|
|
||
| - {{CSSXref("color-scheme")}} | ||
| - {{CSSXref("<color>")}} | ||
|
dletorey marked this conversation as resolved.
|
||
| - [CSS color](/en-US/docs/Web/CSS/CSS_colors) module | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.