Backgrounds
Utilities for adjusting how a background image is scaled to fit inside its box.
| 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>; |
Reach for the bg-cover utility to grow the background image until it blankets the whole layer, trimming any overflow along the way:
<div class="bg-[url(/img/mountains.jpg)] bg-cover bg-center"></div>Reach for the bg-contain utility to fit the background image to the outer edges without any cropping or stretching:
<div class="bg-[url(/img/mountains.jpg)] bg-contain bg-center"></div>Reach for the bg-auto utility to paint the background image at its default size:
<div class="bg-[url(/img/mountains.jpg)] bg-auto bg-center bg-no-repeat"></div>Reach for the bg-size-[<value>] syntax to define the background size from any fully custom value:
<div class="bg-size-[auto_100px] ..."> <!-- ... --></div>For CSS variables, you can also reach for the bg-size-(<custom-property>) syntax:
<div class="bg-size-(--my-image-size) ..."> <!-- ... --></div>Think of this as a tidy shorthand for bg-size-[var(<custom-property>)] that wires up the var() function on your behalf.
Add a breakpoint variant such as md: in front of a background-size utility so it kicks in only at medium screens and larger:
<div class="bg-auto md:bg-contain ..."> <!-- ... --></div>Dig deeper into working with variants in the variants reference.

5-part crash course
Ship UIs you’re proud of.
Bite-sized, hands-on video lessons from the team behind Breezel, dropped straight into your inbox every day for a week.