OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 37

Media Queries and Breakpoints

By Ratan Updated: 15 Oct 2026

Adapt layouts for mobile, tablet, and desktop screens using CSS @media queries.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Change layout when the content needs it

A media query conditionally applies styles according to features such as viewport width, motion preference or print output. Breakpoints should respond to actual layout pressure rather than pretending every phone or laptop has one fixed size.

.layout { display: grid; gap: 1rem; }
@media (min-width: 48rem) {
  .layout { grid-template-columns: 14rem minmax(0, 1fr); }
}
@media print {
  .site-navigation, .print-button { display: none; }
  .tech-lesson-content { color: black; background: white; }
}

The base layout is one column. At sufficient width it becomes sidebar plus content. The print rule hides navigation controls, not the article's main information.

Viewport setup

Responsive pages normally include in the head. Do not disable user zoom. Width queries refer to the viewport, not a particular card's allocated width; container queries address a different use case.

Queries do not add selector specificity

A matching media query makes its contained rules eligible. It does not automatically make a weak selector stronger than every rule outside it. Cascade order and specificity still matter. Keep base rules and progressive overrides easy to trace.

Test around the boundary

If the breakpoint is 48rem, test just below, at and above it, plus intermediate widths and 200% zoom. A design that works only at a few preset screenshots is not reliably responsive. Long translations and large text can reveal problems before the nominal device width does.

Practice

  1. Start with one column and add a second only when both regions remain usable.
  2. Inspect print preview and confirm important instructions remain.
  3. Remove a fixed-width child that causes overflow rather than hiding horizontal scrolling globally.
  4. Use prefers-reduced-motion as a feature query and compare it with a width breakpoint.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat