Theming Tailwind with CSS Variables

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 179

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

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

  • @Сергей-й9т7ъ
    @Сергей-й9т7ъ 2 роки тому

    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!

  • @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.

  • @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!

  • @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!

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

    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

  • @_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 }

  • @yashkhd1100
    @yashkhd1100 3 роки тому +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.

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

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

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

    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.

  • @wolfphantom
    @wolfphantom 3 роки тому +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 3 роки тому +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 { … }

  • @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

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

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

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

    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.

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

    your guys make tailwind CSS custom feature amazing!

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

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

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

    ... 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!

  • @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!

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

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

  • @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.

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

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

  • @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

  • @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!!

  • @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.

  • @subhashmalireddy
    @subhashmalireddy 2 місяці тому

    WOW 🤯 and thank you. I'm pretty new to tailwind, is the theming config especially the stuff related to opacity still relevant(I'm guessing YES, but still wanted to confirm)?

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

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

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

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

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

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

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

    Best teacher ever! Thanks for this tutorial!

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

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

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

    This looks heavy and good to be done

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

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

  • @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');

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

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

  • @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`

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

    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)

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

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

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

      I always more appreciate good voice quality than a cam!

  • @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.

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

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

  • @tonyemmanuel8045
    @tonyemmanuel8045 2 місяці тому

    How about adding spacing like padding to the skin? Is there any specif group name required for that skin ?

  • @razafindrakotojosephin6151
    @razafindrakotojosephin6151 13 днів тому

    i'm quite new to tailwind. Using the withOpacity utility function on typescript doesn't work. How can we implement such utility function for ts?

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

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

  • @parenteseswebdev
    @parenteseswebdev 2 місяці тому

    Would you know a problem that i have. I used tailwind cli to make a website using the stock install procedures. The website looks and functions fine in local vsc dev, but when i upload to server to the htdocs folder all the html files and the output.css, the styling isn't applied. Could you advise.

  • @adrian1358
    @adrian1358 4 місяці тому

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

  • @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

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

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

  • @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

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

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

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

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

  • @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

  • @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 3 роки тому

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

  • @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.

  • @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. ???

  • @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.

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

    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 ???

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

    @18:56 Couldn't you just use Tailwind's opacity variable? Like so:
    'muted': rgba( var( ---color-text-muted ), var( --tw-text-opacity, 1 ) )
    Just tested and that seems to work fine! Way easier than the function.

    • @Mike-lu1pt
      @Mike-lu1pt 2 роки тому

      I was wondering why he didn't just do that, but I think it's because the opacity variable is different for different properties. Right?

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

      1. To make sure your code won't break when the variable name changes
      2. To reset the opacity value. Notice the generated class adding "--tw-text-opacity: 1" above. Without resetting, any bg-opacity class in the parent would persist.

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

      then you're locked down with the hardcoded classname --tw. what if next version they decide to use --tw4-text-opacity?

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

    Tailwind is love, tailwind is life.

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

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

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

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

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

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

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

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

  • @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?

  • @zeeeeeman
    @zeeeeeman 6 місяців тому

    All that function nonsense is no longer needed now. You can just use hex values if you wish. Example: bg-skin-base/10 for 10% opacity on the base background color. Wonderful improvements since 2021.

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

      Thanks for confirming that. I was just about to test the same.

    • @MD-kb8zt
      @MD-kb8zt 5 місяців тому

      I tried this and seems to still not be working. Do I need to define something in the globals.css or tailwind config?

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

      @@MD-kb8zt I did not get around to trying this out at the time. After reading your comment this morning I went and implemented it and I can confirm that / opacities etc do not work by default with the latest version of Tailwind. @zeeeeeman can you confirm this is actually working for you? If so, would you mind sharing your configurtation?

    • @MD-kb8zt
      @MD-kb8zt 5 місяців тому +1

      @@kieran5746 I found a solution. Look for “Customizing Colors” in the tailwind documentation then ctrl f to find “”alpha-value” and it goes over how to define your variables to use the method listed in the original comment

    • @kieran5746
      @kieran5746 4 місяці тому

      @@MD-kb8zt Thank you so much for updating your comment with a solution. I am not currently at a PC but I will try this ASAP. Thanks again!

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

    Using JS functions into CSS.. so cool

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

    The best tutorial ❤

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

    I completely agree with the concept, but the css-variables suck because of type safety, I wish there was a way to enforce your themes to have the same variables

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

    With new TS config it's problematically to implement such function like ({opacity}) => `blabla` to "colors" section

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

      I am getting TypeScript errors for the withOpacity function that make me nuts. I had to use a return type of "any" which makes me squirm a little.

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

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

  • @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 ❤️❤️

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

    Thank you young James Hetfield!

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

    Make a video on RTL with tailwind

  • @CodeFusionDev
    @CodeFusionDev 2 місяці тому

    Kindly use latest tailwind css v3.4.*
    in adding opacity to color

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

    At this point, TW is not adding on top of CSS, but becoming a language of its own. Something many devs won't welcome. This is an unnecessary complexity. Good for prototyping and all, but not sure if this is something I would like in my final product.

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

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

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

    is this still the way to go? I guess since it's over a year ago, there might be a nice approach, so don't have to use this 'unsupported' rgb format . . ?

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

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

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

    Thank you! Could you provide the code somewhere?

  • @QWERTY-mh2hb
    @QWERTY-mh2hb Рік тому

    It's possible to do this with React Native?

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

    Love your videos and tailwindcss!

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

    Thank you. Please, share the code link

  • @visheshmp
    @visheshmp 9 місяців тому +1

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

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

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

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

    What is your VSCode theme?

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

    this video was awesome

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

    Thank you. Great tutorial

  • @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.

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

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

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

    Thanks for tips, tricks and technics
    Wow

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

    at 22:07 (guarding against undefined) you should be able to avoid blocks entirely by using a ternary in your interpolation like so: ${ opacityValue !== undefined ? opacityValue : 1 } ... and even simpler, since opacity:0 is unlikely, like so: ${ opacityValue || 1 } (taking advantage of truthiness, even though 0 is a possible but unlikely input since it would be a strange way to specify invisibility. 🤦🏻‍♂️)

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

      thanks you're solve my problem , I did not put an equal operator

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

      Just do this: ({ opacityValue = 1 }) => { ... }, problem solved. No need for ternaries or short circuits.

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

    Any reason one you couldn't/shouldn't just define the theme colors as `rgba` and use the text-opacity thing directly? So instead of `--color-fill: 185, 28, 28;` and that `withOpacity` function, just do `--color-fill: rgba(185, 28, 28, var(--tw-text-opacity));`? Not sure I understand what the `opacityValue` and helper function you made does "more", and feel like I'm missing something here. 🤔

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

      Then if you used it for a background color it would adopt the text opacity instead of the background opacity. The variable name changes depending on how the color is used, for example:
      That uses two different opacity variables, so if you bake it right into the color one of the won't work.

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

      @@TailwindLabs Aaaah! Knew there had to be something I was missing. Thank you for quick reply!
      Started using Tailwind for the first time last week on a new side-project of mine and I'm LOVING IT 💙

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

    great explanation

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

    Thank u. Wonderful explanation.

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

    Superb content. 👏👏👏

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

    Any chance you could share the code on play.tailwind?

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

    Good tutorials, Thank you very much :)

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

    Wow! That is the business!

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

    Was wondering about how this would be done for building a light/dark theme. Thanks!
    Really breaking away from IE here as it doesn't support css variables anywhere except in the root. I love this design though and hope my company can ditch IE soon.

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

      Tailwind actually has a dark mode, check out the docs and you can implement with that

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

      You can try using "prefers-color-scheme" media query for the dark theme preference. Set the :root selector to the dark color palette inside the media query. Except IE11 all browsers support it so they'll switch to dark theme if the user has set his/her preference for the dark theme. IE11 will ignore it and will use your default color palette.

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

    This is GOLD

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

    I can't find "skin" documentation on tailwindcss website? anyone?

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

      skin is an arbirary but sematic color name added to the config . it coud be named anything ;-) and would work the same