Skip to content
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

29786 ship light dark #30244

Merged
merged 40 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
71e1443
added light-dark page
dletorey Oct 30, 2023
ada9881
Merge branch 'main' into 29786-ship-light-dark
dletorey Oct 30, 2023
29dab16
corrected linting issue
dletorey Oct 31, 2023
8468a3c
Merge branch 'main' into 29786-ship-light-dark
dletorey Oct 31, 2023
474ceca
added light-dark() to see also on color-scheme page
dletorey Oct 31, 2023
3e0b4b7
added the light-dark function to the CSS functions page
dletorey Oct 31, 2023
9169b95
added the light-dark function to the CSS colors page
dletorey Oct 31, 2023
031d6f6
added the content for light-dark function page
dletorey Oct 31, 2023
55d9fd2
Merge branch 'mdn:main' into 29786-ship-light-dark
dletorey Nov 13, 2023
d831625
added the release note for light-dark()
dletorey Nov 13, 2023
49ccfc7
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
af6d0c0
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
5ac2537
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
458a3f5
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
9014726
specifically stated it is a <color> function
dletorey Nov 14, 2023
22814d9
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
07a9e8b
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
123b698
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
1d3df3e
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
d2a8f58
updated the example name in the results
dletorey Nov 14, 2023
72bb911
updated the example name in the results
dletorey Nov 14, 2023
d43a2a0
Update files/en-us/web/css/css_functions/index.md
dletorey Nov 14, 2023
ef8d24f
Update files/en-us/web/css/color_value/index.md
dletorey Nov 14, 2023
f6fc089
Update files/en-us/web/css/color-scheme/index.md
dletorey Nov 14, 2023
fa1e876
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
84e3c9f
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
4785a8e
Merge branch '29786-ship-light-dark' of github.com:CodeRedDigital/con…
dletorey Nov 14, 2023
8f1ba78
Merge branch 'main' into 29786-ship-light-dark
dletorey Nov 14, 2023
0d7c42b
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 14, 2023
c0abd06
moved the color-scheme example and added a note to explain why it is …
dletorey Nov 14, 2023
f5b3f5d
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 16, 2023
5b7171b
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 16, 2023
9ee6ff7
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 16, 2023
1339a0e
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 16, 2023
da1a7a3
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 16, 2023
48417c6
reversed the colors in the syntax example so for light the text color…
dletorey Nov 16, 2023
f979100
Merge branch 'main' into 29786-ship-light-dark
dletorey Nov 16, 2023
b9d0779
Merge branch 'main' into 29786-ship-light-dark
dletorey Nov 16, 2023
5439c1f
Update files/en-us/web/css/color_value/light-dark/index.md
dletorey Nov 17, 2023
f0498cd
Merge branch 'main' into 29786-ship-light-dark
dletorey Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions files/en-us/mozilla/firefox/releases/120/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ This article provides information about the changes in Firefox 120 that affect d

### CSS

- The {{CSSXref("color_value/light-dark", "light-dark()")}} CSS Color function is now supported. This allows the setting of a colors for both light & dark without the need for `prefers-color-scheme` media feature ([Firefox bug 1856999](https://bugzil.la/1856999)).

#### Removals

### JavaScript
Expand Down
1 change: 1 addition & 0 deletions files/en-us/web/css/color-scheme/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ To opt the entire page into the user's color scheme preferences declare `color-s
## See also

- [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme) media query to detect user preferences for color schemes.
- {{CSSXref("color_value/light-dark", "light-dark()")}} color function to set colors for both light and dark color schemes.
- [Applying color to HTML elements using CSS](/en-US/docs/Web/CSS/CSS_colors/Applying_color)
- Other color-related properties: {{cssxref("color")}}, {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, {{cssxref("caret-color")}}, and {{cssxref("column-rule-color")}}
- {{cssxref("background-image")}}
Expand Down
5 changes: 5 additions & 0 deletions files/en-us/web/css/color_value/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ oklab(59% 0.1 0.1 / 0.5)
/* Oklch (Lightness, Chroma, Hue) */
oklch(60% 0.15 50)
oklch(60% 0.15 50 / 0.5)

/* light-dark */
light-dark(white, black)
light-dark(rgb(255 255 255), rgb(0 0 0))
```

A `<color>` value can be specified using one of the methods listed below:
Expand All @@ -62,6 +66,7 @@ A `<color>` value can be specified using one of the methods listed below:
- [Oklab](https://bottosson.github.io/posts/oklab/) color space: {{CSSXref("color_value/oklab", "oklab()")}}, {{CSSXref("color_value/oklch", "oklch()")}};
- Other color spaces: {{CSSXref("color_value/color", "color()")}}.
- By mixing two colors: {{CSSXref("color_value/color-mix", "color-mix()")}}.
- By specifying two colors, the first used for light color-schemes and the second used for dark color-schemes: {{CSSXref("color_value/light-dark", "light-dark()")}}.

### currentcolor keyword

Expand Down
140 changes: 140 additions & 0 deletions files/en-us/web/css/color_value/light-dark/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
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 - selecting one of the two options by detecting if 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.
dletorey marked this conversation as resolved.
Show resolved Hide resolved
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;
}
dletorey marked this conversation as resolved.
Show resolved Hide resolved
```

## Syntax

```css
/* Named color values */
color: light-dark(white, black);

/* RGB color values */
color: light-dark(rgb(255 255 255), rgb(0 0 0));
dletorey marked this conversation as resolved.
Show resolved Hide resolved

/* Custom properties */
color: light-dark(var(--light), var(--dark));
```

### Values

Functional notation: `light-dark(light-color, dark-color)`

- `light-color`

- : {{CSSXref("&lt;color&gt;")}} value to be set for light {{CSSXref("color-scheme")}}.

- `dark-color`
- : {{CSSXref("&lt;color&gt;")}} value to be set for dark {{CSSXref("color-scheme")}}.

### Formal syntax

{{csssyntax}}

## Example

### Setting colors based on color scheme

In a supporting browser, the colors will change based on the user preference through an operating system setting (e.g., light or dark mode) or a user agent setting. You can also change this setting in the browsers {{glossary("developer tools")}}.
dletorey marked this conversation as resolved.
Show resolved Hide resolved

#### HTML

dletorey marked this conversation as resolved.
Show resolved Hide resolved
We include three sections to enable targeting light colors, dark colors, and the user's preferred colors.
dletorey marked this conversation as resolved.
Show resolved Hide resolved
dletorey marked this conversation as resolved.
Show resolved Hide resolved

```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.
Show resolved Hide 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.
Show resolved Hide 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));
}
```

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`.
dletorey marked this conversation as resolved.
Show resolved Hide resolved

> **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("&lt;color&gt;")}}
dletorey marked this conversation as resolved.
Show resolved Hide resolved
- [CSS color](/en-US/docs/Web/CSS/CSS_colors) module
1 change: 1 addition & 0 deletions files/en-us/web/css/css_colors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ To see the code for this color syntax converter, [view the source on GitHub](htt
- [`color-contrast()`](/en-US/docs/Web/CSS/color_value/color-contrast) {{Experimental_Inline}}
- [`color-mix()`](/en-US/docs/Web/CSS/color_value/color-mix)
- [`device-cmyk()`](/en-US/docs/Web/CSS/color_value/device-cmyk) {{Experimental_Inline}}
- {{CSSXref("color_value/light-dark", "light-dark()")}} {{Experimental_Inline}}

### Data types

Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/css/css_functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ The {{CSSxRef("color_value","&lt;color&gt;")}} CSS [data type](/en-US/docs/Web/C
- : Selects the highest color contrast from a list of colors, compare to a base color value.
- {{CSSxRef("color_value/device-cmyk", "device-cmyk()")}} {{Experimental_Inline}}
- : Defines CMYK colors in a device-independent way.
- {{CSSXref("color_value/light-dark", "light-dark()")}} {{Experimental_Inline}}
- : Returns one of two provided colors based on the current color scheme.

## Image functions

Expand Down