Overview
Natours implements a comprehensive responsive design system using a centralized mixin-based approach. The system uses desktop-first design with strategic breakpoints for tablets and mobile devices.While modern best practices often favor mobile-first, Natours uses a desktop-first approach with max-width media queries, which is perfectly valid for projects designed primarily for desktop viewing.
The Respond Mixin
The core of the responsive system is therespond mixin located in sass/abstracts/_mixins.scss:
sass/abstracts/_mixins.scss
Breakpoint System
Phone
0 - 600px (
max-width: 37.5em)Mobile phones in portrait orientation. Smallest screens with single-column layouts.Tablet Portrait
600px - 900px (
max-width: 56.25em)Tablets in portrait mode. Medium-sized screens with simplified layouts.Tablet Landscape
900px - 1200px (
max-width: 75em)Tablets in landscape mode and small laptops. Approaching full desktop layout.Big Desktop
1800px+ (
min-width: 112.5em)Large desktop monitors. Enhanced sizing for ultra-wide screens.Breakpoint Reference
- Overview
- Conversion
| Breakpoint | Min Width | Max Width | Em Value | Use Case |
|---|---|---|---|---|
| phone | 0px | 600px | 37.5em | Mobile phones |
| tab-port | 601px | 900px | 56.25em | Tablet portrait |
| tab-land | 901px | 1200px | 75em | Tablet landscape |
| desktop | 1201px | 1800px | — | Default styles |
| big-desktop | 1801px | ∞ | 112.5em | Large screens |
Usage Examples
Base Font Sizing
The most fundamental responsive implementation is in_base.scss:
sass/base/_base.scss
Tablet Landscape
At 1200px and below, font size reduces to 56.25% = 9px. All rem-based sizes scale down proportionally.
Tablet Portrait
At 900px and below, font size reduces to 50% = 8px. Further scaling for smaller screens.
Component Responsive Design
Here’s how components implement responsive behavior:Card Component
sass/components/_card.scss
The card component relies on root font-size changes for responsive behavior rather than explicit breakpoints. Since all dimensions use
rem units (e.g., 50rem), they automatically scale when the root font-size changes.Button Component
sass/components/_button.scss
Grid System Responsiveness
The grid system uses the clearfix mixin and adapts through rem-based spacing:sass/components/layout/_grid.scss
Desktop-First Approach
How It Works
Write Desktop Styles First
Default styles target desktop screens (1200px - 1800px). These are written outside any media queries.
Override for Smaller Screens
Use
max-width media queries to override styles for progressively smaller screens.Desktop-First vs Mobile-First
- Desktop-First (Natours)
- Mobile-First (Alternative)
Advantages:
- Natural for desktop-focused designs
- Easier to progressively simplify for mobile
- Works well with legacy browser support
Responsive Typography
Typography scales automatically through the root font-size system:sass/base/_typography.scss
Automatic Scaling
All rem-based typography scales automatically without explicit breakpoints. Change the root font-size, and everything adjusts.
Proportional Spacing
Margins, padding, and letter-spacing all use rem units, maintaining proportional relationships across breakpoints.
Advanced Patterns
Using Multiple Breakpoints
Conditional Mixin Usage
The
absCenter mixin is used throughout the codebase for perfect centering. It’s responsive by nature since it uses transforms rather than fixed positioning.Testing Responsiveness
Browser DevTools
Use Chrome/Firefox DevTools responsive design mode to test breakpoints:
- Desktop: 1440px
- Tablet Landscape: 1024px
- Tablet Portrait: 768px
- Phone: 375px
Physical Devices
Test on actual devices when possible:
- iPhone SE (small phone)
- iPad (tablet)
- Desktop monitor (1920px+)
Best Practices
Use rem Units
Always use
rem for sizes, spacing, and typography. Avoid px except for borders (1px, 2px).Test Edge Cases
Test at exact breakpoint values (600px, 900px, 1200px, 1800px) to ensure smooth transitions.
Consolidate Media Queries
Keep all responsive rules for a component in the same file, nested within the component.
Semantic Breakpoints
Use semantic names (
phone, tab-port) rather than size names (small, medium).Next Steps
Architecture
Understand the overall project structure
Sass Structure
Learn about file organization and modules