aspect-ratio
Quick Summary for aspect-ratio
The aspect-ratio CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.
Code Usage for aspect-ratio
aspect-ratio: 1 / 1; aspect-ratio: 1;  /* Global values */ aspect-ratio: inherit; aspect-ratio: initial; aspect-ratio: revert; aspect-ratio: unset; 
More Details for aspect-ratio

aspect-ratio

The aspect-ratio CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.

aspect-ratio: 1 / 1; aspect-ratio: 1;  /* Global values */ aspect-ratio: inherit; aspect-ratio: initial; aspect-ratio: revert; aspect-ratio: unset; 

Values

auto

Replaced elements with an intrinsic aspect ratio use that aspect ratio, otherwise the box has no preferred aspect ratio. Size calculations involving intrinsic aspect ratio always work with the content box dimensions.

<ratio>

The box's preferred aspect ratio is the specified ratio of width / height. If height and the preceding slash character are omitted, height defaults to 1. Size calculations involving preferred aspect ratio work with the dimensions of the box specified by box-sizing.

Formal definition

Initial valueauto
Applies toall elements except inline boxes and internal ruby or table boxes
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

auto | <ratio>

Examples

Examples of values for aspect-ratio

aspect-ratio: 1 / 1; aspect-ratio: 16 / 9; aspect-ratio: 0.5; 

Mapping width and height to aspect-ratio

Browsers have added an internal aspect-ratio property that applies to replaced elements and other related elements that accept width and height attributes. This appears in the browser's internal UA stylesheet.

In Firefox, the internal stylesheet rule looks like this:

img, input[type="image"], video, embed, iframe, marquee, object, table {   aspect-ratio: attr(width) / attr(height); } 

You can read more about this feature in Setting Height And Width On Images Is Important Again.

Specifications

Specification
CSS Box Sizing Module Level 4 # aspect-ratio

See also

Mapping the width and height attributes of media container elements to their aspect-ratio Designing an aspect ratio unit for CSS Setting Height And Width On Images Is Important Again Select your preferred language English (US)Français日本語中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
When i was a little kid, I was really scared of the dark. But then I came to understand, dark just means the absence of photons in the visible wavelength -- 400 to 700 nanometers. Then i thought, well, its really silly to be afraid of a lack of photons. Then i wasn't afraid of the dark anymore after that.
Elon Musk
Random CSS Property

text-decoration-color

The text-decoration-color CSS property sets the color of decorations added to text by text-decoration-line.
text-decoration-color css reference