Performance: Utility-first approach vs traditional CSS
This affects page load speed and rendering performance by changing CSS bundle size and how styles are applied to elements.
Jump into concepts and practice - no test required
<button class="bg-blue-600 text-white p-4 rounded-md">Click me</button> <div class="shadow-md p-8 rounded-md">Content</div>
/* Traditional CSS */ .button { background-color: blue; color: white; padding: 1rem; border-radius: 0.5rem; } .card { box-shadow: 0 4px 6px rgba(0,0,0,0.1); padding: 2rem; border-radius: 0.5rem; } /* Many more selectors with overlapping styles */
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Traditional CSS with large stylesheet | Normal | Low (depends on DOM changes) | Medium due to large CSS | [!] OK |
| Utility-first CSS with Tailwind classes | Normal | Low | Low due to smaller CSS | [OK] Good |
p-4 for padding of 4 units.<button class='bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded'>Click Me</button>
hover:bg-blue-700 changes the background color to blue-700 when hovered.<div class='text-center bg-red-500 p-4'>Hello</div>
text-center is spelled correctly and should center text.shadow-sm, shadow, shadow-md, etc. for shadows. rounded adds normal rounded corners.hover:shadow-lg increase shadow on hover. <div class='shadow-sm rounded hover:shadow-lg p-6'>Card</div> uses shadow-sm with hover:shadow-lg, a common pattern for subtle to stronger shadow on hover.<div class='shadow rounded hover:shadow-lg p-6'>Card</div> uses shadow but no size specified; <div class='box-shadow rounded hover:shadow-xl p-6'>Card</div> uses invalid box-shadow class; <div class='shadow-md rounded-full hover:shadow-2xl p-6'>Card</div> uses rounded-full which makes circle corners, not typical card style.