at-rule

@media — CSS reference

The @media conditional group applies its contents only when the query matches the current environment. Rules still participate in the cascade normally; @media does not add selector specificity. The same rule can react to later viewport changes without reloading.

Formal Syntax & Structure

css syntaxcss
@media (min-width: 600px) { /* conditional declarations */ }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>@media</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}@media (min-width: 600px) {#a{color:rgb(0,100,0)}}</style><body><main id="a">Resize the viewport to explore this example.</main></body></html>
CSS Reference