Performance: Background size and position
This affects how quickly background images load and how smoothly they render on the page.
Jump into concepts and practice - no test required
bg-[url('/large-image.jpg')] bg-cover bg-centerbg-[url('/large-image.jpg')] bg-auto bg-center| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| bg-auto with large image | Minimal | Multiple reflows if image size changes | High paint cost due to large image | [X] Bad |
| bg-cover with optimized image | Minimal | Single reflow | Lower paint cost | [OK] Good |
| Arbitrary complex bg-position | Minimal | No reflows | Slightly higher style calculation | [!] OK |
| Tailwind built-in bg-position | Minimal | No reflows | Lower style calculation | [OK] Good |
bg-cover makes the background image fill the entire element, cropping if needed.bg-contain fits the whole image inside without cropping, bg-auto keeps original size, and bg-center is about position, not size.bg-top for top center, but does not have bg-top-right.bg-top sets top center, bg-righttop is invalid, and bg-top-right is not a valid Tailwind class.<div class="bg-contain bg-bottom bg-no-repeat w-64 h-64"></div>
bg-contain makes the image fit inside the div without cropping.bg-bottom places the image at the bottom, and bg-no-repeat prevents repeating.<div class="bg-auto bg-center bg-cover"></div>
bg-auto keeps original size, bg-cover fills the area. Using both together conflicts because they set different sizes.bg-center is valid for position, and bg-no-repeat is optional; its absence doesn't cause an error.bg-auto and bg-cover together causes conflict [OK]bg-contain fits the entire image inside without cropping, perfect for responsive cards.bg-top-left places image at top left corner, and bg-no-repeat prevents repeating.bg-contain bg-top-left bg-no-repeat [OK]