HTML & CSS Interview Question #141

How can CSS affect web performance?

Advanced CSS, Accessibility, Performance, Debugging & Senior Scenarios Senior Advanced

Quick Interview Answer

CSS can affect network transfer, style calculation, layout, paint, compositing, and the time required before useful content is rendered. Very large stylesheets, unused rules, excessive font resources, expensive visual effects, and frequent layout-changing updates can all contribute to poor performance.

Detailed Explanation

CSS can affect network transfer, style calculation, layout, paint, compositing, and the time required before useful content is rendered. Very large stylesheets, unused rules, excessive font resources, expensive visual effects, and frequent layout-changing updates can all contribute to poor performance.

Optimization should be measurement-driven. Minify and compress production assets, load critical resources appropriately, remove genuinely unused CSS, limit unnecessary fonts, and prefer layouts and animations that avoid repeated expensive rendering work.

Code Example

/* Prefer a targeted transition. */
.card {
    transition:
        transform .2s ease,
        opacity .2s ease;
}

/* Avoid animating layout-heavy properties
   without a measured reason. */