Performance: Gradient utilities (from, via, to)
This affects the browser's paint performance and visual rendering speed by controlling how gradients are drawn on elements.
Jump into concepts and practice - no test required
@apply bg-gradient-to-r from-red-500 via-green-500 to-blue-500;
background: linear-gradient(to right, #ff0000, #00ff00, #0000ff);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Complex manual gradient CSS | Minimal | 0 | High due to multiple color stops | [X] Bad |
| Tailwind gradient utilities (from, via, to) | Minimal | 0 | Lower paint cost with GPU acceleration | [OK] Good |
from-blue-500 do when used with a gradient background?from- class in Tailwind sets the first color stop in a gradient.from-blue-500from- means start color [OK]bg-gradient-to-{direction}, here to-r means left to right.from- (start), via- (middle), then to- (end). bg-gradient-to-r from-red-500 via-yellow-400 to-green-500 follows this order correctly.bg-gradient-to-r from-red-500 via-yellow-400 to-green-500 [OK]<div class="bg-gradient-to-b from-purple-400 via-pink-500 to-red-500 h-32 w-32"></div>
bg-gradient-to-b means gradient goes from top to bottom (vertical).from-purple-400 is start (top), via-pink-500 is middle, to-red-500 is end (bottom).class="bg-gradient-to-l from-green-400 to-yellow-500 via-blue-500"
bg-gradient-to-l is valid and means gradient goes leftwards.from-green-400, to-yellow-500, and via-blue-500. Tailwind allows via- anywhere between from and to; order in class attribute does not matter.bg-gradient-to-br.from-blue-600), middle pink (via-pink-300), end purple (to-purple-700).bg-gradient-to-br from-blue-600 via-pink-300 to-purple-700 matches direction and color order perfectly; others mix colors or directions incorrectly.bg-gradient-to-br from-blue-600 via-pink-300 to-purple-700 [OK]