background size

Utilities for controlling the background size of an element's background image.

2025-04-10

Written by: tdtc

ClassStyles
bg-autobackground-size: auto;
bg-coverbackground-size: cover;
bg-containbackground-size: contain;
bg-size-(<custom-property>)background-size: var(<custom-property>);
bg-size-[<value>]background-size: <value>;

Filling the container

Use the bg-cover utility to scale the background image until it fills the background layer, cropping the image if needed:

<div class="bg-[url(/img/mountains.jpg)] bg-cover bg-center"></div>

Filling without cropping

Use the bg-contain utility to scale the background image to the outer edges without cropping or stretching:

<div class="bg-[url(/img/mountains.jpg)] bg-contain bg-center"></div>

Using the default size

Use the bg-auto utility to display the background image at its default size:

<div class="bg-[url(/img/mountains.jpg)] bg-auto bg-center bg-no-repeat"></div>

Using a custom value

Use the bg-size-[] syntax to set the background size based on a completely custom value:

<div class="bg-size-[auto_100px] ...">
  <!-- ... -->
</div>

Ref