The width media feature targets the viewport’s horizontal size. Build responsive layouts for phones, tablets, and desktops with min-width and max-width queries.
01
@media
Media query.
02
min-width
Wide screens.
03
max-width
Narrow screens.
04
Viewport
Window width.
05
vs height
Horizontal axis.
06
vs property
Query vs size.
Fundamentals
Introduction
Responsive web design starts with width. The width media feature lets you apply CSS when the browser window is wide or narrow — the foundation of mobile-first layouts, breakpoint systems, and adaptive grids.
A phone in portrait mode has a narrow viewport; a desktop monitor has a wide one. By querying viewport width with min-width and max-width, you control when columns stack, when navigation collapses, and when typography scales up.
Definition and Usage
Write @media (min-width: 600px) or @media (max-width: 768px) to apply styles when the viewport meets your width condition. Values use length units such as px, em, rem, or viewport units like vw.
💡
Beginner Tip
Do not confuse this with the CSS width property, which sizes an element. The media feature checks the browser window width, not an individual box.
Foundation
📝 Syntax
Use min-width, max-width, or an exact width inside @media:
syntax.css
/* Viewport is at least 600px wide */@media(min-width:600px){/* Styles for wide viewports */}/* Viewport is at most 768px wide */@media(max-width:768px){/* Styles for narrow viewports */}/* Exact viewport width (rare) */@media(width:1024px){/* Matches only at exactly 1024px width */}
Feature Variants
min-width — Matches when viewport width is greater than or equal to the value (wide screens).
max-width — Matches when viewport width is less than or equal to the value (narrow screens).
width — Matches an exact viewport width; rarely used because few users hit one precise pixel width.
width Media Feature vs width Property
@media (min-width: 600px) Viewport query — “Is the browser window at least 600px wide?”
width: 600px; Element sizing — sets one box to exactly 600 pixels wide.
width vs height Media Features
@media (min-width: 48rem) Horizontal axis — phones vs tablets vs desktops by window width.
@media (min-height: 32rem) Vertical axis — short split windows vs tall full-screen viewports.
UI adapts when users resize horizontally or switch devices.
Compatibility
🖥 Browser Compatibility
The width, min-width, and max-width media features are supported in all modern browsers with 100% global support.
✓ Baseline · Universal support
Viewport width queries
Works in Chrome, Firefox, Safari, Edge, and Opera.
100%Global support
width media features100% supported
Bottom line: Width media queries are the backbone of responsive CSS and are safe for production in every browser.
Wrap Up
🎉 Conclusion
The width media feature lets you respond to viewport width with min-width, max-width, and exact width queries. It is the most essential tool for building responsive websites.
Use it for mobile layouts, desktop upgrades, typography scaling, and tablet-only ranges. Always distinguish viewport width queries from the CSS width property on elements.
Use these points when writing width-based responsive CSS.
5
Core concepts
→01
min-width
Wide screens.
Query
←02
max-width
Narrow screens.
Query
VP03
Viewport
Window width.
Target
+H04
and height
Both axes.
Combine
🌐05
100% support
Universal.
Compat
❓ Frequently Asked Questions
The width media feature matches styles based on the viewport width — the visible horizontal size of the browser window. Use min-width, max-width, or an exact width value inside @media rules to adapt layouts for phones, tablets, and desktops.
min-width applies styles when the viewport is at least the given width (larger screens). max-width applies styles when the viewport is at most the given width (smaller screens). Combine both to target specific width ranges like tablet-only layouts.
The media feature queries the viewport width for conditional rules. The width property sets the width of an individual element. @media (min-width: 600px) checks the window; width: 600px sizes one box.
Use them for responsive layouts — stacking columns on phones, multi-column grids on tablets, wider typography on desktops, and any design that changes based on how wide the browser window is.
Yes. min-width, max-width, and width media features are supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera with 100% global support.