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

Set color-scheme by default #710

Open
jimmywarting opened this issue May 16, 2023 · 5 comments
Open

Set color-scheme by default #710

jimmywarting opened this issue May 16, 2023 · 5 comments

Comments

@jimmywarting
Copy link

Providing both a dark and a light color scheme should be on anyones radar now and it should not be forgotten by the developer that there are two kind of ppl in this world

i think it would be useful if when you create a new html:5 or with ! template
...then it should include a simple style sheet that is just marly a:

@media (prefers-color-scheme: dark) {
  * { color-scheme: dark; }
}

cuz most often ppl

  • forget to add a dark mode
  • or they override a heck of a lot default html/css rules with a bunch of css
    • and then they forget to change the color of some weird native element such as the <select>, <input type=file> element that is a bit harder to style and hence why they also tend to completely write custom component with select2 and lots of included html, css and javascript cuz it's hard to style the <select> or the file input element and also changing the color of the button in the file input
    • another common issue by not using color-scheme is that ppl add a dark background and a light text color but things such as the date icon in eg <input type="date"> still inherit the light theme so the calendar icon is dark on a dark background
      evident by this jsfiddle demo: https://jsfiddle.net/uj1Ltfxs/

so i would wish for a default but tiny and powerful css is added by default so it becomes:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    @media (prefers-color-scheme: dark) {
      * { color-scheme: dark; }
    }
  </style>
</head>
<body>
  
</body>
</html>

the color-scheme is often overlooked/forgotten and everyone should be using it i think. it takes care of a lot of fixes and reduces the amount of css you really have to write for having both a dark and light theme

while at it i also think the users own system/OS font should be used by default too.

necolas/normalize.css#665

font-family: -apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif
so something like this:

    * {
      font-family: -apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif 
    }
    @media (prefers-color-scheme: dark) {
      * { color-scheme: dark; }
    }
@sergeche
Copy link
Member

I’m not sure if it’s something that must be added by default. I did some quick test and found that this @media only works with bare HTML page without styling. Adding background and color to :root selector forces given colors regardless of user theme. So this @media rule will fix something for unstyled pages only, which doesn’t looks real production page. Or maybe you can provide some good examples when this snippet actually provides a good styling by default?

Also, I believe that a proper dark theme or default font face is something that should be provided by developer, not a default. And Emmet allow developers to customize snippets

@jimmywarting
Copy link
Author

Or maybe you can provide some good examples when this snippet actually provides a good styling by default?

Think my jsfiddle is sufficient.

when you use color-scheme: dark then you will style the calendar widget that you can't solve with any other css selector

image

and this is what it would look without it:

image

so it's more than just default background/text color that gets applied.
And there is many styled/production ready websites that still uses native form inputs for instance.
radio boxes can still go unstyled. you get the more system OS looks and feel to them

@sergeche
Copy link
Member

IMO on second screenshot it matches better the default page UI. I’m not convinced such CSS should be default for simple HTML skeleton.

@jimmywarting
Copy link
Author

i haven't tried to style the page at all.

@jimmywarting
Copy link
Author

ok, turned out that you can set a meta tag as well.

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

this is actually better.

a full demo of all element is here: https://color-scheme-demo.glitch.me/
and a blog about it: https://web.dev/color-scheme/ explaining why it's a good choice to have it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants