MEDIA QUERIES /// RESPONSIVE DESIGN /// BREAKPOINTS /// MOBILE FIRST /// MEDIA QUERIES /// RESPONSIVE DESIGN /// BREAKPOINTS /// MOBILE FIRST ///

Media Queries

Adapt your layout to any screen size. Master mobile-first architecture, breakpoints, and responsive principles.

responsive.css
1 / 9
12345
📐

Tutor:The web is viewed on everything from smartwatches to ultra-wide monitors. CSS Media Queries adapt your layout to fit the screen.

Skill Matrix

UNLOCK NODES BY MASTERING RESPONSIVE DESIGN.

Mobile First Basics

Always write CSS for the smallest screens first. Then use media queries to enhance the layout.

System Check

Which media query targets screens that are 1024px or wider?


Community Holo-Net

Showcase Your Layouts

ACTIVE

Built an incredibly fluid responsive grid? Share your solutions and get feedback!

CSS Media Queries: Responsive Web

Frontend Instructor in Code Syllabus

Pascual Vila

Frontend Instructor // Code Syllabus

The web isn't just viewed on 1080p desktop monitors anymore. Your users are on phones, tablets, smart TVs, and everything in between. Media Queries are the magic that makes your website fluid, adaptable, and beautiful on every screen size.

The Viewport Meta Tag

Before you even write a single media query, you must tell mobile browsers not to pretend to be a desktop. Add this inside your HTML <head>:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Without it, a mobile phone will render your site at ~980px width and zoom out, making your text unreadable and rendering your media queries useless.

Anatomy of a Media Query

A media query consists of an optional media type (like screen or print) and any number of media feature expressions (like min-width).

@media screen and (min-width: 768px) { /* CSS rules apply when screen is 768px or wider */ .container { display: flex; } }

The "Mobile-First" Philosophy

Instead of styling for desktop and using max-width to squish things down for mobile, industry best practice is Mobile-First.

  • Write your base styles for the smallest screens outside of any media queries.
  • Use min-width media queries to add layout complexity as the screen gets wider.
  • This results in less code overriding, faster rendering on weak mobile devices, and fewer bugs.

Frequently Asked Questions

¿Cuál es la diferencia entre min-width y max-width?

min-width: "A partir de este ancho hacia arriba". Si usas (min-width: 768px), el código se aplica en pantallas de 768px, 1024px, 1920px... (Desktop-first).

max-width: "Desde este ancho hacia abajo". Si usas (max-width: 767px), el código se aplica en pantallas de 767px, 320px... (Diseño para móviles cuando usas enfoque desktop-first).

¿Cuáles son los breakpoints más comunes?

Aunque la filosofía ideal es poner breakpoints donde el diseño se rompe, los estándares habituales de la industria (como Tailwind) son:

  • 640px: Móviles grandes / Tablets pequeñas (sm)
  • 768px: Tablets en vertical (md)
  • 1024px: Tablets en horizontal / Portátiles (lg)
  • 1280px: Escritorio normal (xl)
¿Puedo combinar múltiples condiciones?

¡Sí! Usa la palabra clave and para requerir múltiples condiciones, o una coma , (que actúa como un OR).

@media screen and (min-width: 768px) and (max-width: 1024px) { /* Aplica solo a tablets específicas */ }

Responsive Glossary

@media
The CSS rule used to apply styles based on the result of one or more media queries.
snippet.css
min-width
Media feature checking if the viewport is equal to or WIDER than the specified width. Core to mobile-first.
snippet.css
max-width
Media feature checking if the viewport is equal to or NARROWER than the specified width.
snippet.css
orientation
Checks if the device is held in 'portrait' (taller) or 'landscape' (wider) mode.
snippet.css
viewport
The user's visible area of a web page. Always include the meta tag for proper rendering on mobile.
snippet.css
breakpoint
The specific pixel value at which your layout needs to change (or 'break') to adapt to the new space.
snippet.css