A media query is a CSS rule that applies styles only when the device meets set conditions like screen width.
A media query is a rule in CSS, the language that controls how web pages look, that applies styling only when a device meets certain conditions. The most common condition is screen width, which lets a page present one layout on a wide desktop monitor and a different, better-suited layout on a narrow phone. Media queries are the mechanism that makes a single website adapt gracefully across the huge range of devices people use, from small handsets to large displays, without needing separate versions of the site for each.
The way a media query works is a conditional test attached to a block of style rules. A designer writes a query that says, in effect, "when the screen is at or below a certain width, apply these styles." If the condition is true for the visitor's device, the enclosed rules take effect; if not, they are ignored. Beyond width, media queries can respond to other characteristics such as screen height, orientation whether the device is held upright or sideways, resolution, and even user preferences like a taste for dark color schemes or reduced motion. By stacking several queries at different width thresholds, known as breakpoints, a designer can adjust the layout progressively, rearranging columns, resizing text, hiding or showing elements, and reflowing content so the page remains usable and attractive at every size.
Media queries were formalized as part of the CSS3 standard around 2012, arriving at the moment the industry needed them most. The rapid spread of smartphones and tablets had created a web accessed on wildly varying screen sizes, and the old approach of designing for a single fixed width was breaking down. The name combines "media," from the Latin sense of a means or channel, with "query," meaning a request or question. A media query is literally a question the stylesheet asks about the medium on which the page is being displayed, and the answer determines which styles apply. This capability became the technical foundation of responsive design.
For a business, media queries are essential because visitors now arrive from every kind of device, and a large share of web traffic comes from phones. A site that does not adapt forces mobile users to pinch, zoom, and scroll sideways to read content or tap tiny buttons, which drives them away. Search engines also evaluate how well a site works on mobile devices and favor those that do, so a responsive layout built with media queries supports both usability and visibility. Rather than maintaining a separate mobile site, a business can serve one adaptable site that meets everyone well, which is simpler to maintain and more consistent for the brand.
Common mistakes include choosing breakpoints based on the dimensions of specific popular devices rather than on where the content itself starts to look awkward, which leaves the design fragile as new devices appear. Designers sometimes hide important content on smaller screens instead of reflowing it, denying mobile users information that desktop users get. Another error is building for large screens first and squeezing down, which often produces cramped mobile experiences, whereas designing for small screens first tends to yield cleaner results. Media queries relate closely to responsive design, which they enable, to CSS more broadly, to the mobile-first approach that prioritizes small screens, and to breakpoints, the specific thresholds at which layouts change. Used thoughtfully, media queries let one site serve everyone well.
Media queries let one codebase serve every screen size well. That adaptability is now a baseline expectation for both users and search rankings.