Performance: Why backgrounds enhance design
Backgrounds affect page load speed and rendering performance by adding image assets and paint complexity.
Jump into concepts and practice - no test required
<div class="bg-[url('/small-optimized-image.webp')] bg-cover bg-center"></div><div class="bg-[url('/large-unoptimized-image.jpg')] bg-cover bg-center"></div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large unoptimized background image | Minimal | 0 | High (delays paint) | [X] Bad |
| Optimized background image | Minimal | 0 | Medium (faster paint) | [!] OK |
| Complex CSS gradient | Minimal | 0 | Medium-High (multiple paint layers) | [!] OK |
| Simple CSS gradient | Minimal | 0 | Low (fewer paint layers) | [OK] Good |
| Background color only | Minimal | 0 | Very Low (instant paint) | [OK] Good |
bg- set background colors.bg-gray-200 applies a light gray background, while others affect text, border, or hover states.<div class="bg-blue-500 bg-opacity-50">Hello</div>
bg-blue-500 sets a medium blue background color. bg-opacity-50 sets the background transparency to 50%.<div class="bg-red-600 bg-opacity-150">Error</div>
bg-opacity-150 is invalid.bg-red-600 is a valid color. Class names are space-separated, not comma-separated.bg-gradient-to-r creates a gradient from left to right. from-green-400, via-blue-500, and to-purple-600 define the gradient colors.p-6 and rounded corners rounded-lg improve focus and modern look.