One line of CSS to add basic dark/light mode

When you have your OS set up in dark mode seeing bright form elements is grating. By starting your style sheet with a single line of CSS, you can make sure that people using dark mode get dark form elements and backgrounds and those using light mode, light ones. You can see it in this […]


This content originally appeared on Christian Heilmann and was authored by Chris Heilmann

When you have your OS set up in dark mode seeing bright form elements is grating. By starting your style sheet with a single line of CSS, you can make sure that people using dark mode get dark form elements and backgrounds and those using light mode, light ones.

Codepen showing the difference the line of CSS makes - offering the page in a dark and light mode

You can see it in this codepen


See the Pen
color-scheme
by Christian Heilmann (@codepo8)
on CodePen.


You can also use the browser developer tools to simulate the different modes to see the difference.

Emulating different modes in browser developer tools

Read more about color-scheme on the MDN web docs.


This content originally appeared on Christian Heilmann and was authored by Chris Heilmann


Print Share Comment Cite Upload Translate
APA
Chris Heilmann | Sciencx (2023-03-27T00:36:08+00:00) » One line of CSS to add basic dark/light mode. Retrieved from https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/.
MLA
" » One line of CSS to add basic dark/light mode." Chris Heilmann | Sciencx - Monday June 20, 2022, https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/
HARVARD
Chris Heilmann | Sciencx Monday June 20, 2022 » One line of CSS to add basic dark/light mode., viewed 2023-03-27T00:36:08+00:00,<https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/>
VANCOUVER
Chris Heilmann | Sciencx - » One line of CSS to add basic dark/light mode. [Internet]. [Accessed 2023-03-27T00:36:08+00:00]. Available from: https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/
CHICAGO
" » One line of CSS to add basic dark/light mode." Chris Heilmann | Sciencx - Accessed 2023-03-27T00:36:08+00:00. https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/
IEEE
" » One line of CSS to add basic dark/light mode." Chris Heilmann | Sciencx [Online]. Available: https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/. [Accessed: 2023-03-27T00:36:08+00:00]
rf:citation
» One line of CSS to add basic dark/light mode | Chris Heilmann | Sciencx | https://www.scien.cx/2022/06/20/one-line-of-css-to-add-basic-dark-light-mode-2/ | 2023-03-27T00:36:08+00:00
https://github.com/addpipe/simple-recorderjs-demo