Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. CSS contrast-color is newly baseline, but it falls short in some areas.

CSS contrast-color is newly baseline, but it falls short in some areas.

Scheduled Pinned Locked Moved Uncategorized
10 Posts 5 Posters 24 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • firefoxwebdevs@mastodon.socialF This user is from outside of this forum
    firefoxwebdevs@mastodon.socialF This user is from outside of this forum
    firefoxwebdevs@mastodon.social
    wrote on last edited by
    #1

    CSS contrast-color is newly baseline, but it falls short in some areas. Here's how it works, and what to look out for:

    vrugtehagel@mastodon.socialV firefoxwebdevs@mastodon.socialF simevidas@mastodon.socialS 3 Replies Last reply
    0
    • firefoxwebdevs@mastodon.socialF firefoxwebdevs@mastodon.social

      CSS contrast-color is newly baseline, but it falls short in some areas. Here's how it works, and what to look out for:

      vrugtehagel@mastodon.socialV This user is from outside of this forum
      vrugtehagel@mastodon.socialV This user is from outside of this forum
      vrugtehagel@mastodon.social
      wrote on last edited by
      #2

      @firefoxwebdevs fun fact, you can (kind of) make it output colors other than white or black, using relative color syntax! For example, if you wanted yellow instead of white (for whatever reason), you could do `rgb(from contrast-color(var(--my-color)) r g 0)`. This doesn't account for the changed color when deciding the most contrasty color, though, so I reckon this is only useful for very minor color changes (like a slightly off-white or nearly-black).

      firefoxwebdevs@mastodon.socialF 1 Reply Last reply
      0
      • firefoxwebdevs@mastodon.socialF firefoxwebdevs@mastodon.social

        CSS contrast-color is newly baseline, but it falls short in some areas. Here's how it works, and what to look out for:

        firefoxwebdevs@mastodon.socialF This user is from outside of this forum
        firefoxwebdevs@mastodon.socialF This user is from outside of this forum
        firefoxwebdevs@mastodon.social
        wrote on last edited by
        #3

        You can often get a better result using this trick with oklch() by @khamer which approximates APCA https://random-stuff.jakearchibald.com/color-contrast/#2277d3

        aardrian@toot.cafeA adamhotep@infosec.exchangeA 2 Replies Last reply
        0
        • vrugtehagel@mastodon.socialV vrugtehagel@mastodon.social

          @firefoxwebdevs fun fact, you can (kind of) make it output colors other than white or black, using relative color syntax! For example, if you wanted yellow instead of white (for whatever reason), you could do `rgb(from contrast-color(var(--my-color)) r g 0)`. This doesn't account for the changed color when deciding the most contrasty color, though, so I reckon this is only useful for very minor color changes (like a slightly off-white or nearly-black).

          firefoxwebdevs@mastodon.socialF This user is from outside of this forum
          firefoxwebdevs@mastodon.socialF This user is from outside of this forum
          firefoxwebdevs@mastodon.social
          wrote on last edited by
          #4

          @vrugtehagel yesss, you can also use similar tricks to approximate APCA https://random-stuff.jakearchibald.com/color-contrast/#2277d3

          1 Reply Last reply
          0
          • firefoxwebdevs@mastodon.socialF firefoxwebdevs@mastodon.social

            You can often get a better result using this trick with oklch() by @khamer which approximates APCA https://random-stuff.jakearchibald.com/color-contrast/#2277d3

            aardrian@toot.cafeA This user is from outside of this forum
            aardrian@toot.cafeA This user is from outside of this forum
            aardrian@toot.cafe
            wrote on last edited by
            #5

            @firefoxwebdevs
            For folks reading into this thread, understand that APCA is not part of any W3C spec, draft or otherwise:
            https://adrianroselli.com/2026/04/wcag3-contrast-as-of-april-2026.html

            You can still use APCA (whichever APCA version), but the colors you choose may not satisfy WCAG. Be sure to also check them against WCAG.

            @khamer

            1 Reply Last reply
            0
            • firefoxwebdevs@mastodon.socialF firefoxwebdevs@mastodon.social

              You can often get a better result using this trick with oklch() by @khamer which approximates APCA https://random-stuff.jakearchibald.com/color-contrast/#2277d3

              adamhotep@infosec.exchangeA This user is from outside of this forum
              adamhotep@infosec.exchangeA This user is from outside of this forum
              adamhotep@infosec.exchange
              wrote on last edited by
              #6

              @firefoxwebdevs @khamer Here's a useful resource for checking color contrast: https://webaim.org/resources/linkcontrastchecker/

              In my own code, and I'm ashamed I didn't save links to how I found these values, I calculate contrast-color manually in JS like this (assuming values for the background's r, b, and g of 0-255):

              let luminance = r / 1199 + g / 357 + b / 3532; // 0-1
              let foreground = luminance > .63 ? "#000" : "#fff";

              I also emphasize it more with text shadow, giving a subtly glowing outline around the text:

              elem.style.textShadow = "0 0 .3ex " + (luminance > .63 ? "#fff" : "#000");
              firefoxwebdevs@mastodon.socialF 1 Reply Last reply
              0
              • adamhotep@infosec.exchangeA adamhotep@infosec.exchange

                @firefoxwebdevs @khamer Here's a useful resource for checking color contrast: https://webaim.org/resources/linkcontrastchecker/

                In my own code, and I'm ashamed I didn't save links to how I found these values, I calculate contrast-color manually in JS like this (assuming values for the background's r, b, and g of 0-255):

                let luminance = r / 1199 + g / 357 + b / 3532; // 0-1
                let foreground = luminance > .63 ? "#000" : "#fff";

                I also emphasize it more with text shadow, giving a subtly glowing outline around the text:

                elem.style.textShadow = "0 0 .3ex " + (luminance > .63 ? "#fff" : "#000");
                firefoxwebdevs@mastodon.socialF This user is from outside of this forum
                firefoxwebdevs@mastodon.socialF This user is from outside of this forum
                firefoxwebdevs@mastodon.social
                wrote on last edited by
                #7

                @adamhotep @khamer that's cool, but just be aware of the cases where WCAG gets it wrong (that page uses WCAG)

                adamhotep@infosec.exchangeA 1 Reply Last reply
                0
                • firefoxwebdevs@mastodon.socialF firefoxwebdevs@mastodon.social

                  @adamhotep @khamer that's cool, but just be aware of the cases where WCAG gets it wrong (that page uses WCAG)

                  adamhotep@infosec.exchangeA This user is from outside of this forum
                  adamhotep@infosec.exchangeA This user is from outside of this forum
                  adamhotep@infosec.exchange
                  wrote on last edited by
                  #8

                  @firefoxwebdevs @khamer yeah, iirc I tweaked the formula a bit, but I also did some unit conversion, so it's harder to see that.

                  1 Reply Last reply
                  0
                  • firefoxwebdevs@mastodon.socialF firefoxwebdevs@mastodon.social

                    CSS contrast-color is newly baseline, but it falls short in some areas. Here's how it works, and what to look out for:

                    simevidas@mastodon.socialS This user is from outside of this forum
                    simevidas@mastodon.socialS This user is from outside of this forum
                    simevidas@mastodon.social
                    wrote on last edited by
                    #9

                    @firefoxwebdevs Thanks for reminding me how to pronounce WCAG

                    firefoxwebdevs@mastodon.socialF 1 Reply Last reply
                    0
                    • simevidas@mastodon.socialS simevidas@mastodon.social

                      @firefoxwebdevs Thanks for reminding me how to pronounce WCAG

                      firefoxwebdevs@mastodon.socialF This user is from outside of this forum
                      firefoxwebdevs@mastodon.socialF This user is from outside of this forum
                      firefoxwebdevs@mastodon.social
                      wrote last edited by
                      #10

                      @simevidas I was actually shocked whisperx picked it up correctly.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups