Blog
Understanding CSS Selectors & Specificity for Scalable UI Design
HubSpot CMS Developer
Listen to the Blog
Target HTML elements precisely and understand which styles take priority using CSS selectors and specificity.
What Are CSS Selectors?
Selectors define which HTML elements a CSS rule applies to.
This applies to all <p> elements
Common Selector Types
1. Type Selector
Targets elements by tag name:
2. Class Selector .
Targets elements with a specific class using
This is highlighted text.
3. ID Selector
Targets a single element with #
Welcome
Attribute Selector
Targets elements with specific attributes
Combinators
1. Descendant Selector
Applies to <p> inside a <div>
2. Child Selector
Applies only to direct children
3. Adjacent Sibling Selector
Targets the <p> immediately after <h2>
CSS Specificity
Determines which CSS rule wins when multiple rules target the same element
Specificity hierarchy:
- Inline styles (style="") Highest
- IDs (#id)
- Classes, attributes, pseudo-classes (.class, [attr], :hover)
- Type selectors (div, p) Lowest
Example:
Specificity example
Result: Text will be red because ID has higher specificity
Visual Suggestions
- Diagram showing type, class, ID hierarchy
- GIF highlighting multiple selectors and which one takes effect
- Screenshot of DevTools showing applied styles and specificity
I'm Mukesh Saini, a seasoned HubSpot CMS Developer specializing in custom templates, seamless integrations, and high-performing digital experiences. Having honed his skills over several years in the industry, i possess a deep understanding of HubSpot's capabilities.
HubSpot CMS Developer
Related Post
You may also be interested in
-
Introduction to CSS - Inline, Internal & External Styles
Style your HTML with CSS using different methods to control colors, fonts, layouts, and ...
-
Learn How to Build Tables in HTML Step by Step
Organize data effectively using tables for clear presentation on your web pages.
-
Master HTML Head Elements & Metadata
Everything you see on a page lives in the , but everything search engines and browsers ...