The width media feature tests the viewport width (or the page box for paged media). It is a range feature, so you also get min-width and max-width variants.
Use it for responsive layouts—stack on small screens, expand on large ones. It is not the same as the width property, which sizes one element.
Deprecateddevice-width
Do not use device-width / min-device-width / max-device-width. Query the viewport with width instead.
Note Prefer em / rem for breakpoints
Length features work with px, but em or rem often keep breakpoints in sync when users enlarge text.
Start mobile-first with base styles, then layer larger breakpoints with min-width.
Write a single-column layout that works on a small screen.
Add @media (min-width: …) to enhance for tablets and desktops.
Use max-width when a tweak should apply only below a size.
Prefer a few clear breakpoints over many tiny ones.
Piece
Required?
Role
@media
Yes
Wraps the query
Length value
Yes
Breakpoint size (px, em, rem, …)
min- / max-
Usual
Range matching instead of exact width
Base styles
Yes
Look correct before any query matches
Try it
Live Preview
Resize this window. The sample uses real @media (max-width: 600px) and (min-width: 601px) rules. The note shows the current viewport width from JavaScript.
Viewport width
Coral under 601px. Blue at 601px and up.
Width breakpoints
Resize to switch styles
max-width: 600pxmin-width: 601px
Checking…
Code
CSS Examples
Each snippet focuses on the width media feature. Use Try It Yourself for a live editor—resize the preview pane.
Example 1 — Mobile-First min-width
Start simple, then enhance when the viewport is wide enough.
CSS
p {
background: #fecaca;
}
@media (min-width: 35rem) {
p {
background: #dbeafe;
}
}
Keep a default. Gray applies outside the target band.
Join with and. Both min and max must match.
Hit the middle. Green appears from 400px through 700px.
Optional modern form.@media (400px <= width <= 700px) means the same where supported.
Edge Cases & Pitfalls
Viewport queries are easy to confuse with element sizing.
vs property
Media feature ≠ width property
@media (min-width: 600px) checks the window. width: 600px sizes a box.
exact
Exact width: is brittle
@media (width: 360px) only matches that exact size. Prefer min- / max- ranges.
device
Skip deprecated device queries
device-width reflects hardware, not layout. Use viewport width.
scrollbar
Scrollbar can affect the value
The viewport width measurement can include scrollbar space. Avoid razor-thin exact breakpoints.
a11y
Test with larger text
If you use px breakpoints, zoom text and check layout. em/rem often fare better.
Compatibility
Browser Support
width is a browser media feature. Node.js, Deno, and Bun do not evaluate it.
✓ Baseline · Widely available
width
min-width, max-width, and width media features have been interoperable across browsers for years (Baseline since about July 2015). Foundational for responsive CSS.