Performance: Why advanced styling creates polished UIs
Advanced styling affects page load speed and rendering smoothness by controlling CSS complexity and layout stability.
<style>
.card {
width: 300px;
height: auto;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.card:hover {
transform: scale(1.07);
box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
</style><style>
.card {
width: 300px;
height: auto;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
transition: all 0.3s ease;
}
.card:hover {
width: 320px;
box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
</style>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Changing width on hover | None | 1 reflow per hover | 1 repaint per hover | [X] Bad |
| Using transform scale on hover | None | 0 reflows | 0 repaints, only compositing | [OK] Good |
<style>
button {
color: black;
}
@media (max-width: 600px) {
button {
color: blue;
}
}
</style>
<button>Click me</button><style>
.button:hover {
background-color: yellow;
}
</style>
<button class='button' on:hover>Hover me</button>Pass the test and this pattern moves unknown