Responsive Design and Dark Mode
Build layouts that adapt to any screen with mobile-first breakpoints and add a polished, user-aware dark mode using CSS variables and Tailwind.
Responsive Design and Dark Mode is a free Next.js 15 Fullstack Web Apps lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Next.js 15 Fullstack Web Apps learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Mobile-First Thinking
Responsive design means one layout that adapts to phones, tablets, and desktops. The modern approach is mobile-first: style the small screen first, then add enhancements for larger ones.
Media Queries
The CSS @media rule applies styles only above (or below) a width. Mobile-first uses min-width breakpoints.
.grid { display: block; }
@media (min-width: 768px) {
.grid { display: grid; grid-template-columns: 1fr 1fr; }
}Fluid Units
Prefer relative units so layouts scale naturally:
remfor spacing and font size%andfrfor widthsclamp()for fluid typography
h1 { font-size: clamp(1.5rem, 4vw, 3rem); }Tailwind Breakpoints
Tailwind makes responsiveness inline with prefixes like sm:, md:, lg:. Unprefixed classes are the mobile base.
<div class="block md:grid md:grid-cols-2 lg:grid-cols-3">Flexbox and Grid
Two layout engines cover almost everything:
- Flexbox for one-dimensional rows or columns
- Grid for two-dimensional layouts
Combine them and let breakpoints reflow content.
What Is Dark Mode?
Dark mode swaps a light palette for a dark one to reduce eye strain and save battery on OLED screens. A good implementation respects the user system preference and lets them override it.
System Preference
The CSS media feature prefers-color-scheme detects the OS theme so you can default to what the user already chose.
@media (prefers-color-scheme: dark) {
body { background: #111; color: #eee; }
}CSS Variables for Theming
Define colors as CSS custom properties on the root, then override them for dark mode. Components reference variables, so a single switch repaints the whole app.
:root { --bg: #fff; --fg: #111; }
[data-theme='dark'] { --bg: #111; --fg: #eee; }
body { background: var(--bg); color: var(--fg); }Tailwind Dark Variant
Tailwind ships a dark: variant. Toggle a dark class on the html element and dark utilities activate.
<div class="bg-white text-black dark:bg-gray-900 dark:text-white">Persisting the Choice
Store the user choice in localStorage and apply it before paint to avoid a flash of the wrong theme. Libraries like next-themes handle this cleanly in Next.js.
const theme = localStorage.getItem('theme') || 'system';
document.documentElement.dataset.theme = theme;Accessibility & Contrast
Whatever the theme, keep text readable. Aim for a contrast ratio of at least 4.5:1 for body text per WCAG. Test both themes; a color that works on white may fail on dark.
Quick Check
Test your responsive and theming knowledge.
Recap
You learned adaptive styling:
- Mobile-first media queries and fluid units adapt layouts
- Tailwind
md:/lg:prefixes make breakpoints inline - CSS variables plus
prefers-color-schemepower dark mode - Persist the choice and keep contrast accessible in both themes
Frequently asked questions
Is the “Responsive Design and Dark Mode” lesson free?
Yes — the full text of “Responsive Design and Dark Mode” is free to read here on the web, and the Next.js 15 Fullstack Web Apps course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Next.js 15 Fullstack Web Apps course, upgrade to CoddyKit PRO.
What will I learn in “Responsive Design and Dark Mode”?
Build layouts that adapt to any screen with mobile-first breakpoints and add a polished, user-aware dark mode using CSS variables and Tailwind. You practise Next.js 15 Fullstack Web Apps with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Next.js 15 Fullstack Web Apps?
No prior experience is required. Next.js 15 Fullstack Web Apps on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Responsive Design and Dark Mode” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Next.js 15 Fullstack Web Apps lesson?
Yes. Every Next.js 15 Fullstack Web Apps lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- CSS Modules and Global Styles
- Integrating Tailwind CSS
- Component Libraries and Theming
- Responsive Design and Dark Mode