Dark Mode
React.js
easy
25 mins
You have to build a simple Dark Mode Toggle component in React. The goal is to allow users to switch between light mode and dark mode by toggling a checkbox. The theme should visually update the background color , text and text color .
Things To Do
-
State Management
- Add a
useStatehook to keep track of whether the app is in dark mode or light mode.
- Add a
-
Toggle Function
- Implement the
toggleThemefunction to update the state when the checkbox is toggled.
- Implement the
-
Dynamic Class Application
- Apply the class
dark-modeorlight-modeto the parent<div>based on the value of state variable.
- Apply the class
-
Text Label
- Update the
<span className="mode-text">to show"Dark Mode"or"Light Mode"depending on the current theme.
- Update the
Important Note
- Apply the class
dark-modeto the parent<div>when dark mode is active. - Apply the class
light-modewhen light mode is active.
Reference UI

Preview what you need to build
Companies:
meesho
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
