Last updated: 15 January 2026

Tailwind CSS Aspect Ratio

Set element aspect ratios in Tailwind CSS with aspect-auto, aspect-square, aspect-video, and custom ratios. Essential for responsive images, videos, and embeds.


The aspect-* utilities in Tailwind CSS set the aspect ratio of an element, ensuring it maintains its proportions regardless of the parent container's size. This is essential for responsive images, video embeds, thumbnails, and any element that needs consistent proportions.

How to Set Tailwind Aspect Ratio

Apply an aspect ratio with the aspect-{ratio} class:

  • aspect-auto – Default browser behavior, no forced ratio.
  • aspect-square – 1:1 ratio (perfect square).
  • aspect-video – 16:9 ratio (standard video).
html
<div class="aspect-video bg-gray-200 rounded-lg">
16:9 video container
</div>

Preview

aspect-square (1:1)

aspect-video (16:9)

All Aspect Ratio Classes

| Class | CSS Property | Common Use | |-------|-------------|------------| | aspect-auto | aspect-ratio: auto | Default behavior | | aspect-square | aspect-ratio: 1 / 1 | Profile pictures, thumbnails, icons | | aspect-video | aspect-ratio: 16 / 9 | YouTube embeds, video players |

Responsive Images

Combine aspect-* with object-cover for perfectly proportioned images:

html
<div class="aspect-video overflow-hidden rounded-lg">
<img src="/image.jpg" class="w-full h-full object-cover" alt="Cover image" />
</div>

Preview

Square image

Video ratio

Video Embeds

The classic use case — responsive YouTube or Vimeo embeds:

html
<div class="aspect-video w-full">
<iframe
class="w-full h-full rounded-lg"
src="https://www.youtube.com/embed/..."
allowfullscreen
></iframe>
</div>

Responsive Aspect Ratios

Change aspect ratios at different breakpoints:

html
<div class="aspect-square md:aspect-video lg:aspect-auto">
Square on mobile, 16:9 on tablet, auto on desktop
</div>

✏️ Arbitrary Value Usage

Set custom aspect ratios with arbitrary values:

html
<!-- 4:3 ratio -->
<div class="aspect-[4/3]">
Classic TV ratio
</div>
<!-- 3:2 ratio -->
<div class="aspect-[3/2]">
Photo ratio
</div>
<!-- 21:9 ultrawide -->
<div class="aspect-[21/9]">
Ultrawide cinema ratio
</div>

Preview

4:3 ratio

3:2 ratio

21:9 ultrawide

Common Layout Patterns

Thumbnail Grid

html
<div class="grid grid-cols-3 gap-2">
<div class="aspect-square overflow-hidden rounded-lg">
<img src="/photo1.jpg" class="w-full h-full object-cover" alt="Photo 1" />
</div>
<div class="aspect-square overflow-hidden rounded-lg">
<img src="/photo2.jpg" class="w-full h-full object-cover" alt="Photo 2" />
</div>
<div class="aspect-square overflow-hidden rounded-lg">
<img src="/photo3.jpg" class="w-full h-full object-cover" alt="Photo 3" />
</div>
</div>

Hero Image with Fixed Ratio

html
<div class="aspect-[2/1] w-full overflow-hidden rounded-xl">
<img src="/hero.jpg" class="w-full h-full object-cover" alt="Hero banner" />
</div>

Windframe is an AI visual editor for rapidly building stunning web UIs & websites

Start building stunning web UIs & websites!

Build from scratch or select prebuilt tailwind templates