Media queries let your CSS react to the device and viewport—width, orientation, print mode, hover ability, and more. You write them with the @media rule so styles apply only when a condition is true.
@media vs media query
The @media rule is the CSS at-rule that wraps a block of styles. The media query is the condition after @media (for example (max-width: 600px)). When the query matches, those styles apply; when it does not, the browser ignores that block.
What should beginners learn first?
Start with width (min-width / max-width) for responsive layouts, then print for paper styles, orientation for portrait vs landscape, and hover for mouse vs touch. Those cover most CSS tutorial needs.
Hub vs single-feature pages
This page teaches how media queries work in a CSS tutorial. Each name in the index links to a focused feature guide (for example CSS width Media Feature). For the properties you change inside a query, see CSS Properties; for targeting elements, see CSS Selectors.
Viewport meta required.
Include <meta name="viewport" content="width=device-width, initial-scale=1"> in HTML. Without it, mobile browsers may not report the real width and your queries will misfire.
Base styles first.
Write default CSS outside @media, then override inside queries. Do not put every style inside a media block.
Prefer mobile-first.
Base styles for small screens, then min-width to enhance larger viewports—usually cleaner than stacking many max-width overrides.
Syntax
CSS Syntax
An @media rule takes an optional media type plus one or more features:
One line: Media queries adapt CSS to viewport and device—set the viewport meta, style mobile first, then open feature guides from the index.
Frequently Asked Questions
The @media rule wraps CSS that applies only when a media query matches—for example a max viewport width, print mode, or hover capability. It is the foundation of responsive CSS in this tutorial.
A media query is the condition after @media, such as (max-width: 600px) or (orientation: landscape). It can include an optional media type (screen, print) plus features combined with and, or, or not.
Mobile-first means you write base styles for small screens, then use min-width queries to add layout for larger viewports. Example: one column by default, then @media (min-width: 768px) for two columns.
screen targets displays (phones, monitors). print targets paper or print preview. Use @media print to hide navigation, simplify colors, and tune typography for printing.
Start with width (min-width / max-width), then print, orientation, and hover. Those cover responsive layouts, print styles, rotation, and touch vs mouse.
Open the width tutorial for breakpoints, or continue with any-hover from the sidebar. Pair media queries with CSS Properties so you know what styles change inside each query.