Layout

aspect-ratio

Utilities for controlling the aspect ratio of an element.

ClassStyles
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>;

Examples

Basic example

Use aspect-<ratio> utilities like aspect-3/2 to give an element a specific aspect ratio:

Resize the example to see the expected behavior

<img class="aspect-3/2 object-cover ..." src="/img/villas.jpg" />

Using a video aspect ratio

Use the aspect-video utility to give a video element a 16 / 9 aspect ratio:

Resize the example to see the expected behavior

<iframe class="aspect-video ..." src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe>

Using a custom value

Use the aspect-[<value>] syntax to set the aspect ratio based on a completely custom value:

<img class="aspect-[calc(4*3+1)/3] ..." src="/img/villas.jpg" />

For CSS variables, you can also use the aspect-(<custom-property>) syntax:

<img class="aspect-(--my-aspect-ratio) ..." src="/img/villas.jpg" />

This is just a shorthand for aspect-[var(<custom-property>)] that adds the var() function for you automatically.

Responsive design

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.

Customizing your theme

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:

<iframe class="aspect-retro" src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe>

Learn more about customizing your theme in the theme documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy

Tailwind CSS 中文网(本网站)的目标是为中文开发者提供准确、及时的 Tailwind CSS 中文文档

Tailwind CSS 中文文档由本网站维护人员共同翻译,采用 MIT 开源协议发布

本网站与 tailwindcss.com 及 Tailwind Labs Inc. 并无从属关系

Tailwind 商标由 Tailwind Labs Inc. 所有

京ICP备15031610号-8