Performance: Element selectors
Element selectors affect how quickly the browser matches CSS rules to HTML elements during style calculation.
Jump into concepts and practice - no test required
.intro-text { color: blue; font-size: 1.2rem; }
p { color: blue; font-size: 1.2rem; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Element selector (e.g., p) | Matches all <p> elements | 0 | Low | [OK] |
| Class selector (e.g., .intro-text) | Matches fewer elements | 0 | Low | [OK] Good |
p { color: red; }p targets all <p> tags in the HTML.h1.<div> <p>Hello</p> <p>World</p> <span>!</span> </div>
p { color: blue; }p styles only <p> elements, not <span>..li { color: green; }.li targets elements with class 'li', not the <li> tag.li without a dot.button without dot or hash, correctly selecting all <button> elements.