Utilities for controlling the background size of an element's background image.
2025-04-10
Written by: tdtc
| Class | Styles |
|---|---|
| bg-auto | background-size: auto; |
| bg-cover | background-size: cover; |
| bg-contain | background-size: contain; |
bg-size-(<custom-property>) | background-size: var(<custom-property>); |
bg-size-[<value>] | background-size: <value>; |
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>
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>
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>
Use the bg-size-[ syntax to set the background size based on a completely custom value:
<div class="bg-size-[auto_100px] ...">
<!-- ... -->
</div>