Media Query
A CSS rule applying styles based on device features.
See it on the 3D treeGoing deeper
Written with the @media rule, it wraps styles that apply only when a condition is true. Conditions include viewport width, orientation, pointer precision, hover ability, print output and user preferences such as reduced motion or colour scheme. Container queries are related but respond to an element's container instead.
Why it matters
You can specify how a design should respond to circumstances beyond width, including how people interact and what they prefer.
In practice
You ask for large transitions to be removed when someone has set their system to reduce motion.
Common mistake
Assuming a narrow screen means touch and a wide one means mouse, instead of querying pointer features or designing for both.
Connected terms
- BreakpointA breakpoint is commonly written as the width condition in a query.
- CSSMedia queries are part of the CSS language.
- Mobile FirstMin-width queries add layout rules as space increases.
- Responsive DesignMedia queries are one of the main tools that make layouts adapt.
- ViewportQueries test viewport features to decide which styles apply.
- Reduced MotionA preference that pages can detect with a media query.