12 KiB
| title | chunk | source | category | tags | date_saved | instance |
|---|---|---|---|---|---|---|
| Aspect ratio - Glossary | MDN | 1/3 | https://developer.mozilla.org/en-US/docs/Glossary/Aspect_ratio | reference | web, html, css, javascript, documentation | 2026-05-05T05:24:30.298117+00:00 | kb-cron |
MDN HTML HTML: Markup language
HTML reference
HTML guides
Markup languages
CSS reference
CSS guides
Layout cookbook
JavaScriptJS JavaScript: Scripting language
JS reference
JS guides
Web APIs Web APIs: Programming interfaces
Web API reference
Web API guides
- Using the Web animation API
- Using the Fetch API
- Working with the History API
- Using the Web speech API
- Using web workers
Technologies
Topics
Learn Learn web development
Frontend developer course
- Getting started modules
- Core modules
- MDN Curriculum
- Check out the video course from Scrimba, our partner
Learn HTML
Learn CSS
Learn JavaScript
Tools Discover our tools
About Get to know MDN better
Aspect ratio
An aspect ratio is the proportional relationship between an element or viewport's width and height. It is represented as a <ratio> of two numbers.
Having an aspect ratio, whether it's an inherent aspect ratio like with images and videos or if it's extrinsically set, maintains the intended proportions of an element. You can also query an element or viewport's aspect, which is useful in developing flexible components and layouts.
In CSS, the <ratio> data type is written as width / height (e.g., 1 / 1 for a square, 16 / 9 for widescreen) or a single number, in which case the number represents the width and the height is 1.
In SVG, the aspect ratio is defined by the a four-value viewBox attribute. The first two values the smallest X and Y origin coordinates the SVG can have, and the second two values are the width and height which set the aspect ratio of the SVG.
In JavaScript APIs, querying an aspect ratio returns a double-precision floating-point number representing the width divided by height. You can also use JavaScript to set an element's aspect ratio. For example, setting an aspect ratio constraint for a 1920x1080 video using the MediaStreamTrack or MediaTrackSettings dictionary's aspectRatio property would be computed as 16/9, or 1920/1080, which is 1.7777777778:
In this article
See also
- CSS
aspect-ratioproperty - Understanding aspect ratios guide
- CSS box sizing module
- Related glossary terms:
- CSS
min-content,max-content, andfit-contentproperty values.