Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

light/dark mode in html, without CSS (only html)

it there a way to make the HTML elements be in dark mode

if the user has activated in his system "dark mode"
and if the user is like to use standard colors, to be "light mode"

all this automatically when the user opens the website.
without any buttons.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and I want that if the user changes the theme color preference from the setting, it will automatically switch to the correct one directly without refreshing the page.

the black and white color of text, I want that don’t use any CSS

so not using CSS. in this project I am using only HTML.

<!-- here is example of tags to color automatically for the answer -->
<h1>
<span>hello world<span>
<input>

if there a way to do this with one line or 2 maximum.

maybe adding a library with no configuration needed, but I don’t find it

>Solution :

add this CSS property color-scheme: light dark; (is only one line of css)

OR if you need only html you can use this <meta> tag

<meta name="color-scheme" content="light dark">

https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme

watch this youtube video for more details: https://youtu.be/n3lcjY4Mm00

it does all the things you listed before!

enter image description here
enter image description here

<html>

<head>
  <meta name="color-scheme" content="light dark">
</head>

<body>
  <h1>hello world</h1>
  <span>hello world</span>
  <input type="text" placeholder="hello world">
</body>

</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading