Theming Tailwind with CSS Variables

Поділитися
Вставка
  • Опубліковано 27 лип 2024
  • In this video, you'll learn how to build designs that support multiple themes in Tailwind CSS, leveraging the power of CSS variables. We also look at a common "gotcha" you might run into when trying to use color opacity utilities alongside colors defined as variables.
    Source code: play.tailwindcss.com/YelhilBeHb
  • Наука та технологія

КОМЕНТАРІ • 175

  • @rfmiotto
    @rfmiotto 3 роки тому +10

    I was running into this just a couple days ago! What a perfect timing for this tutorial. Thank you Tailwind Labs for these videos. Please, keep coming up with high-quality materials like this.

  • @jslbrt
    @jslbrt 3 роки тому +49

    I'm going nuts with Tailwind, I love it.

  • @Andrey-il8rh
    @Andrey-il8rh 3 роки тому +2

    I really like how flexible it is to style not only the full root document but each component individually. I already see how those variables can even be scoped inside the component itself to provide completely different styling rules for each individual component and not only colors, it basically allows for turning Tailwind into an ultimate utility-meta framework where classes become meta-information for a possible look. Requires a bit of a mental stretch in the beginning but gives ultimate powers!

  • @yashkhd1100
    @yashkhd1100 2 роки тому +1

    I think your method is best one for implementing dynamic theming with tailwind CSS. I have seen bunch of other approaches but by far this one is cleanest one.

  • @QueeeeenZ
    @QueeeeenZ 2 роки тому

    Perfect, this is exactly what I was looking for! I thought it was not possible to do themes with Tailwind.

  • @ulvidamirli2758
    @ulvidamirli2758 3 роки тому

    Perfect tutorial and that’s what I was looking for. Out of topic, but it would be perfect to see web design tutorials from you

  • @friemae
    @friemae 3 роки тому +2

    These videos are really excellent, awesome developer experience!

  • @benthomson2406
    @benthomson2406 2 роки тому

    your guys make tailwind CSS custom feature amazing!

  • @user-hn5ie9hx6q
    @user-hn5ie9hx6q Рік тому

    Exploring tailwind and had thoughts few days ago: "How can I use css variables for themes" And today video appeared. Magic!
    Thanks UA-cam and you guys!
    Awesome!

  • @weblearningd2294
    @weblearningd2294 Рік тому

    I can not stop watching your videos, really great!! Thanks a lot!

  • @SusanthCom
    @SusanthCom 3 роки тому

    Thank you so much ❤️ for this wonderful tutorial. Would love to see more possibilities of theming. Hope we can control more looks like, border radius, background image, polygon shapes, different svg based on theme. It will bring great change in looks apart from colour alone. 👍👍 Keep rocking.

  • @faraonch
    @faraonch 10 місяців тому

    Fantastic demo! You could consider setting the default transparency value to 1 in function arg where you deconstruct the opacity value to avoid the if statement in the withOpacity.

  • @addd3231
    @addd3231 7 місяців тому

    Very helpful tutorial, few days ago I tried to build my app with custom theme colors, but this is more useful 🤯

  • @akamfoad
    @akamfoad 2 роки тому

    Will use this video as inspiration to theme my website soon, thanks for the great explanation and approach as always

  • @aleksandervitalevich1299
    @aleksandervitalevich1299 Місяць тому

    «Лёгким движением руки брюки превращаются… брюки превращаются… превращаются брюки… в элегантные шорты!» 👍👍👍

  • @_CazaBobos
    @_CazaBobos 2 роки тому +1

    I've been looking for this for very long. Thanks! It works amazingly with Next.js SSG
    Just a little trick: instead of asking if opacityValue is undefined, you can use a nullish coalescence operator to assign a default value when it's null or undefinded. Example... ${ opacityvalue ?? 1 }

  • @paawfrance
    @paawfrance 2 роки тому

    Thank you from France, your video is a game changer for me :)

  • @Andrey-il8rh
    @Andrey-il8rh 3 роки тому

    I've heard this punch from many people who hate (don't know how to use) Tailwind - that it can't be used on a "themeable project", thanks for myth-busting this argument!

  • @elie1400
    @elie1400 3 роки тому +84

    A list of your vscode extensions would be appreciated

    • @DaniloMarquesdeRezende
      @DaniloMarquesdeRezende 3 роки тому +2

      Agreed

    • @eYinka
      @eYinka 3 роки тому +1

      Honestly +1

    • @corey5974
      @corey5974 3 роки тому +7

      I believe the one that highlights the css colors is a plugin called Color Hight (naumovs.color-highlight) by Sergii Naumov

    • @DanielDrummond2k6
      @DanielDrummond2k6 2 роки тому

      Any one know how extension to convert color Hex to RGBA and vise versa?

    • @elie1400
      @elie1400 2 роки тому +2

      @@DanielDrummond2k6 hex-to-rgba by dakshmiglani

  • @Allformyequine
    @Allformyequine 2 роки тому

    ... and that is it!! LOL Fantastic and you sometimes make me laugh a little which is a giant bonus; Tailwind really has a gem with you and the way you do these videos! How long did they look to find a coder that is ALSO great in front of a camera lol! Rock on!

  • @jimmyj.6792
    @jimmyj.6792 3 роки тому

    So awesome 😍😍😍 simple as well with a great quality and some magic final tricks 😁👌🎉🎉

  • @lightningspeed6466
    @lightningspeed6466 2 роки тому +1

    Thanks it was really helpfull
    Was trying to figure it out for a long time

  • @raymondmichael4987
    @raymondmichael4987 2 роки тому

    This looks heavy and good to be done

  • @divdax4286
    @divdax4286 3 роки тому

    Love your videos and tailwindcss!

  • @renu3463
    @renu3463 3 роки тому

    Really like this series

  • @thomassaw
    @thomassaw 5 місяців тому

    Thank you so much for this video. Learned a lot!

  • @adrian1358
    @adrian1358 11 днів тому

    Great stuff, a lot of useful info, thank you 😊

  • @MikeStratton
    @MikeStratton 2 роки тому

    You make it look insanely easy. wait, maybe it is that easy!

  • @oliverp8006
    @oliverp8006 3 роки тому +7

    Great one, would be nice to have a follow up part about the best way to add/implement dark mode to the theming

  • @VuNguyen-yj5wi
    @VuNguyen-yj5wi 2 роки тому

    Thank you so much! It's so useful ❤️

  • @mkroven
    @mkroven 3 роки тому

    Thank u. Wonderful explanation.

  • @markconger8049
    @markconger8049 3 роки тому

    Should my brain hurt after watching this? LOL It does.
    I’m sure I’ll have to watch this series a couple of times through since my CSS skills are so-so.
    But, that said, I’m very impressed so far with Tailwind’s approach. It seems now we finally have CSS that is a programming language than whatever it was previously.

  • @dealloc
    @dealloc 2 роки тому

    I would just specify colors for specific states in the theme without the hassle of support bg-opacity, etc. It may seem odd, but if the idea is to give control to the theme of defining colors, then it makes more sense that it also controls the opacity.
    There are cases where you want to use a different opacity based on the contrast, as color is perceived differently based on the background and foreground contrast and the opacity will look lighter/darker depending on this. This is also why dark themes aren't simply just inverting the colors; contrast matters.

  • @ShinjaeKang
    @ShinjaeKang 3 роки тому

    Good tutorials, Thank you very much :)

  • @electrotsmishar
    @electrotsmishar 2 роки тому

    Thank you. Great tutorial

  • @sinyayadynya
    @sinyayadynya 3 роки тому

    What a masterpiece!

  • @jnetto
    @jnetto 3 роки тому +1

    Best teacher ever! Thanks for this tutorial!

  • @FauzulChowdhury
    @FauzulChowdhury 3 роки тому

    Superb content. 👏👏👏

  • @xithalius
    @xithalius 3 роки тому

    Great video!

  • @chethannp5981
    @chethannp5981 Рік тому

    The best tutorial ❤

  • @evanfuture
    @evanfuture 3 роки тому

    Amazing, I love it.

  • @andreich1980
    @andreich1980 3 роки тому

    Nice video, thank you.

  • @justine_chang39
    @justine_chang39 2 роки тому

    this video was awesome

  • @tamrat_assefa
    @tamrat_assefa 3 роки тому

    This is super cool.

  • @agnemedia624
    @agnemedia624 3 роки тому

    Thanks for tips, tricks and technics
    Wow

  • @visheshpandey2001
    @visheshpandey2001 5 місяців тому +1

    14:40 thats amazing!!!!!!!!!!

  • @amrishpatidar2579
    @amrishpatidar2579 2 роки тому

    great explanation

  • @valtism
    @valtism 3 роки тому +3

    The microphone is so big 🤣
    Thanks for the content as always!

    • @siewierap
      @siewierap 3 роки тому

      I always more appreciate good voice quality than a cam!

  • @techie607
    @techie607 3 роки тому

    I am trying to implement tailwind css struggling a lot but feeling confident as well

  • @wolfphantom
    @wolfphantom 2 роки тому +11

    The return value could be streamlined as an implicit return, but I would at least set the default @ 22:00 with ({ opacityValue = 1 }) rather than setting a guard check

    • @LorenzoLeonardini
      @LorenzoLeonardini 2 роки тому +2

      I have the feeling (but I could be totally wrong) that opacityValue is not the value itself but the name of the CSS variable for the opacity (--tw-bg-opacity)

    • @yakovlev_io
      @yakovlev_io 2 роки тому +1

      @@LorenzoLeonardini you are right, it’s an object destruction syntax { … }

  • @dibbyo456
    @dibbyo456 3 роки тому

    This is GOLD

  • @vesper8
    @vesper8 3 роки тому +3

    Amazing video! It would really helpful if you could share a gist or repo with the code too... also would love it if you could name a few of the plugins you're using on vscode.. notably the css preview when you hover a class and the one that highlights colors with their actual color. Many thanks!!

  • @AriBahtiar
    @AriBahtiar 3 роки тому

    thiank u.. i am happy with this video.

  • @adamtak3128
    @adamtak3128 3 роки тому +1

    Is this the theming strategy you suggest we use with the new JIT compiler in tailwindcss?

  • @Diamonddrake
    @Diamonddrake 3 роки тому

    Tailwind is love, tailwind is life.

  • @Andrey-il8rh
    @Andrey-il8rh 3 роки тому +1

    Just a small suggestion to make check inside withOpacity more succinct, you can just check for undefined like so opacityValue ?? 1 that way if it will be undefined it will default to 1, note that I'm using nullish coalescing operator here to support 0 values. It's natively supported in Node since v.14

  • @harrygreen1465
    @harrygreen1465 Рік тому

    Great video, thanks! It's a little outdated I think, as you can now define hex colours inside the tailwind config `theme`, and opacity variants will work without needing to add the logic yourself.

  • @Martin-4D
    @Martin-4D 3 роки тому

    Wow! That is the business!

  • @kohelet910
    @kohelet910 2 роки тому

    Using JS functions into CSS.. so cool

  • @TobiasSailer
    @TobiasSailer 3 роки тому +2

    Curious: is this vscode preview plugin public? Can't find it!

  • @neelabhdutta6691
    @neelabhdutta6691 2 роки тому

    I am thinking of using it to implement light/dark theme on user selection, so, do I have to change the wrapper class conditionally or dark:my-wrapper would work just like usual html with dark class ???

  • @zeroows
    @zeroows 2 роки тому +1

    Great work, Thank you.
    27:05 where did the fly came from :)

  • @VincentCordel
    @VincentCordel 8 місяців тому

    Great tutorial thank you!
    Quick question: is it possible to use the default tailwind colour palette in the css variables instead of the hex/rgb hardcoded values?
    In other words, something like:
    -colour-primary: Colors.red.700
    Instead of
    -colour-primary: rgb(255,179,255)

  • @jasarwadlow9406
    @jasarwadlow9406 3 роки тому +1

    Neat! Great video, it's well-explained and very easy to understand. Thanks!
    I have a question: can we use any existing tailwind colors (ie, text/bg-red-500)?
    Using the approach in the video, it looks like the same color may be redefined multiple times.
    aka, is it possible to create something like an Alias Token?
    Or is the only way to do this via the tailwind config (where we have access to the colors)?

    • @jasarwadlow9406
      @jasarwadlow9406 3 роки тому

      nvm, I think I found how:
      --color-fill: theme('colors.red.700');

  • @JimOHalloran
    @JimOHalloran 3 роки тому +2

    Kinda feels like with naming colours you're getting back into some of the "naming is hard" territory that utilities were meant to solve for us. But I don't see any other way around it.
    I'm working on my first Tailwind application at the moment which will eventually be forked off and used as the basis for many other apps. How the follow on apps get re-coloured without a massive search and replace to change a whole bunch of utilities was on my mind, so this is well timed.

  • @WalterKimaro
    @WalterKimaro 3 роки тому

    So good

  • @MasudRana-nx4rf
    @MasudRana-nx4rf 3 роки тому

    Awesome.

  • @devhamdani
    @devhamdani 11 місяців тому

    Can you tell me that which fonts you're using for your editor. I really love it.

  • @dorshiff
    @dorshiff Рік тому

    When it came to typography, there are some needed changes in different screen sizes, how do you define them in this method?

  • @SamAbaasi
    @SamAbaasi 2 роки тому

    Thanks a lot

  • @markokraljevic1590
    @markokraljevic1590 2 роки тому

    but what if i want to reuse colors from the palette like --accent-medium: theme('colors.pink.700'); and not hardcoding rgb values? theme('colors.pink.700') is hex value and I need to convert to rgb somewhere

  • @magnusandersson2495
    @magnusandersson2495 3 роки тому

    Why split and convert the hex code to rgb values in your with opacity function instead of using the vscode plug-in? Javascript has parseint-function that can do this.

  • @palyanytsia
    @palyanytsia 3 роки тому +5

    What's the plugin you are to preview colors in css?

  • @myxsys
    @myxsys 2 роки тому

    The opacity function doesn't work in Tailwind CSS v3.0.24. However, returning `var(${variableName})` works without wrapping `rgb` or `rgba`

  • @benjaminmaywald660
    @benjaminmaywald660 3 місяці тому

    Thanks for the whole Playlist ...your microphone is getting bigger with every video ;-)

  • @chaes1161
    @chaes1161 3 роки тому +2

    Great!
    Is there any way to enable color preview using this approach?

    • @huannguyen6559
      @huannguyen6559 2 роки тому +1

      You can still use rgb(0,0,0,1) in your css file for color preview but need to remove "rgb" and "alpha" in the "withOpacity" function

  • @JustinByrne1337
    @JustinByrne1337 3 роки тому

    Does anyone know how to get that preview panel in VSCode I can't find one that looks that good

  • @jameelahamedmca
    @jameelahamedmca 2 роки тому

    Usefull Thanks

  • @iamdavidwparker
    @iamdavidwparker 3 роки тому +1

    I implemented multiple themes on a site of mine last year. 12 themes light + dark mode. It was super simple, though I _think_ this may be even easier. Can't wait to try it out!
    Note: not sure why my last comment was deleted? Due to link?

    • @TailwindLabs
      @TailwindLabs  3 роки тому

      Not sure either, I did see the notification email though originally! We didn’t delete it, must be a UA-cam thing probably link related like you said 🤔

    • @iamdavidwparker
      @iamdavidwparker 3 роки тому

      @@TailwindLabs probably. Not worried about it. Thanks for the video, the timing is perfect.

    • @SusanthCom
      @SusanthCom 3 роки тому

      Could you please share your implementation. Would like to learn more about theming ❤️ Thanks 👍in advance

    • @SusanthCom
      @SusanthCom 3 роки тому

      @david Parker ❤️❤️

  • @stctheproducer
    @stctheproducer 3 роки тому

    First comment! 🥳 Thanks for this video 🙏🏾

  • @lenartpapez2512
    @lenartpapez2512 3 роки тому +1

    This looks amazing, but I can't seem to get it to work in a new Angular project (v11.2). Neither with CSS or SCSS. Any news on that?

    • @g-luu
      @g-luu 2 роки тому

      did you manage to get it working? seems to work on development but not in production

  • @matthewblott
    @matthewblott 3 роки тому

    Genius :-)

  • @codementor3974
    @codementor3974 Рік тому

    i have a problem ,if we set opacity-x for bg-theme-x not only bg opaicty changed even text opacity turn chnaged , what to do in this situation please guide

  • @JohnSmith-zl8rz
    @JohnSmith-zl8rz 3 роки тому

    You only use textColor and backgroundColor, so I need go to each tailwind config and add those again, like "divideColor", "caretColor" etc. ???

  • @brianzitzow4411
    @brianzitzow4411 3 роки тому

    Any reason you are using CSS Custom Properties rather than plugins that add the utilities and use theme properties with the values defined directly in the theme?

  • @helloiamjoshie
    @helloiamjoshie 2 роки тому

    How would one go about setting up border colors this way?

  • @andelkocvjetkovic7249
    @andelkocvjetkovic7249 3 роки тому

    👏👏👏

  • @hcsftw
    @hcsftw 3 роки тому

    Thank you! Could you provide the code somewhere?

  • @ahmedosama7632
    @ahmedosama7632 3 роки тому +1

    Make a video on RTL with tailwind

  • @lcapocer
    @lcapocer 2 роки тому

    When I use Vue-Cli and run a build only the :root theme is inside the generated css file, why is that?

  • @mircast0
    @mircast0 Рік тому

    Thank you young James Hetfield!

  • @gabrielalvescunha9405
    @gabrielalvescunha9405 Рік тому

    Damn! I rarely comment, but this one: 👍!

  • @ray-lee
    @ray-lee 3 роки тому

    how about dark theme? is it just dark:theme-name?

  • @joeregan.
    @joeregan. 3 роки тому +1

    Why doesn't tailwind include classes like primary by default like other popular frameworks like bootstrap and uikit?

  • @ulrichmbouna4091
    @ulrichmbouna4091 3 роки тому

    About new tailwindcss/jit , i have problemes with postcss 8 in vue 3 project , how can i do please?

    • @macbruker
      @macbruker 3 роки тому +1

      Try searching for a similar issue in the tailwindcss/jit github repo. If you don't find an existing issue, you can add one of your own. It could be that you are missing the NODE_ENV=development variable. Instructions for this is in the readme file in the repo.

  • @sushardianto8039
    @sushardianto8039 3 роки тому

    Thank you. Please, share the code link

  • @JohnSmith-zl8rz
    @JohnSmith-zl8rz 3 роки тому

    text-skin-base is confusing, sounds very close to text-base (size), what about text-skin-content ?

  • @userquin
    @userquin 3 роки тому

    take a look at windicss with vite

  • @QWERTY-mh2hb
    @QWERTY-mh2hb 8 місяців тому

    It's possible to do this with React Native?

  • @diego5g
    @diego5g 3 роки тому

    What is your VSCode theme?