media-feature
Aspect ratio — CSS reference
Aspect ratio is the ratio of the queried width to height. It is a dimensionless ratio of the viewport for continuous media, not the aspect ratio of an image or a CSS element.
Formal Syntax & Structure
css syntaxcss
@media (aspect-ratio >= 1/1) { /* conditional declarations */ }Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>aspect-ratio</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}@media (aspect-ratio >= 1/1) {#a{color:rgb(0,100,0)}}</style><body><main id="a">Resize the viewport to explore this example.</main></body></html>