DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • The Box Model
  • Specificity & The Cascade
  • CSS Units Deep Dive
  • Stacking Contexts & Z-Index
  • Flexbox Mastery
  • CSS Grid Mastery
  • Centering, Subgrid & Container Queries
  • CSS Custom Properties & Variables
  • Selectors: :has(), Pseudo-classes & Pseudo-elements
  • Responsive Functions: calc(), clamp(), min(), max()
  • Media Queries & Mobile-First Design
  • Transitions & Animations
  • Transforms, Filters & Clipping
  • CSS Methodologies: BEM, CSS-in-JS & Tailwind
  • Typography, Color Spaces & Dark Mode
  • CSS Performance & Optimization
  • CSS Interview Questions — Part 1
  • CSS Interview Questions — Part 2
← From Beginner to Expert in Fundamentals of Frontend

Media Queries & Mobile-First Design

16 min read
Media QueriesMobile-FirstBreakpointsLogical PropertiesRTLaspect-ratioobject-fitRange Syntax

Responsive Design Foundations

Mobile-First vs Desktop-First

ApproachBase Styles ForMedia QueriesPerformance
Mobile-First ✅Small screensmin-width (add complexity)Better — mobile loads less CSS
Desktop-First ❌Large screensmax-width (override complexity)Worse — mobile downloads desktop CSS

Modern Media Query Syntax

CSS now supports range syntax (Level 4) which is more readable:

/* Old syntax */
@media (min-width: 768px) and (max-width: 1023px) { }

/* New range syntax ✅ */
@media (768px <= width < 1024px) { }
@media (width >= 1024px) { }

Common Breakpoints

DeviceBreakpointTailwind Class
Small mobile< 640px(default)
Large mobile≥ 640pxsm:
Tablet≥ 768pxmd:
Laptop≥ 1024pxlg:
Desktop≥ 1280pxxl:
Large Desktop≥ 1536px2xl:

Logical Properties for RTL/LTR

Logical properties work correctly in both left-to-right (English) and right-to-left (Arabic, Hebrew) layouts:

Physical (Old) ❌Logical (New) ✅
margin-leftmargin-inline-start
margin-rightmargin-inline-end
padding-toppadding-block-start
widthinline-size
heightblock-size
text-align: lefttext-align: start

Aspect Ratio

The aspect-ratio property prevents layout shift by reserving the correct space before content loads:

img { aspect-ratio: 16 / 9; width: 100%; object-fit: cover; }

object-fit & object-position

ValueBehavior
coverFills container, crops excess (most common)
containFits inside container, may leave gaps
fillStretches to fill (may distort)
noneOriginal size, may overflow
scale-downLike contain, but never scales UP

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.