Understanding the Element Selector in CSS
The element selector in CSS targets all HTML elements of a specific type. It applies the defined style rules to every instance of that HTML element on the page. This selector is also known as a type selector.
Selects elements by their HTML tag name (e.g., div, p, h1).
Applies styles to all matching elements globally unless overridden.
Has low specificity compared to class or ID selectors.
Useful for setting default styles for common tags.
We have a simple HTML page with a <button> element. How would you write a CSS rule to make all buttons have a blue background using an element selector?
If you add a <button class='primary'> and also have a .primary { background: red; } rule, which background color will the button show and why?
You notice that a <nav> element isn’t picking up the styles you wrote with the nav { background: #333; } selector. What are possible reasons it’s not applying?
During a feature rollout, a teammate wrapped a <p> inside a <section>. Your existing p { margin: 0; } rule now behaves unexpectedly. How would you debug and decide whether to keep the element selector or switch to a class?
Our front‑end team is building a component library that must support theming and avoid CSS bloat. Discuss the trade‑offs of using element selectors versus class selectors for base styling in this context.
A page with thousands of DOM nodes is experiencing a noticeable render lag, and you suspect CSS selector performance. How would you evaluate the impact of element selectors and what mitigation strategies would you propose?
We are migrating a legacy codebase that heavily relies on element selectors to a design system that enforces BEM naming. Outline a migration plan that minimizes visual regressions and maintains performance.
Cross‑team, we need to enforce a consistent visual hierarchy across many micro‑frontends. How would you set policies around element selectors to balance global defaults and team autonomy, and what tooling would you use to enforce them?