Start Using color-scheme CSS Property When Working With Dark/Light Themes

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2025

ความคิดเห็น • 22

  • @wajdwael8775
    @wajdwael8775 ปีที่แล้ว +2

    Simple and clear explanation.

    • @CSSWeekly
      @CSSWeekly  ปีที่แล้ว +1

      Thank you so much, Wajd! I'm thrilled to hear this! 🙏

  • @CSSWeekly
    @CSSWeekly  2 ปีที่แล้ว +5

    A few more websites I found that should probably use color-scheme property:
    - hashnode.com/
    - web.dev/
    - jsfiddle.net/
    - vercel.com/
    Have you found any? 🙂

    • @galliumwang5089
      @galliumwang5089 2 ปีที่แล้ว +2

      howerer, It doesn't provide a button to switch theme, it's really annoying😅

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +1

      True. But if they did everything for us, we wouldn't have an opportunity to play with new features. 😅

  • @clevermissfox
    @clevermissfox ปีที่แล้ว +2

    If you’re using set colors on your page , can you set up custom properties and tell the browser “these are the set of colours for light mode” and “these are the set of colours for dark mode”? Other than using media query of (@prefers-color-scheme: dark) but still with css?
    Eg
    if (light mode) {
    -body-bg: lightpink;
    -card-bg: lightgrey;
    -primary-txt: black;
    }
    Then if(darkmode) {
    -body-bg: charcoal;
    -card-bg: black;
    -body-text: white;
    }

    • @CSSWeekly
      @CSSWeekly  ปีที่แล้ว +1

      This is a fantastic question! 🙏
      There isn't a simple way really to accomplish this, as far as I know. 🙁
      There is light-dark() function that lets you specify light and dark colors in one line. And we might new schemed-value() function that would help with this.
      Bramus Van Damme has a nice article on the subject: www.bram.us/2023/10/09/the-future-of-css-easy-light-dark-mode-color-switching-with-light-dark/

  • @danieladu3923
    @danieladu3923 10 หลายเดือนก่อน +1

    What is the title of the yellow book om your table

    • @CSSWeekly
      @CSSWeekly  10 หลายเดือนก่อน

      "Show Your Work!" by Austin Kleon. It's a short book encouraging you to share your work openly and publicly. 🙂

  • @thedacian123
    @thedacian123 2 ปีที่แล้ว +2

    Hello,So when we are setting color-scheme property ,you are telling the browser to render the page/elements using OS system prefs color scheme?

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +3

      Hello Alex. The color-scheme tells the browser to render page/elements in the color-scheme you specify. It doesn't have to match the system color-scheme. A website could support only a dark scheme, for example, while you use light in your OS. And you would use this with `prefers-color-scheme` media query, not instead.
      Does this answer your question?🙂

    • @clevermissfox
      @clevermissfox ปีที่แล้ว

      @@CSSWeeklyif you have a light theme OS , where would you specify that you prefer a dark theme to have those styles applied?

  • @bonsayeb9620
    @bonsayeb9620 2 ปีที่แล้ว +1

    Thank you for this awesome video. Is it possible to add animation to the color-scheme property? I tried adding a transition of 2s but it didn't work.

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +2

      Thanks for your comment, Bonsaye! 🙏
      Unfortunately, color-scheme is not animatable. You can find a list of all properties that are here: developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
      Hope this helps. 🙂

  • @nathan_wind
    @nathan_wind 2 ปีที่แล้ว +1

    Cool video! Though I knew about light/dark modes, I didn’t know they could both be specified, and I also didn’t know about the meta tag for them.

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +2

      Thank you so much, Nathan! I’m delighted to hear that you learned something new! 🙏

  • @svenson95
    @svenson95 2 ปีที่แล้ว +2

    Even TH-cam doesnt use color-scheme :D although it would look much better if they would
    Greets from Berlin!

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +1

      Indeed it seems like TH-cam doesn't use `color-scheme`, but I think they do a great job with their dark theme-their attention to detail is on point. 🙂

  • @loiuxxx
    @loiuxxx 2 ปีที่แล้ว +2

    how about if there is a defined colors? will color-scheme work?

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +1

      No, it will not work automatically in that case, John. Or rather, only native UI elements would be affected.
      So you will have to redefine those colors manually. And this is probably the most common way people would use the color-scheme.

    • @loiuxxx
      @loiuxxx 2 ปีที่แล้ว +1

      @@CSSWeekly thanks!

    • @CSSWeekly
      @CSSWeekly  2 ปีที่แล้ว +1

      Glad I could help! 🙂