Layout
Utilities for controlling the aspect ratio of an element.
Class | Styles |
---|---|
aspect-<ratio> | aspect-ratio: <ratio>; |
aspect-square | aspect-ratio: 1 / 1; |
aspect-video | aspect-ratio: var(--aspect-ratio-video); /* 16 / 9 */ |
aspect-auto | aspect-ratio: auto; |
aspect-(<custom-property>) | aspect-ratio: var(<custom-property>); |
aspect-[<value>] | aspect-ratio: <value>; |
Use aspect-<ratio>
utilities like aspect-3/2
to give an element a specific aspect ratio:
Resize the example to see the expected behavior
Tailwind provides a few named aspect ratio utilities for common use cases. For example, use aspect-video
to give a video element a 16 / 9 aspect ratio:
Resize the example to see the expected behavior
Use the aspect-(<custom-property>)
syntax to set the aspect ratio based on a custom property:
<div class="aspect-(--my-aspect-ratio) ..."> <!-- ... --></div>
Use the aspect-[<value>]
syntax to set the aspect ratio based on a completely custom value:
<div class="aspect-[calc(4*3+1)/3] ..."> <!-- ... --></div>
Prefix an aspect-ratio
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<iframe class="aspect-video md:aspect-square ..." src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe>
Learn more about using variants in the variants documentation.
Use the --aspect-*
theme variables to customize the aspect ratio utilities in your project:
@theme { --aspect-retro: 4 / 3; }
Now the aspect-retro
utility can be used in your markup:
<div class="aspect-retro"> <!-- ... --></div>
Learn more about customizing your theme in the theme documentation.