Backgrounds
Classes for choosing where an element's background image sits within it.
| Class | Styles |
|---|---|
| bg-top-left | background-position: top left; |
| bg-top | background-position: top; |
| bg-top-right | background-position: top right; |
| bg-left | background-position: left; |
| bg-center | background-position: center; |
| bg-right | background-position: right; |
| bg-bottom-left | background-position: bottom left; |
| bg-bottom | background-position: bottom; |
| bg-bottom-right | background-position: bottom right; |
| bg-position-(<custom-property>) | background-position: var(<custom-property>); |
| bg-position-[<value>] | background-position: <value>; |
Reach for utilities such as bg-center, bg-right, and bg-top-left when you want to steer where an element's background image lands:
Hover across each tile below to reveal the full image
bg-top-left

bg-top

bg-top-right

bg-left

bg-center

bg-right

bg-bottom-left

bg-bottom

bg-bottom-right

<div class="bg-[url(/img/mountains.jpg)] bg-top-left"></div><div class="bg-[url(/img/mountains.jpg)] bg-top"></div><div class="bg-[url(/img/mountains.jpg)] bg-top-right"></div><div class="bg-[url(/img/mountains.jpg)] bg-left"></div><div class="bg-[url(/img/mountains.jpg)] bg-center"></div><div class="bg-[url(/img/mountains.jpg)] bg-right"></div><div class="bg-[url(/img/mountains.jpg)] bg-bottom-left"></div><div class="bg-[url(/img/mountains.jpg)] bg-bottom"></div><div class="bg-[url(/img/mountains.jpg)] bg-bottom-right"></div>Reach for the bg-position-[<value>] syntax whenever you want to pin the background position to an entirely custom value:
<div class="bg-position-[center_top_1rem] ..."> <!-- ... --></div>When you're working with CSS variables, the bg-position-(<custom-property>) syntax comes
<div class="bg-position-(--my-bg-position) ..."> <!-- ... --></div>Think of it as a tidy shorthand for bg-position-[var(<custom-property>)] that wires up the var() function on your behalf.
Add a breakpoint variant such as md: in front of any background-position utility so it only takes effect at medium screens and larger:
<div class="bg-center md:bg-top ..."> <!-- ... --></div>Read up on how to work with variants over variants reference guide.

5-day quick series
Build UIs worth showing off.
Short, hands-on video lessons from the team behind Breezel, dropped straight into your inbox every single day for a full week.