Topics Covered in This Mobile & Responsive Web Design Tutorial:
Mobile First Thinking, Fluid Widths, Min-width Vs. Max-width Media Queries
Exercise Preview

How you order media queries affects whether CSS rules work as expected and determines how much CSS you'll need to write.
Exercise Overview
The order of your media queries isn't just a stylistic choice—it fundamentally affects how your CSS rules cascade and determines how much code you'll need to write. With mobile traffic now dominating web usage in 2026, understanding the strategic differences between mobile-first and desktop-first approaches has become essential for modern web development. Using a mobile-first approach, we place mobile device rules at the foundation, progressively enhancing for larger screens below. The desktop-first approach inverts this hierarchy, starting with desktop styles and overriding them for smaller viewports. In this comprehensive exercise, you'll implement both methodologies and discover why most professional teams have standardized on mobile-first development.
Using the Desktop First Approach
- On the Desktop, navigate to Class Files > yourname-Mobile and Responsive Class and open the Media Queries—Desktop First folder.
- Open index.html in your code editor.
- Take a moment to examine the code structure. This is a clean wireframe featuring the fundamental layout components: header, main, aside, and footer—the building blocks of most web layouts.
- Preview index.html in a browser. Resize the browser window and observe how all elements maintain fixed widths, forcing horizontal scrolling on smaller screens—exactly the user experience we want to eliminate.
- In your code editor, open main.css (located in the Media Queries—Desktop First folder). We'll begin our transformation by implementing fluid widths across all major layout components.
Desktop First Implementation Steps
Start with Fixed Desktop Layout
Begin with desktop-optimized styles and fixed widths that require scrolling on small screens
Convert to Fluid Widths
Replace fixed pixel widths with percentage-based flexible layouts
Add Tablet Breakpoint
Use max-width media queries to modify layout for medium screens
Add Mobile Breakpoint
Create additional max-width queries for smallest screen sizes
Coding Fluid Widths
Our first step involves liberating the layout from fixed constraints. Let's start by removing the restrictive width property from the body rule, allowing our content to breathe and adapt.
Edit the body rule by deleting the width property entirely. Your updated code should match the following:
body { background:,000; margin: 20px auto; }Now we'll transform all fixed widths on the header, main, and aside elements into flexible percentage widths. Edit the header rule as highlighted below:
header { background: #c1424d; float: left; width: 20%; }Edit the main rule to allocate the majority of horizontal space to our primary content:
main { background: #c5a87f; float: left; width: 60%; }Edit the aside rule to complete our three-column fluid layout:
aside { background: #9a886f; float: right; width: 20%; }- Save the file and prepare to see the immediate transformation.
Preview index.html in a browser. Resize the window dynamically to observe how our content now flexes responsively. This represents significant progress, but you'll notice that extremely narrow viewports still create an uncomfortably cramped user experience—our next challenge to solve.
Layout Width Distribution
Adding Tablet Styles
With our flexible foundation in place, it's time to introduce media queries that intelligently restructure our layout for intermediate screen sizes. This is where responsive design truly demonstrates its power.
- Return to main.css in your editor.
After the footer rule, add this media query targeting tablet-sized devices:
@media (max-width: 1024px) { }NOTE: This breakpoint captures devices up to 1024px wide, including iPads in landscape orientation and smaller desktop windows—covering a significant portion of your audience.
For development visibility, let's add a visual indicator when these tablet styles are active. Insert the following code within the media query:
@media (max-width: 1024px) { body { background: gray; } }- Save the file to test your progress.
- Preview index.html in a desktop browser. Gradually narrow the window and watch for the background color change to gray—this confirms your media query is functioning correctly.
- Switch back to main.css to continue our layout optimization.
For tablet users, a horizontal navigation header typically provides better usability than a narrow sidebar. Add this rule within your media query:
@media (max-width: 1024px) { body { background: gray; } header { float: none; width: auto; } }- Save your changes to see the layout transformation.
Preview index.html in a browser and test the responsive behavior.
Excellent progress! The header now spans the full width at tablet sizes, creating a more natural reading flow. However, you'll notice the main content and aside retain their percentage widths, creating an awkward gap. Let's refine this layout further.
Back in main.css, add this rule after the header rule within the media query to optimize the sidebar width:
aside { width: 40%; }- Save the file to implement this improvement.
Preview index.html in a browser. Perfect! Our tablet layout now provides an optimal balance between content and supplementary information.
The 1024px breakpoint targets iPad landscape orientation and similar tablet devices for optimal viewing experience.
Tablet Layout Adjustments
Header Modification
Remove float and set width to auto so header spans full width across top of page.
Content Rebalancing
Adjust aside width to 40% to eliminate gaps while maintaining two-column main content layout.
Adding Mobile Styles
Now we'll complete our responsive system by addressing mobile devices—the most critical viewport in 2026. In main.css, add this media query after the existing max-width: 1024px rule:
@media (max-width: 600px) { }NOTE: This breakpoint targets smartphones and very small tablets, ensuring your content remains accessible on the smallest screens.
Add a distinct visual indicator for mobile breakpoint activation:
@media (max-width: 600px) { body { background: #fff; } }- Save the file and test the breakpoint behavior.
- Preview index.html in a browser. Notice how the background transitions to white as you narrow the window further—each breakpoint is now clearly differentiated.
- On mobile devices, horizontal scrolling should be completely eliminated. Return to main.css to implement single-column stacking.
After the body rule in the max-width: 600px media query, add this crucial mobile optimization:
@media (max-width: 600px) { body { background: #fff; } main, aside { float: none; width: auto; } }Save the file and preview index.html in a browser. Resize comprehensively to observe your wireframe's complete responsive transformation across all device categories.
Mobile Optimization Checklist
Targets typical mobile device widths
Allows natural stacking for narrow screens
Enables full-width content utilization
Verify responsive behavior at all breakpoints
Using the Mobile First Approach
You've successfully implemented desktop-first responsive design by layering media queries to progressively modify desktop styles for smaller screens. Now let's explore the mobile-first methodology—the approach that has become the industry standard for modern web development. This philosophy prioritizes the most constrained environment first, then progressively enhances the experience as screen real estate and processing power increase.
Mobile-first thinking delivers multiple strategic advantages that extend beyond technical implementation. It forces you to ruthlessly prioritize content hierarchy, ensuring that only the most essential elements compete for attention on small screens. From a performance perspective, mobile-first typically results in leaner codebases since you're building up rather than overriding existing styles. Instead of defining desktop floats only to remove them on mobile (requiring multiple declarations), mobile-first leverages HTML's natural document flow and strategically adds layout complexity only when beneficial. This approach aligns perfectly with the progressive enhancement philosophy that drives modern web architecture.
- Close any open files in your code editor and browser to start fresh.
- On the Desktop, navigate to Class Files > yourname-Mobile and Responsive Class and open the Media Queries—Mobile First folder.
- Open index.html in your code editor. You'll recognize this as identical HTML structure from our desktop-first exercise—demonstrating how the same content can be approached with completely different CSS strategies.
- Preview index.html in a browser to see the starting point.
- Notice that the elements display with minimal styling beyond background colors. Resize your browser window to observe how HTML's default behavior—flexible widths and natural stacking—already provides an excellent mobile foundation without any additional CSS effort.
Mobile First Benefits and Considerations
Min-Width Media Queries
- In your code editor, open main.css from the Media Queries—Mobile First folder.
- Observe how this CSS file contains significantly less code than our desktop-first approach. This efficiency stems from leveraging HTML's inherent responsive characteristics rather than fighting against them.
With our mobile design complete by default, we'll now enhance the experience for larger screens. After the footer rule, add this progressive enhancement:
@media (min-width: 600px) { }NOTE: This min-width query applies styles only to devices 600px or wider, building upward from our mobile foundation.
Add a visual indicator to clearly identify when tablet enhancements are active:
body { background: gray; }Inside the media query, after the body rule, implement our two-column tablet layout by floating the main content:
main { float: left; width: 60%; }Complete the tablet layout by positioning the aside element as a complementary sidebar:
aside { float: right; width: 40%; }- Save your changes and test the responsive behavior.
- Preview index.html in a browser. Resize to trigger the gray background and observe the two-column layout. While the main and aside elements are positioning correctly, there's a subtle but important issue: the floating elements cause the footer to slip underneath them. In most browsers this is invisible, but certain webkit versions and browser developer tools will reveal this layout problem—a gap between columns where the footer's background color bleeds through.
- Switch back to main.css to resolve this floating context issue.
Inside the media query, after the aside rule, add this essential layout fix:
footer { clear: both; }- Save the file and verify the correction.
- Preview index.html and resize to confirm that both mobile and tablet layouts now render flawlessly.
Finally, we'll add desktop enhancements for the largest screens. In main.css, after the min-width: 600px media query, add this final breakpoint:
@media (min-width: 1024px) { }Inside this media query, add the desktop background indicator:
body { background:,000; }For desktop users with ample horizontal space, we can afford to display the header as a sidebar navigation. Add this enhancement after the body rule:
header { float: left; width: 20%; }With the header now occupying horizontal space, adjust the aside width to maintain perfect proportions in our three-column desktop layout:
aside { width: 20%; }- Save the file to complete your mobile-first implementation.
- Preview index.html in a browser. Comprehensively test by resizing across all breakpoints to experience the seamless progression from mobile single-column to tablet two-column to desktop three-column layouts.
Save and close your files—you've successfully mastered both responsive design methodologies.
While both approaches achieve identical visual results, the mobile-first strategy has become the overwhelming preference among professional development teams. Beyond generating leaner code, mobile-first aligns with user behavior patterns in 2026, where mobile traffic consistently dominates across most industries. By designing for the most constrained environment first, you ensure that your most important content and functionality receives priority, creating better user experiences across all devices.
Min-Width vs Max-Width Media Queries
| Feature | Min-Width (Mobile First) | Max-Width (Desktop First) |
|---|---|---|
| Query Logic | 600px and wider | 600px and narrower |
| CSS Cascade | Additive styles | Override styles |
| Default State | Mobile layout | Desktop layout |
| Code Efficiency | Less redundant code | More override rules |
Mobile First Breakpoint Progression
Base Mobile Styles
Default HTML stacking, no floats, flexible widths
Tablet Enhancement
Add floats: main 60% left, aside 40% right, clear footer
Desktop Expansion
Header floats left 20%, aside reduces to 20% width