Using currentColor with color-mix is amazing

Поделиться
HTML-код
  • Опубликовано: 3 дек 2024

Комментарии • 89

  • @LePhenixGD
    @LePhenixGD 9 месяцев назад +72

    Quick SVG trick:
    To easily adjust SVG colors without directly modifying the fill property, set the fill attribute to 'currentColor'. Then, by adjusting the color property of the SVG's container, you can dynamically change its color!

    • @kylerjohnson988
      @kylerjohnson988 9 месяцев назад

      Nice! Thanks for sharing this

    • @jaydee-222
      @jaydee-222 9 месяцев назад +22

      note, for those who may not know, this only works with inlined SVGs, not those inserted via the tag

    • @w01dnick
      @w01dnick 9 месяцев назад

      @@jaydee-222 also, it's nice to use - this way SVG's are cached in one file and used in html with relatevily low overhead.

    • @jensdemuynck
      @jensdemuynck 9 месяцев назад +4

      I use this all the time! When i clean up the code of an SVG, i always set the fill attribute to 'currentColor'. By far the cleanest way!

    • @tspander
      @tspander 9 месяцев назад

      I usually color SVGs by making them the mask-image of a container with a set background

  • @denoww9261
    @denoww9261 9 месяцев назад +9

    I love using color-mix() with `color-scheme: light dark` plus currentColor, Canvas, and other s! I've been building an internal web-based tool at work and I haven't specified a _single colour_ manually, because everything uses system colours and looks right at home on whichever OS or theme the user has. I also love `font-family: system-ui` for that reason!

  • @caigner
    @caigner 9 месяцев назад +11

    A video series on the tools of the trade would be very welcome!

  • @MrJettann
    @MrJettann 9 месяцев назад +8

    Definitely want a video about dev tools stuff! Awesome, as always btw😊

    • @muisadinam9615
      @muisadinam9615 9 месяцев назад

      would also love a video about the dev tools!

    • @alainkr
      @alainkr 9 месяцев назад

      I'd love 2 as well

  • @HeyJes
    @HeyJes 9 месяцев назад +19

    While all this is great, I myself cannot wait for the issues with color-contrast() to get ironed out! Having text color accessibility automatically managed by CSS will be a game-changer! I wrote a smallish Sass library that did sort of the same function and it was great (though I don’t really use it anymore).

    • @KevinPowell
      @KevinPowell  9 месяцев назад +6

      omg yes! It's a bit annoying because it's one of those things that all the browsers *could* do pretty easily right now, but I also understand they want to get it right, since once it comes out, that's what we have. But yes, I would *really* like to have it too :D

  • @KingTMK
    @KingTMK 9 месяцев назад +8

    Would definitely love a deep-dive into the emulation settings!

  • @Thebiggestgordon
    @Thebiggestgordon 9 месяцев назад

    I'm so glad you're talking about accessibility and contrast. On my phone I have colour filters bound to triple-clicking the power button because so many websites use low contrast colours that I literally can't tell apart.

  • @sovereignlivingsoul
    @sovereignlivingsoul 9 месяцев назад +1

    You always put out videos when i happen to be doing something on that issue, i am currently building myself a color pallet of the various color schemes and i was looking into currentColor during my research, thought about it for a second, but now i think i will try to incorporate it into my designs, i like color and i like shadow effects, and using contrast to highlight elements, so this could be a very useful tool that would allow me to use my creative nature quite well, thanks Kevin.

  • @joshuamitchell6204
    @joshuamitchell6204 9 месяцев назад +1

    Would love a video on the rendering settings in the devtools! Always been curious about them but never gotten around to taking a deep dive

  • @mebamme
    @mebamme 9 месяцев назад +2

    A trick I used a couple of years ago to give links a semi-transparent background matching the text color was to give it an extremely tall background gradient (which the link is in the middle of) from currentColor to transparent.

    • @Turabbo
      @Turabbo 9 месяцев назад

      Nice trick!

  • @victorvanrijn
    @victorvanrijn 5 месяцев назад +1

    A great video with practical examples, thanks Kevin!

  • @ericwilliams5456
    @ericwilliams5456 9 месяцев назад +1

    Thanks!

  • @KET0NES
    @KET0NES 9 месяцев назад

    love this! genius to use custom variables like this, can always automagically get the contrast / mix color.
    would love a video on advanced dev tools like the rendering tab.

  • @einatblackrose
    @einatblackrose 9 месяцев назад +9

    I always appreciate how you focus on accessibility. I feel like so many who undermine it in their tutorials.
    I'm probably off topic here, but I wander if you can do a tutorial for accessible dropdown menu. I've been looking for it, and couldn't find a single one that's useful, and I thought no one would do this better than you anyway... 🙏🙏🙏

    • @KevinPowell
      @KevinPowell  9 месяцев назад +6

      Could definitely be something worth looking at 👍

  • @rs14058
    @rs14058 4 месяца назад

    This is really cool! I didn't know these cool things where already possible in all major browsers 💪💪

  • @AleksanderFimreite
    @AleksanderFimreite 9 месяцев назад

    Normally for Lighter / Darker content segments I usually put one color and let transparency blend the dark value underneath towards a white or black transparent box.
    But I would much rather replace that with this, because it brings some other issues along with it when using transparency. This is perfect for my use case.

  • @PedroPisandelli
    @PedroPisandelli 9 месяцев назад

    Really useful feature!! And using the amounts as custom properties, we can easily change darkness amount just scoping the css variable.

  • @tomapedersen
    @tomapedersen 9 месяцев назад +2

    CSS Color Module Level 5 also has relative color syntax which I feel is even more powerful, can use calc-functions to change the values of another color in any color space. Very easy to do things like make something more or less transparent, more or less saturated or even invert a color completely. But it is sadly not yet supported in Firefox.

    • @KevinPowell
      @KevinPowell  9 месяцев назад

      Yup, the relative syntax is fantastic as well. It's a little cumbersom, but *very* powerful. Just wish we could make loops like with Sass, as it'd be a lot faster to make a quick color pallet 😅

    • @seanthesheep
      @seanthesheep 9 месяцев назад

      It's supported in Chrome, but it doesn't work with currentColor apparently because the spec forgot to test it 😂

  • @CSScapism
    @CSScapism 9 месяцев назад

    Great Video!!!
    Just a quick Dev-tools tip, pressing the 'Escape' key will toggle the drawer where the Rendering tab is.

  • @jikochi
    @jikochi 9 месяцев назад

    that's so awesome. thanks kevin!

  • @EricFressange
    @EricFressange 9 месяцев назад +3

    What is the extension you are using to have the contrast or other useful information on inspection?
    Do you have some other extensions to share?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +2

      No extension, it's built into Chrome (and Firefox). The select element thing in the dev tools, when you use it, and hover over something (don't click on it) it shows the contrast. Doesn't work for elements with background images or gradients though.

    • @margaretclaypool
      @margaretclaypool 9 месяцев назад

      @@KevinPowell Hmmm... I'm not seeing that in Firefox. I get a popup of the element with all its selectors, as well as the dimensions, but no info on contrast :(

  • @easysolutions8628
    @easysolutions8628 9 месяцев назад

    Thank you so much Sir ❤ You are G.O.AT of front end development 😊

  • @ALCATRAAAZZ
    @ALCATRAAAZZ 9 месяцев назад

    pretty neat indeed!

  • @nomadshiba
    @nomadshiba 9 месяцев назад

    relative color syntax wasnt working with currentColor, this is great

  • @Luis-fh8cv
    @Luis-fh8cv 9 месяцев назад

    For some reason I always thought it was orangered as opposed to orange-red. And it made me chuckle. Now it’s css that chuckles at my stupidity

  • @clevermissfox
    @clevermissfox 9 месяцев назад +2

    I had no idea you could use color-mix WITHIN the border-color property!! I love this channel. Great video and always learn something@

  • @miguelbezerra5848
    @miguelbezerra5848 5 месяцев назад

    Great video Kevin! How do you have the contrast score appearing in your dev tools? Is it a flag, an extension or something else?

  • @BlastDk3y
    @BlastDk3y 9 месяцев назад +1

    Really good video, thanks a lot !
    One little question, what is the pointer tool you use at @3:16 please ?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +2

      In Chrome (and firefox), the select element thing in your dev tools. Just, instead of clicking on something, you just hover over it :)

  • @vvrath
    @vvrath 9 месяцев назад

    Ahhh very cool! Just the other day I was wondering if there was a way of doing this

  • @D7460N
    @D7460N 9 месяцев назад

    Thanks for yet another jewel of a video!
    You mentioned style queries could take care of this...
    Understood, style queries are not 100% supported yet, but I like to progressively enhance my work.
    Any examples or resources?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +1

      This is a great starting place: developer.chrome.com/docs/css-ui/style-queries

  • @uimonk
    @uimonk 9 месяцев назад

    ur a a legend!!

  • @clevermissfox
    @clevermissfox 9 месяцев назад +1

    Huh, color-mix IS working on your "background" property; couldnt get it to work on "background-color" though... i wonder if i was doing something wrong or if its only recignized as a background-image or aomething like a gradient

  • @joe-skeen
    @joe-skeen 9 месяцев назад +1

    Can you do current background color in the color mix too? That could help with switching dark and light theme, right?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +2

      No way to access the current background color the way we can use currentColor, but you could use custom properties for that :)

  • @danko95bgd
    @danko95bgd 9 месяцев назад +1

    Isn't there color-contrast as well with new color 5 syntax. Not sure about support, but it accepts a list of colors and uses one that passes the contrast ratio.

    • @KevinPowell
      @KevinPowell  9 месяцев назад +1

      It's in the works, but it's sort of in limbo at the moment. The current method for calculating contrast is a bit flawed. The raw numbers don't always match the percieved contrast... Afaik, they're still trying to figure out what the best method is to use, under the hood, and it seems to be taking awhile...

  • @truvc
    @truvc 9 месяцев назад +1

    Interesting. I always took it for granted that I couldn’t use currentColor as an argument to color-mix() for the color property. It doesn’t make sense really. Because currentColor is the color… so how can I mix with it?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +1

      currentColor is what it is *before* the mix :D

  • @ApprendreSansNecessite
    @ApprendreSansNecessite 9 месяцев назад +1

    I am not a fan, not of the feature, but of this trend which consists of defining colors during development. This is the designerp's job.
    Now for things like form elements which can have a LOT of different intermediary states I totally get that you can be forced to generate color variants, but I really think having an array of predefined colors is superior in terms of branding, and I would like there to be a better way of doing it than using indices like primary-500

    • @KevinPowell
      @KevinPowell  9 месяцев назад +1

      I agree that it's the designers job, but the designer *can* take advantage of this. We've had tools like this for *decades* with pre-processors, and large systems have long used them (Bootstrap is the first thing that comes to mind, which uses SCSS mix(), which is very similar).

    • @ApprendreSansNecessite
      @ApprendreSansNecessite 9 месяцев назад

      @@KevinPowell I agree designers, even when doing design for print, mix colours to generate shades, etc. and having a way to express that in code could make this process more transparent, but it's not going to because - and I deplore it - developers don't use abstractions when they write CSS, especially when they use tools like Tailwind. They code in tactical mode, the rules underlying the design, even the brand, escape them, even when they have a keen eye for things like spacing, hierarchy, etc. and care deeply about doing a proper job.
      I have been in both sides of the divide, as you have if I recall, and never was I able to agree on a ubiquitous language for states and colours and stuff like that with devs because the idea that there was even a conversation to be had about this did not come to their mind. They don't see a "domain" in the brand, "business rules" in the style guide or design system. Design is a coat of paint to make things look proper and does not deserve attention.

    • @ApprendreSansNecessite
      @ApprendreSansNecessite 9 месяцев назад

      I realise I was essentialising a group of people and I don't like that. It's a symptom of my recent experiences which made me "lose faith" a little bit. Your viewers are kind of a living proof that I am wrong because you talk about these topics, at least indirectly, a lot

  • @clevermissfox
    @clevermissfox 9 месяцев назад

    Does color-mix work on background-color? Someone in the comments on another vid said it should work anywhere you can define a colour but i wasnt getting anything when i tried background-color: color-mix(in rgb, white, deeppink); for example

  • @penguinxed
    @penguinxed 9 месяцев назад

    thanks for another useful content mr Kevin! Do you have a plan to release another design to code content? they're very useful! 😊

    • @KevinPowell
      @KevinPowell  9 месяцев назад +1

      Yup, will have one soon-ish :)

    • @penguinxed
      @penguinxed 9 месяцев назад

      @@KevinPowell cant wait for that thank you so much as always!

  • @ruegen_9443
    @ruegen_9443 9 месяцев назад

    How are you accessing the accessibility in the popup when you hover? Chrome option?

    • @KevinPowell
      @KevinPowell  9 месяцев назад +2

      It's built it to the inspector thingy... I wish I knew the name, lol. In the dev tools, the top left tool that is an arrow pointing into a dotted box. Select that, then hover over elements. Firefox has one too.

    • @ruegen_9443
      @ruegen_9443 9 месяцев назад +1

      found it, thanks - wish I knew about it long ago!@@KevinPowell

  • @dankierson
    @dankierson 9 месяцев назад

    I wonder what its value really is in the context of a site where users can select their own color theme.
    Choosing the right combination of colors for a theme demands a lot more than just diluting, darkening or mixing in some other color. Color combos have to be selected based on the degree of interest they have relative to each other. And of course relevance to the site subject.
    This tool might be alright for mild contrast but it's too limited for serious work, I feel.

    • @KevinPowell
      @KevinPowell  9 месяцев назад

      It's just one tool at our disposal, but one that a lot of big systems have used well. Bootstrap uses the Sass version ( the mix() function) quite a lot, as an example. We also have a relative syntax, where you can adjust one (or several) parts of a color, so increase/decrease lightness or saturation, or shift a hue... and use calc() for it all, so it opens up a lot of possibilities.

  • @bulent2435
    @bulent2435 9 месяцев назад

    İmpressive. Thanks

  • @Irongrip62
    @Irongrip62 9 месяцев назад

    Wouldn't you be able to leak history state for links using this current state mix?

    • @KevinPowell
      @KevinPowell  9 месяцев назад

      I don't see how? 🤔

    • @Irongrip62
      @Irongrip62 9 месяцев назад

      @@KevinPowell give visited links a different color but make it through an ungodly ammount of chained mixes. Then try for a timing attack.

  • @gwemula
    @gwemula 9 месяцев назад

    New room? :)

  • @philwinkle
    @philwinkle 9 месяцев назад

    not me thinking it was "fun time friends" all this time??

  • @StellarWeb008
    @StellarWeb008 9 месяцев назад

    KEVIN IS GOD!!!!
    I am editing this comment again.
    HE IS GODLIER, GODLIEST!!!!

  • @mendosis
    @mendosis 9 месяцев назад +1

    sadly i would say color-mix is not for real-world scenarios, as graphic designers use their perception not math to design color versions of components.

    • @clamhammer2463
      @clamhammer2463 9 месяцев назад +1

      Some* designers do. and they will be left in the past

    • @KevinPowell
      @KevinPowell  9 месяцев назад

      Totally depends. Sometimes you'll be working with a tight and very perscribed design system... but as the web evolves, and with new things like color-mix() and the eventual contrast tools, and other things that are on the way, those design systems are, most likely, going to start using these types of things as well.
      Also, we've been able to mix colors with pre-processors for a long time now, and I've seen it widely used, including with large systems like Bootstrap, and others. We're just moving those tools from pre-processors to the core language now.

  • @donmorris4506
    @donmorris4506 9 месяцев назад

    Sass

    • @KevinPowell
      @KevinPowell  9 месяцев назад +1

      Yup, something we've long had with Sass! The nice thing here is it works with custom properties, which is handy.

  • @HabibiCode
    @HabibiCode 9 месяцев назад

    3

  • @HabibiCode
    @HabibiCode 9 месяцев назад

    2

  • @HabibiCode
    @HabibiCode 9 месяцев назад

    4