Bird
Raised Fist0
CSSmarkup~20 mins

Mobile-first approach in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Mobile-first Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use a mobile-first approach in CSS?
Which of the following best explains the main reason developers use a mobile-first approach when writing CSS?
AIt uses JavaScript to detect screen size and load styles dynamically.
BIt ensures styles for small screens load first, improving performance on mobile devices.
CIt applies desktop styles first, then overrides them for mobile devices.
DIt disables styles on mobile devices to save bandwidth.
Attempts:
2 left
💡 Hint
Think about which devices usually have slower connections and smaller screens.
📝 Syntax
intermediate
2:00remaining
Identify the correct mobile-first media query
Which CSS media query correctly follows the mobile-first approach to apply styles for screens wider than 600px?
A@media (max-width: 600px) { body { background: blue; } }
B@media screen and (min-device-width: 600px) { body { background: blue; } }
C@media (min-width: 600px) { body { background: blue; } }
D@media screen and (max-device-width: 600px) { body { background: blue; } }
Attempts:
2 left
💡 Hint
Mobile-first uses min-width to add styles for bigger screens.
rendering
advanced
2:00remaining
What background color will the page show on a 500px wide screen?
Given this CSS, what background color will the page have when viewed on a screen 500px wide?
CSS
body {
  background-color: white;
}

@media (min-width: 600px) {
  body {
    background-color: green;
  }
}

@media (min-width: 400px) {
  body {
    background-color: yellow;
  }
}
AYellow
BWhite
CGreen
DNo background color
Attempts:
2 left
💡 Hint
Check which media queries apply at 500px width.
selector
advanced
2:00remaining
Which CSS selector targets only mobile devices in a mobile-first approach?
You want to style a nav element only on screens smaller than 480px. Which CSS snippet correctly does this using a mobile-first approach?
Anav { font-size: 1.2rem; } @media (min-width: 480px) { nav { font-size: 1rem; } }
B@media (min-width: 480px) { nav { font-size: 1.2rem; } }
C@media (max-width: 479px) { nav { font-size: 1.2rem; } }
Dnav { font-size: 1rem; } @media (max-width: 479px) { nav { font-size: 1.2rem; } }
Attempts:
2 left
💡 Hint
Mobile-first means base styles for small screens, then bigger screen overrides.
accessibility
expert
3:00remaining
How does mobile-first CSS improve accessibility?
Which statement best explains how a mobile-first CSS approach can help users with disabilities?
AIt hides content on mobile devices to reduce cognitive load.
BIt disables animations on mobile devices to reduce distractions.
CIt automatically adds ARIA labels to all elements for screen readers.
DIt ensures simpler layouts and larger touch targets on small screens, aiding users with motor impairments.
Attempts:
2 left
💡 Hint
Think about how mobile design affects ease of use for everyone.

Practice

(1/5)
1. What does the mobile-first approach in CSS mean?
easy
A. Write all styles without using media queries
B. Start styling for small screens first, then add styles for larger screens
C. Start styling for desktop screens first, then add styles for smaller screens
D. Only style for mobile devices and ignore desktops

Solution

  1. Step 1: Understand mobile-first approach

    Mobile-first means you write CSS targeting small screens first, like phones.
  2. Step 2: Add styles for bigger screens

    Then you use media queries with min-width to add or change styles for tablets and desktops.
  3. Final Answer:

    Start styling for small screens first, then add styles for larger screens -> Option B
  4. Quick Check:

    Mobile-first = Start small, add bigger [OK]
Hint: Think: style phones first, then bigger screens [OK]
Common Mistakes:
  • Confusing mobile-first with desktop-first
  • Using max-width instead of min-width for bigger screens
  • Ignoring media queries completely
2. Which CSS syntax correctly applies styles for screens wider than 600px in a mobile-first approach?
easy
A. @media (max-width: 600px) { ... }
B. @media (width: 600px) { ... }
C. @media screen and (min-width: 600px) { ... }
D. @media screen and (max-width: 600px) { ... }

Solution

  1. Step 1: Identify mobile-first media query

    Mobile-first uses min-width to add styles for bigger screens.
  2. Step 2: Choose correct syntax with media type

    Using @media screen and (min-width: 600px) targets screens wider than 600px correctly.
  3. Final Answer:

    @media screen and (min-width: 600px) { ... } -> Option C
  4. Quick Check:

    Mobile-first uses min-width with media type [OK]
Hint: Use min-width for bigger screens in mobile-first [OK]
Common Mistakes:
  • Using max-width instead of min-width for bigger screens
  • Using 'width' instead of 'min-width'
  • Confusing min-width and max-width
3. Given this CSS, what background color will a 700px wide screen see?
body { background: white; }
@media (min-width: 600px) { body { background: blue; } }
@media (min-width: 800px) { body { background: green; } }
medium
A. Blue
B. White
C. Green
D. No background color

Solution

  1. Step 1: Check base style

    Base background is white for all screen sizes.
  2. Step 2: Check media queries for 700px width

    700px is >= 600px but < 800px, so blue applies, green does not.
  3. Final Answer:

    Blue -> Option A
  4. Quick Check:

    700px triggers min-width 600px but not 800px [OK]
Hint: Check which min-width media query matches screen size [OK]
Common Mistakes:
  • Choosing green because 700 > 600 but ignoring 800px limit
  • Choosing white ignoring media queries
  • Confusing min-width with max-width
4. What is wrong with this mobile-first CSS snippet?
body { font-size: 14px; }
@media (max-width: 600px) { body { font-size: 16px; } }
medium
A. It uses max-width instead of min-width for bigger screens
B. No error, this is correct mobile-first CSS
C. The base font size should be larger than media query size
D. Media query should use min-width for mobile-first approach

Solution

  1. Step 1: Identify media query type

    The snippet uses max-width: 600px, which targets small screens.
  2. Step 2: Check mobile-first rule

    Mobile-first uses base styles for small screens and min-width for bigger screens, so this is reversed.
  3. Final Answer:

    Media query should use min-width for mobile-first approach -> Option D
  4. Quick Check:

    Mobile-first uses min-width, not max-width [OK]
Hint: Mobile-first uses min-width, max-width is desktop-first [OK]
Common Mistakes:
  • Thinking max-width is correct for mobile-first
  • Ignoring base styles importance
  • Assuming no error in reversed media query
5. You want a button to have 100% width on phones and 200px width on screens wider than 768px. Which CSS correctly uses mobile-first approach?
hard
A. button { width: 100%; } @media (min-width: 768px) { button { width: 200px; } }
B. button { width: 200px; } @media (max-width: 768px) { button { width: 100%; } }
C. button { width: 100%; } @media (max-width: 768px) { button { width: 200px; } }
D. button { width: 200px; } @media (min-width: 768px) { button { width: 100%; } }

Solution

  1. Step 1: Set base style for small screens

    Mobile-first means base style is for phones, so width 100% is base.
  2. Step 2: Use min-width media query for bigger screens

    Use @media (min-width: 768px) to set width 200px for larger screens.
  3. Final Answer:

    button { width: 100%; } @media (min-width: 768px) { button { width: 200px; } } -> Option A
  4. Quick Check:

    Base small, min-width bigger = mobile-first [OK]
Hint: Base styles for mobile, min-width for bigger screens [OK]
Common Mistakes:
  • Using max-width for bigger screens
  • Setting desktop styles as base
  • Reversing widths in media queries