SEO check

CSS Media Queries: Syntax, Examples and How to Fix the Check

A practical guide to CSS media queries, how our free report decides pass or fail, and how to add responsive breakpoints the right way.

Free to use 6 min read Updated Oct 2026

CSS Media Queries in One Minute

Quick answer: CSS media queries are @media rules that apply a block of CSS only when a condition is true, such as the viewport being at least 768px wide. Our report passes a page when one of its first eight linked stylesheets holds a plain @media rule with a bracket right after the keyword.

  • Pass: A linked stylesheet contains a rule like @media (min-width: 768px).
  • Fail: None of the first eight linked stylesheets does, or your queries live only in inline CSS.
  • Fix: Add a mobile first min-width rule to a linked .css file, then run the report again.

Check my website

What Are CSS Media Queries?

A media query is the @media at-rule. The browser tests its condition continuously and switches the wrapped rules on or off as the window, device or user preference changes. Google Search Central recommends responsive design with the same HTML on every device. The MDN @media reference documents the full syntax.

A query lives either in an @media block inside a stylesheet or in the media attribute of a link element. A linked sheet that doesn't match still downloads, at lower priority and without blocking rendering, as our guide to render blocking resources explains.

Anatomy of an @media rule

A rule has an optional media type (it defaults to all), conditions in brackets, and a block of ordinary CSS.

CSS
/* media type: screen, condition: viewport at least 768px wide */
@media screen and (min-width: 768px) {
  .nav { display: flex; }
}

When the condition fails, the browser skips the block and the base styles stay in force. Current browsers also let you nest a query inside a style rule, next to its base styles.

CSS
.card { padding: 1rem; @media (min-width: 768px) { padding: 2rem; } }

When a script needs the same answer, window.matchMedia runs the query from JavaScript.

Types, features and operators

The three types are all, screen and print. Each media feature in brackets tests one thing: width and height (with min-height and max-height), orientation (landscape or portrait), aspect-ratio, resolution, hover and pointer. The preference features prefers-color-scheme, prefers-reduced-motion, prefers-contrast and forced-colors come from Media Queries Level 5.

The logical operators are the and operator, the not operator and only, which hides a query from very old browsers. A comma separates queries and acts as or, and Media Queries Level 4 added a real or keyword plus range syntax such as (600px <= width < 1000px), the same test as a min-width and max-width pair but easier to read.

CSS
@media screen, print { body { color: #111; } }
@media (orientation: landscape) and (min-width: 600px) { .hero { height: 60vh; } }
@media not print { .nav { position: sticky; } }

The comma list applies when either query is true, and not flips the rest. Resolution targets sharp displays, hover and pointer separate a mouse from a touchscreen, and the media attribute on a link element applies the idea to a whole file.

HTML
<link rel="stylesheet" href="wide.css" media="(min-width: 768px)">
CSS
@media (min-resolution: 2dppx) { .logo { background-image: url(logo-2x.png); } }
@media (hover: hover) and (pointer: fine) { .menu a:hover { text-decoration: underline; } }

Min-width versus max-width

Min-width builds up: the base CSS serves the smallest screen and each query adds layout. Max-width strips down from a desktop base. Both limits are inclusive, so min-width: 768px and max-width: 768px both match a viewport exactly 768px wide. Range syntax with an exclusive upper bound avoids the clash.

How SEO Site Checker Tests CSS Media Queries

This check sits on the card titled Mobile Snapshot and Responsiveness, covered from the screenshot side in our mobile snapshot check guide. The test is a text scan, not a visual one.

Exact rule: the check passes when at least one of the first eight linked stylesheets contains the text @media, then optional spaces, then an opening bracket. Case is ignored. Anything else is a fail.

What the scanner reads

The report loads your page in headless Chromium and takes the rendered HTML, so stylesheet links that scripts have added by the time the page settles are generally part of the rendered HTML we read. It collects every link element whose rel includes stylesheet, keeps the first eight, and downloads each with a 3 second connect and read timeout inside a 10 second shared window. There is no warning state, and a page with no linked stylesheet fails.

What counts as pass or fail

PatternCountedWhy
@media (min-width: 768px)YesBracket follows the keyword
@media(max-width:600px)YesThe space is optional
@media (width >= 768px)YesRange syntax opens with a bracket
@media (prefers-color-scheme: dark)YesAny bracketed query matches
@media screen and (min-width: 768px)NoWords sit before the bracket
@media only screen and (...)NoSame reason
@media printNoNo bracket at all

One dark mode query turns the card green although it says nothing about layout.

Not tested: whether any query changes your layout, the viewport meta tag, inline style blocks, @import files, protocol relative links and the 430 px screenshot. A pass only proves the text exists in a linked stylesheet, and the scan reads raw text, so even a commented-out rule would count.

Cases that surprise people

  • Inline CSS. Queries in a style block are never read, including the WordPress Additional CSS box. See the inline CSS guide for why.
  • The @import rule. Styles pulled in through @import are not followed.
  • The media attribute on a link. It is valid responsive CSS, but the scan reads only file contents.
  • Protocol relative and relative links. An href such as //cdn.example.com/site.css is skipped, so write the full https:// address. Relative hrefs are joined to the site root, not the page's folder.
  • The ninth stylesheet. Only the first eight files are downloaded, and a file that times out counts as no match.

The 430 px screenshot on the card has no effect on the result. The failed card says the page is not using CSS media queries, but the test is narrower than that: it only recognises the plain @media ( form in a linked file. A responsive site that writes every query as @media screen and (...), or keeps them in inline CSS, can therefore show red. One plain @media (min-width: ...) rule in a linked stylesheet is the whole remedy.

Test my CSS now

How to Add CSS Media Queries the Mobile First Way

  1. Confirm the viewport tag. Without <meta name="viewport" content="width=device-width, initial-scale=1"> mobile browsers lay the page out at about 980 CSS pixels, so narrow queries never fire in responsive web design terms. Our meta viewport tag guide has the details.
  2. Write base styles first. Style the smallest screen with no query: one column, full width images.
  3. Add min-width queries where the layout strains. Widen the browser until something breaks.
  4. Use the plain form. Write @media (min-width: 600px) instead of prefixing screen and. It behaves the same on screens, our scanner recognises it, and print rules belong in their own block.
  5. Keep queries in a linked file. A .css file is scanned, while a style block or theme customizer box is not.
  6. Run the report again. Clear caches first, then confirm the card is green.
CSS
.cards { display: grid; grid-template-columns: 1fr; }
@media (min-width: 600px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
}

CSS Media Query Examples and Common Breakpoints

These are the default breakpoints of two popular frameworks, both mobile first with min-width.

NameBootstrap breakpoints (5.3)Tailwind breakpoints
sm576px640px
md768px768px
lg992px1024px
xl1200px1280px
xxl or 2xl1400px1536px

The web.dev media queries lesson argues for content based breakpoints: add one where a line of text grows too long, not where a device model ends.

CSS
@media (min-width: 48em) { .layout { display: grid; } }
@media (600px <= width < 900px) { .sidebar { float: none; width: auto; } }
@media print { .site-nav { display: none; } }

The first query uses em units on purpose. Em values follow the browser's default font size, so a visitor who raised that setting keeps the single column layout until the window is wide enough for the larger text. Container queries suit component level layout better.

Why Your CSS Media Queries Are Not Working

  • No viewport tag. A phone reporting 980 px never matches max-width: 640px. Add the tag from the meta viewport tag guide.
  • Wrong order. A query above the rule it overrides loses on source order, so place queries after the rules they change.
  • Syntax slips. The text and(min-width: 600px) is invalid because and needs a space before the bracket, and a bare 768 without px breaks it too.
  • Queries in the wrong place. Browsers apply them, but see the report section above: inline blocks are skipped.
  • Too many or slow files. Anything past the eighth link, or a file that times out, goes unread.
  • Test that the query fires. Put a red outline inside the query, then drag the width across the breakpoint in DevTools.

CSS Media Query Best Practices

  • Design mobile first. With min-width queries the base CSS is the small screen layout and each query only adds to it, so there is less to override and undo and the stylesheet is easier to maintain. The whole file still downloads on every device.
  • Keep content identical. Googlebot smartphone indexes the mobile version, so content found only on desktop may never be indexed, as the Google mobile-first indexing guidance explains. Rearrange content with queries, never remove it.
  • Prefer fluid techniques. Wrapping flexbox rows, auto-fit grid columns and clamp() for type reflow on their own, so you write a query only where the design changes shape.
  • Minify when finished. Follow our CSS minification guide once the queries settle.

How to Fix

The short version, the same steps you see when you click How to Fix in your report.

Why this fails: None of the first eight stylesheets linked from your page contains an @media rule our scanner recognises, so responsive styling could not be confirmed. Queries written only in inline style blocks, or as @media screen and (...), are not matched, and stylesheet links starting with // are skipped.

How to fix it:

  1. Check that the head contains <meta name="viewport" content="width=device-width, initial-scale=1"> and add it if it is missing.
  2. If the site has no responsive CSS yet, write base styles for the smallest screen first, with no query.
  3. Add @media (min-width: 768px) rules to a linked .css file.
  4. If your site is already responsive, rewrite one rule from @media screen and (min-width: 768px) to @media (min-width: 768px). Both behave the same on screens, and only the second form is recognised by the scanner.
  5. Keep the queries in that linked file, not in an inline style block.
  6. If your page links more than eight stylesheets, put the media queries in one of the first eight, or merge files, because later links are not read.
  7. Link the stylesheet with a full https:// address, because a link starting with // is skipped.
  8. Clear your caches so the scanner downloads the new file.
CSS
/* one column by default, two columns from 768px */
.cards { display: grid; grid-template-columns: 1fr; }
@media (min-width: 768px) {
  .cards { grid-template-columns: 1fr 1fr; }
}
  • WordPress: add the rules to the child theme style.css and make sure functions.php enqueues it. Avoid the Additional CSS box, which prints an inline style block.
  • Shopify: in the admin go to Online Store, Themes, Edit code, then open a file under Assets such as base.css and add the rules there.
  • Static site: edit the linked .css file and upload it again.

Re-test: run our free report again, open the Mobile Snapshot and Responsiveness card and confirm it shows the passed message. Syntax details are in the MDN @media reference.

Re-test my website

Frequently Asked Questions

What are CSS media queries used for?
They apply CSS only when a condition is true, such as viewport width, orientation, resolution or a user preference like dark mode. The usual job is rearranging a layout for phones, tablets and desktops, and they also drive print styles.
How do I write a CSS media query for mobile?
Write base styles for small screens first, then add a rule such as @media (min-width: 768px) for larger ones. Add the viewport meta tag too, or phones use a wide virtual width and narrow rules never match.
Should I use min-width or max-width in media queries?
Use min-width for a mobile first build, because styles grow with the screen and little needs overriding. Use max-width for desktop first code or a one off fix. If you pair the two, use range syntax or offset the values by 0.02px or one pixel, so the queries never match the same width.
What are the most common CSS media query breakpoints?
Popular frameworks cluster around 576 to 640, 768, 992 to 1024, 1200 to 1280 and 1400 to 1536 pixels, the Bootstrap and Tailwind defaults. Treat them as starting points, because breakpoints chosen where your content breaks age better.
Why are my CSS media queries not working on mobile?
Usually because the viewport meta tag is missing, the rule sits in the wrong order, or the syntax is invalid, such as a missing bracket or unit. An unclosed brace in an earlier rule can swallow the query after it.
Do CSS media queries affect SEO?
Not as a direct ranking factor, but they make responsive design possible. Google recommends one URL with the same HTML for every device and indexes the mobile version. Our report marks a page red when it finds no plain @media rule in a linked stylesheet, which is a narrower test than full responsiveness.
Can I use media queries in inline CSS?
Only in a style element, not in a style attribute, which cannot hold an @media rule. An external stylesheet is better still. Our report reads linked stylesheets and ignores inline style blocks, so queries kept only inline show as a fail.

See how your site scores right now

Paste your address into the free report, then use the How to Fix button on anything that needs work.

Free to use. Results in under a minute for most sites.