Aspect Ratio

Aspect Ratio

Sometimes you can’t control the size of an image, you can constrain your images with aspect-ratios. The base class aspect-ratio maintains a 1 to 1 ratio relative to its container’s width.

Use aspect-ratio-3-to-2, aspect-ratio-4-to-3, aspect-ratio-8-to-3, aspect-ratio-8-to-5, or aspect-ratio-16-to-9 to maintain the specific ratio relative to its container or create your own by setting padding-bottom to the ratio you want e.g. 2 to 1 .aspect-ratio-2-to-1 { padding-bottom: 50% }.

1:1
3:2
4:3
8:3
8:5
16:9

Snippet

Aspect Ratio Sass API

The map $aspect-ratio-sizes allows generating any number of aspect ratio variants. If a key starts with ., #, or ’%’ Clay will output it as is, otherwise we will prepend . to the key (e.g., .aspect-ratio-16-to-9). It will also generate a Sass placeholder prefixed by % (e.g., %aspect-ratio-16-to-9).

Snippet

Outputs:

Snippet

Aspect Ratio Bg Contain

The class aspect-ratio-bg-contain on aspect-ratio centers the background-image and scales the image as large as possible without cropping or stretching the image.

Snippet

Aspect Ratio Bg Cover

The class aspect-ratio-bg-cover on aspect-ratio centers the background-image and scales the image to fill the container. It will stretch and change the proportions of the image to achieve this.

Snippet

Aspect Ratio Bg Center

The class aspect-ratio-bg-center on aspect-ratio will center the background-image.

Snippet

Aspect Ratio Item

Use aspect-ratio-item on the nested img if you want to keep the content’s original size and crop the visible area.

thumbnail

Snippet

Aspect Ratio Item Fluid

The class aspect-ratio-item-fluid should be used on aspect-ratio-item to keep wide images viewable inside the aspect-ratio container. It sets the max-width to be 100%, similar to img-fluid.

Original Image
thumbnail of a hot air balloon
16:9
thumbnail
1:1
thumbnail
3:2
thumbnail
4:3
thumbnail
8:3
thumbnail
8:5
thumbnail
16:9
thumbnail

Snippet

Aspect Ratio Item Vertical Fluid

The class aspect-ratio-item-vertical-fluid should be used on aspect-ratio-item to keep tall images viewable inside the aspect-ratio container. It sets the max-height to be 100%.

1:1
thumbnail
3:2
thumbnail
4:3
thumbnail
8:3
thumbnail
8:5
thumbnail
16:9
thumbnail

Snippet

Aspect Ratio Item Flush

The class aspect-ratio-item-flush should be used for images that are too narrow and want it to fill the remaining space. It forces the width to be 100.6%.

The 100.6% width is to account for browser subpixel rendering issues.
16:9
thumbnail
16:9
thumbnail

Snippet

Aspect Ratio Item Vertical Flush

The class aspect-ratio-item-vertical-flush should be used for images that are too short and want it to fill the remaining vertical space. It forces the height to be 100.6%.

The 100.6% height is to account for browser subpixel rendering issues.
16:9
thumbnail
16:9
thumbnail

Snippet

Aspect Ratio Item Center Middle

The class aspect-ratio-item-center-middle centers an item horizontally and vertically.

thumbnail

Snippet

Aspect Ratio Item Top Center

The class aspect-ratio-item-top-center vertically aligns the item at the top and centers it horizontally.

thumbnail

Snippet

Aspect Ratio Item Top Right

The class aspect-ratio-item-top-right aligns the item at the top right corner.

thumbnail

Snippet

Aspect Ratio Item Right Middle

The class aspect-ratio-item-right-middle aligns an item in the middle vertically and right side horizontally.

thumbnail

Snippet

Aspect Ratio Item Bottom Right

The class aspect-ratio-item-bottom-right aligns an item at the bottom right corner.

thumbnail

Snippet

Aspect Ratio Item Bottom Center

The class aspect-ratio-item-bottom-center aligns an item at the bottom vertically and centers it horizontally.

thumbnail

Snippet

Aspect Ratio Item Bottom Left

The class aspect-ratio-item-bottom-left aligns an item at the bottom left corner.

thumbnail

Snippet

Aspect Ratio Item Left Middle

The class aspect-ratio-item-left-middle aligns an item on the left horizontally and in the middle vertically.

thumbnail

Snippet

Edit this page on GitHub

Contributors

Matuzalém Teles

Last edited May 9, 2025 at 6:15:38 AM