Dark mode with TailwindCSS in under 7 minutes

  Рет қаралды 44,850

Built With Code

Built With Code

Күн бұрын

Пікірлер: 105
@hawkdawg443
@hawkdawg443 11 ай бұрын
Thanks man, that transition part is a cherry on top
@fulviavaz
@fulviavaz 9 ай бұрын
Amazing! Your solution is much simpler that I was trying! Thanks!
@ethan.creates
@ethan.creates Жыл бұрын
Dope video man! Loved the transition tip and everything else was very clear!
@razeku1332
@razeku1332 Ай бұрын
Best tutorial i saw been 4 times watching same tutorial still doenst understand,, but this amazing thanks man
@dr.insane9929
@dr.insane9929 7 ай бұрын
Thanks brotha, The transition was a lifesaver.
@nisargjaiswal4264
@nisargjaiswal4264 Жыл бұрын
Suggestion for video: Keep mobile users in mind, so zoom in the code for better readability. Nice video, keep it up buddy ✌️
@builtwithcode
@builtwithcode Жыл бұрын
Thanks for the callout, will try to zoom in more in the future.
@bryan_11016
@bryan_11016 3 ай бұрын
Thanks a lot mate. I was struggling with Dark mode in Tailwind and you made it look simple. Appreciate it👍❤
@the.mackuha
@the.mackuha Жыл бұрын
Straight to the point! Thanks man🔥
@builtwithcode
@builtwithcode 11 ай бұрын
Thanks for watching, glad it was helpful!
@felipepadovani6263
@felipepadovani6263 10 ай бұрын
Excellent dude !! helped me a lot
@masoodacheampong5385
@masoodacheampong5385 7 ай бұрын
Thank you very much, at the end, I knew you would use useState to handle the transition, so I did mine just like that.
@vladanisov1689
@vladanisov1689 11 ай бұрын
This was incredibly helpful, thank you my man!
@builtwithcode
@builtwithcode 11 ай бұрын
Glad to hear it!
@chadvise3308
@chadvise3308 5 ай бұрын
This was so helpful thanks for the content ❤
@francesco_gramazio
@francesco_gramazio 7 ай бұрын
freaking awesome, thanks mate !
@DEBUGENTITY
@DEBUGENTITY 11 ай бұрын
Loved this video.. Thanks for making this🎉
@AmanMarve-ge3md
@AmanMarve-ge3md Күн бұрын
Great Video 🔥
@sybrespect3161
@sybrespect3161 10 ай бұрын
you just got a new subscriber 👍🏾
@AndrewDBrown2020
@AndrewDBrown2020 14 күн бұрын
Perfect - thank you.
@TusharVerma-i1k
@TusharVerma-i1k Ай бұрын
i created this button in navbar , now i am using this navbar in every component but the color is changing only in navbar not everywhere, how to solve this?
@angeline9552
@angeline9552 9 ай бұрын
This is so helpful, thank u :)
@musicworld1717
@musicworld1717 10 ай бұрын
it helped me immensly..thanks bro
@abishekbaiju1705
@abishekbaiju1705 6 ай бұрын
Excellent tutorial. thanks a lot
@builtwithcode
@builtwithcode 5 ай бұрын
Glad it was helpful!
@akshaykumar-xu2be
@akshaykumar-xu2be 10 ай бұрын
Thanks bro. 💯Worth watching . just SUBSCRIBED
@builtwithcode
@builtwithcode 10 ай бұрын
Glad it was helpful!
@chan4est
@chan4est 7 ай бұрын
Super helpful! I'm curious how you handle both use cases at once. Basically using the user's preferred theme during first site use but once the user chooses their preferred theme, it overrides their OS's preference upon every revisit. Also how do you handle images that need to be swapped out in dark mode?
@builtwithcode
@builtwithcode 7 ай бұрын
You'll want to store the preferred theme in localStorage. If you see that the storage is empty, then default to the OS preference. For images, I imagine the best way is to have the theme stored in some sort of global state (e.g., with React Context), then dynamically set the img src based on which theme is active.
@davonne007
@davonne007 11 ай бұрын
Definitely doing this .,.!!
@K4NEKIIIIa
@K4NEKIIIIa 3 ай бұрын
how we can make the navbar dark mode on all the pages??
@Kyruu28
@Kyruu28 7 ай бұрын
So instead of using text, I chose to use icons for the toggle instead. I wonder how to add transition for the toggle icon so it can fade or spin etc. ? I've tried added transition class to the icon element but it doesn't work...
@builtwithcode
@builtwithcode 7 ай бұрын
Framer Motion would help here to animate when one icon unmounts and another comes into view
@killiankavanagh3854
@killiankavanagh3854 10 ай бұрын
Thanks so much man
@nonefvnfvnjnjnjevjenjvonej3384
@nonefvnfvnjnjnjevjenjvonej3384 6 ай бұрын
so how does tailwind get the dark mode actually. does it set it to dark on the html element?
@tasfin660
@tasfin660 7 ай бұрын
for some reason after writing * { @apply transition-colors duration-200; } this, all my other transition duration not working
@ahrenwagner2993
@ahrenwagner2993 5 ай бұрын
Great video :) Is there a way to do this without needing to prefix dark in your markup?
@builtwithcode
@builtwithcode 5 ай бұрын
The prefix is how tailwind recognizes which styles to apply in light vs dark mode. You could leverage a "non-Tailwind" approach using CSS variables and the prefers-color-scheme CSS selector. At that point I just prefer the "dark" prefix :)
@Yesterday_i_ate_rat
@Yesterday_i_ate_rat 10 ай бұрын
Top notch content❤
@alexdin1565
@alexdin1565 5 ай бұрын
thanks bro please can you make your video about "Custom themes with TailwindCSS in under 9 minutes" with this ? i mean user can switch thems and change from dark and light in same time
@MyGeorge1964
@MyGeorge1964 Жыл бұрын
Is there is way to abstract all of the dark mode css to the tailwind config and maybe the stylesheet so that you only need to specify one variable in the html or jsx that will change depending on whether it's dark or light?
@builtwithcode
@builtwithcode Жыл бұрын
Yes you can definitely do this. One way is to use reusable components so you add the light and dark mode classes once in the component definition and have multiple instances. The other is in the stylesheet you can use the @apply declaration and directly use the appropriate tailwind classes in CSS.
@cabaucom376
@cabaucom376 11 ай бұрын
What if you wanted a dropdown menu for “system”, “dark”, “light”? I would like system to be the default but if someone specifies then update accordingly.
@builtwithcode
@builtwithcode 11 ай бұрын
The system value is stored in the `prefers-color-scheme` CSS property. In TS/JS you can check if it's dark using `window.matchMedia('(prefers-color-scheme: dark)').matches`
@lolhp._.
@lolhp._. 6 ай бұрын
anyone know how to do the same thing but for the html tag?
@aldrinwong6160
@aldrinwong6160 Ай бұрын
simple! this helps!
@ahmedahmedx9600
@ahmedahmedx9600 8 ай бұрын
What if i want also the darkmode got saved in browser when toggling the button so if its still darkmode even when page refreshed
@builtwithcode
@builtwithcode 8 ай бұрын
You can store the active theme in local storage and read it on page load
@nested9301
@nested9301 6 ай бұрын
cookies + server side rendering
@martinfriday5481
@martinfriday5481 7 ай бұрын
I created a button component and applied this dark and light mode to it, but when I call the component in another component and write "dark" styles, it doesn't work, is there any way around this??
@builtwithcode
@builtwithcode 7 ай бұрын
Did you setup dark mode in the tailwind config?
@martinfriday5481
@martinfriday5481 7 ай бұрын
@@builtwithcode yea, I did everything there, but the dark mode only applied to that button component and when I exported it to a page, it didn't affect the rest of the page
@builtwithcode
@builtwithcode 7 ай бұрын
Are you applying the “dark” class to the root body or html tag? Tailwind should then enable dark mode for all the children
@martinfriday5481
@martinfriday5481 7 ай бұрын
@@builtwithcode I should add the dark class to the HTML?
@martinfriday5481
@martinfriday5481 7 ай бұрын
@@builtwithcode Then how will my button component toggle the dark mode on and off on button click, that's the issue
@nested9301
@nested9301 6 ай бұрын
oh tailwind is awesome !!
@angeline9552
@angeline9552 9 ай бұрын
how would you implement a site-wide light/dark mode toggle?
@builtwithcode
@builtwithcode 9 ай бұрын
Store the state in the main App component, then apply the "dark" class in the or at the top App level.
@martinfriday5481
@martinfriday5481 7 ай бұрын
How??? I created a button component that I want to reuse across the site, how do I make it toggle the whole thing
@rayudubharani
@rayudubharani 7 ай бұрын
sir what about system default
@moistmangomilkshake347
@moistmangomilkshake347 18 күн бұрын
THANK YOU
@maeel
@maeel 10 ай бұрын
can i have a list of every vs code extension do you have for react?
@builtwithcode
@builtwithcode 10 ай бұрын
The main ones I use in my workflow: - ES7+ React/Redux/React-Native snippets - Tailwind CSS IntelliSense - Prettier - Code formatter - Error Lens
@maeel
@maeel 10 ай бұрын
thanks a lot @@builtwithcode
@qotibamhamed6467
@qotibamhamed6467 10 ай бұрын
I'm experiencing an issue where, when I switch to light mode in my system, dark mode functions perfectly. However, when I enable dark mode in my system, the toggle between dark mode and light mode doesn't work. Can someone please assist me with this problem? (I replicated your steps exactly for importing dark mode in Tailwind.)
@builtwithcode
@builtwithcode 10 ай бұрын
Hmm that's odd. Did you update the Tailwind config file to use "class" for dark mode functionality?
@anonymoussloth6687
@anonymoussloth6687 Жыл бұрын
Could u do a video with dark mode using css variables - which could be extended to multiple themes
@builtwithcode
@builtwithcode Жыл бұрын
Thanks for the suggestion, I'll consider it for a future video.
@AnkitKumar-dy5um
@AnkitKumar-dy5um 8 ай бұрын
That's super easy :)
@userre85
@userre85 8 ай бұрын
Which VS code theme are you using?
@builtwithcode
@builtwithcode 8 ай бұрын
"Dark Modern" that comes with vscode
@adityarajawat3185
@adityarajawat3185 Жыл бұрын
Nice explanation
@builtwithcode
@builtwithcode Жыл бұрын
Thanks!
@daniali4619
@daniali4619 11 ай бұрын
Can its change multiple pages mood, i means if we set toggle btn in nav bar then how to change multiple pages dark mood i think then its not work, I'm right or not ?
@builtwithcode
@builtwithcode 11 ай бұрын
For using across an entire website, you'll want to setup a React Context that stores the theme value, and then wrap the entire app in that context's provider. You then connect the toggle button to update the value in the context, which will propagate to other pages.
@TOONSSTATION
@TOONSSTATION 4 ай бұрын
Nice
@deelakaransilu814
@deelakaransilu814 3 ай бұрын
thank u ❤
@mhalwasoffice6132
@mhalwasoffice6132 4 ай бұрын
how can i share this useState betwen the componants
@builtwithcode
@builtwithcode 4 ай бұрын
If you want to share across multiple components, consider using state management such as React Context and storing the theme information there
@mhalwasoffice6132
@mhalwasoffice6132 4 ай бұрын
@@builtwithcode ty
@DrJake-dl7rg
@DrJake-dl7rg 9 ай бұрын
what if we want to refresh the page?
@builtwithcode
@builtwithcode 9 ай бұрын
You would need to persist the state in storage, e.g., using LocalStorage.
@DrJake-dl7rg
@DrJake-dl7rg 9 ай бұрын
@@builtwithcode yeah thanks for replying! I'm having a rough time connecting the react state and Local Storage properly and couldn't find a good tutorial about that, yours was good tho.
@sai-oduri
@sai-oduri 3 ай бұрын
thanks
@tutopoints1920
@tutopoints1920 7 ай бұрын
Nice One
@abhishekchaudhary4058
@abhishekchaudhary4058 8 ай бұрын
Thanks
@rishabhagrawal8938
@rishabhagrawal8938 11 ай бұрын
How to add one condition inside an another condition like inside dark want to add another condition . Please help it is urgent or please share Where I can talk to yo
@builtwithcode
@builtwithcode 11 ай бұрын
What type of other condition? If it's something stored in a component variable, then in the styling class names you can use a ternary operator with the variable and use the "dark" prefixing to limit the styling to dark mode.
@sad_man_no_talent
@sad_man_no_talent 5 ай бұрын
thx
@deylerdeyler6401
@deylerdeyler6401 10 ай бұрын
does this work on next 13?
@builtwithcode
@builtwithcode 10 ай бұрын
Yes this should work on Next 13
@reyu_
@reyu_ 2 ай бұрын
the problem with this is when you set to darkmode then you refresh the page then it will back to light
@builtwithcode
@builtwithcode 2 ай бұрын
One way around this is to store the active theme in local storage. Then every time you load the page read from there to initialize the theme.
@kruthiks5400
@kruthiks5400 3 ай бұрын
Thank you man
@lawalmuktair5617
@lawalmuktair5617 6 күн бұрын
@pastiille7467
@pastiille7467 9 ай бұрын
merci
@01dom
@01dom 4 ай бұрын
Not good to be honest, would be better to define colors and change them with css so you wouldn't have to write dark everywhere
@danishnazirpeer3422
@danishnazirpeer3422 4 ай бұрын
That's what i was thinking when i clicked the video. Instead we got the most basic approach.
@AhmedMohamed-hz9bs
@AhmedMohamed-hz9bs 8 ай бұрын
❤❤❤❤
@arupde6320
@arupde6320 Жыл бұрын
be regular
@haha-eg8fj
@haha-eg8fj 10 ай бұрын
In my case I don’t need to give my document a dark class name and it just works after I confige tailwind.config.ts. I don’t know why.
@SrEdgar
@SrEdgar 5 ай бұрын
how?
@EswarRemoteEnginneer
@EswarRemoteEnginneer Ай бұрын
thanks
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Рет қаралды 200 М.
Custom themes with TailwindCSS in under 9 minutes
8:40
Built With Code
Рет қаралды 10 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Build a dark mode light mode in reactjs with context api
29:20
Hitesh Choudhary
Рет қаралды 34 М.
8 TailwindCSS Classes I Wish I Found Earlier
4:48
Tom Is Loading
Рет қаралды 78 М.
Next Js Tutorial -  Dark & Light Themes using Shadcn / UI
19:33
You’re doing dark mode wrong!
7:54
Coding in Public
Рет қаралды 55 М.
Next.js Dark Mode with No Flicker + Tailwind CSS
9:43
Dave Gray
Рет қаралды 42 М.
CSS Dark Mode Toggle Button from scratch in 6 Minutes
6:58
Red Stapler
Рет қаралды 93 М.
I WISH I Knew These Tailwind Tips Earlier
9:15
Theo - t3․gg
Рет қаралды 200 М.
10 Tailwind Tricks You NEED To Know!
10:45
Ravi - Perfect Base
Рет қаралды 313 М.
The Best Way to Handle Dark Mode with TailwindCSS
3:49
Tom Is Loading
Рет қаралды 34 М.
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН