Dark and Light Mode — Using React & Tailwind CSS
You can add the Dark and Light Mode feature to your application if your users choose to walk on the dark side???
Let’s speak a bit about what dark mode is at first.
The dark mode is an effective experience solution created to increase the user experience.?Dark Mode?also known as a?Night Mode?is a popular feature that alters the colour scheme of a user interface (UI).
Many studies show that it is being preferred by users.
A?survey?figured out that out of 2,514 total votes, an overwhelming 81.9% of?Android Authority?readers use dark mode on their phones, in apps, and wherever else it’s available. 9.9% said they’re somewhere in between dark and light mode, meaning 91.8% of voters use some form of a dark mode on their smartphones. Just 8.2% said they don’t use dark mode at all as you can see below chart.
We can clearly see the curiosity of users about dark mode support for popular applications, especially Snapchat, Chrome, Facebook, Youtube and Safari.
In addition, we can clearly see the curiosity of users about dark mode support against popular applications.
Let’s talk about the advantages and disadvantages of the dark mode feature in terms of users and devices.
?? Advantages
Personal tastes and preferences vary, but users report that they prefer dark-themed software over light-themed one not only because of the above advantages but also it looks more simplistic and sophisticated and generally looks more “cool”.
?? Disadvantages:
Let’s code ?? ??
First, let’s install the packages required for our project.
1. Add Tailwind CSS to the React Project
Thanks to the Dark Mode support provided by Tailwind CSS, we can use this support in our application by simply adding the?dark: prefix to the CSS classes.
领英推荐
To learn more and review examples ??
2. Let’s include a nice icon animation package developed for dark/light mode transition with React.
All we need is;
We need a UI component such as a switch, checkbox, button or radio to enable the user to switch to Dark/Light mode. The switch component was my choice for this case. Because why not?
Bonus feature:?The last preferred mode of the user is saved in the browser (on localStorage) and when the user refreshes the page, he/she can continue with his/her last preferred mode. You can also see this feature by clicking the live demo link below and experiencing the last mode you prefer when you refresh your page by default.
Result
Congrats, now you can skip to the dark side! ??
The live demo link below??
Please feel free to comment and put your thought into this post. If you like what you read, don’t forget to clap ??
Founder, CEO @ Cre8 Team | Helping digital products companies and startups reach their business goals via effective UI/UX design solutions
4 个月Omer, thanks for sharing!
UI / UX Designer | Product Designer | Web Designer | Mobile Designer | Figma
2 年????
B2B SaaS Marketing Manager | Data Science Enthusiast
2 年??