Skip to content

Commit

Permalink
Update example: Adapting to color schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiy authored Dec 13, 2023
1 parent f5f944c commit 8f2f21b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions files/en-us/web/css/color-scheme/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ To opt the entire page into the user's color scheme preferences, declare `color-
}
```

To style specific elements based on the user's color scheme preferences, declare `color-scheme` on specific elements.

```css
header,
footer {
color-scheme: only dark;
}
main {
color-scheme: only light;
}
```

### Setting colors based on color scheme

To style elements based on color scheme preferences, use the [`prefers-color-scheme`](/en-US/docs/Web/CSS/@media/prefers-color-scheme) media query. The example below opts in elements with a class of `.element` to using both light and dark operating system color schemes via the `color-scheme` property, and then uses `prefers-color-scheme` to specify the desired foreground and background colors for those color schemes.
Expand Down

0 comments on commit 8f2f21b

Please sign in to comment.