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

add a new tip on prefers-color-scheme media feature #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ A collection of tips to help take your CSS skills pro.
1. [Set `font-size` on Form Elements for a Better Mobile Experience](#set-font-size-on-form-elements-for-a-better-mobile-experience)
1. [Use Pointer Events to Control Mouse Events](#use-pointer-events-to-control-mouse-events)
1. [Set `display: none` on Line Breaks Used as Spacing](#set-display-none-on-line-breaks-used-as-spacing)
1. [Detect Whether the User Prefers Light Theme or Dark Theme](#detect-whether-the-user-prefers-light-theme-or-dark-theme)


### Use a CSS Reset
Expand Down Expand Up @@ -622,6 +623,32 @@ br + br {
<sup>[back to table of contents](#table-of-contents)</sup>


### Detect Whether the User Prefers Light Theme or Dark Theme

With The `prefers-color-scheme` Media Feature You Can Detect What Color Sheme Does the User Prefer

It Checks if the User Has Their System Settings Set To Light Mode or Dark Mode

```css
/* These Styles Will Apply if User Has Set Their System Settings to Dark Mode */
@media (prefers-color-scheme: dark) {
.element {
color: #fff;
background-color: #232323;
}
}
/* These Styles Will Apply if User Has Set Their System Settings to Light Mode */
@media (prefers-color-scheme: light) {
.element {
color: #232323;
background-color: #fff;
}
}
```

<sup>[back to table of contents](#table-of-contents)</sup>


## Support

Current versions of Chrome, Firefox, Safari, Opera, Edge, and IE11.
Expand Down