The CSS element selector (also called the type selector) matches HTML elements by tag name. It is the most fundamental way to apply styles — write p to style every paragraph, or h1 for all top-level headings.
01
Tag name
p, h1, div.
02
All matches
Every element.
03
Specificity
(0, 0, 1)
04
Base styles
Typography.
05
Combine
p.intro
06
Lists
ul, ol, li.
Fundamentals
Introduction
The CSS element selector targets HTML elements based on their tag name. When you write h1 { color: blue; }, every <h1> on the page receives that style. No class or id is required.
This selector is also known as the type selector because it selects by element type. It is usually the first selector beginners learn and forms the foundation for more specific rules using classes, ids, and combinators.
Definition and Usage
Use element selectors to set base styles that apply consistently across your site: default paragraph spacing, heading sizes, link colors, and list indentation. Because they affect all matching tags, they are ideal for global typography and reset styles in your stylesheet.
💡
Beginner Tip
Start with element selectors for page-wide defaults (body, p, a), then add .class or #id rules when you need to style individual components differently.
Each rule targets every element of that tag type. All <p> elements get gray text; all <h1> elements get blue centered headings. No classes needed for these base styles.
Example 2 — Typography with element selectors
Set a type scale for headings and body text using multiple element rules.
body sets inherited defaults for the whole page. Individual heading elements get their own font sizes, and a gets link styling. This is the standard pattern for a typography foundation.
📄 Lists & Combinations
Style lists and combine element selectors with classes.
Each list-related tag gets its own rule. ul and ol control bullet/number style and indentation; li controls spacing and text color for every list item.
Example 4 — element.class combined selector
Use p.lead to style only paragraphs with class="lead", not every p.
The bare p rule sets defaults for all paragraphs. p.lead adds extra specificity (0, 1, 1) to override the base rule only on elements with class="lead".
Tips
💬 Usage Tips
Start with defaults — Use element selectors for site-wide base styles before adding classes.
Group related tags — h1, h2, h3 { font-family: serif; } shares one rule.
Combine with classes — button.primary targets only primary buttons.
Understand specificity — A class rule always beats a bare element rule.
Reset margins — Browsers add default margins to h1, p, ul; reset them explicitly.
Use semantic tags — Style article, nav, and section for meaningful layout defaults.
Watch Out
⚠️ Common Pitfalls
Unintended global styling — div { padding: 2rem; } affects every div on the page.
Specificity surprises — A class on one element overrides your element rule; know the cascade.
Overusing element selectors — For component-specific styles, prefer classes over tag names.
Styling too broadly — a { color: red; } turns every link red, including nav and footer.
Forgetting inheritance — Styles on body flow to children; some properties do not inherit.
Tag name typos — paragaraph is not a valid selector; match real HTML tag names.
A11y
♿ Accessibility
Use semantic HTML — Style real heading levels (h1–h6) instead of resizing div tags.
Maintain contrast — Element-level text colors should meet WCAG contrast guidelines.
Do not remove focus styles — When styling a or button, keep visible :focus outlines.
Heading hierarchy — Style h1 larger than h2 to reflect document structure for screen readers.
List semantics — Use ul/ol/li for lists; do not fake lists with styled div elements.
🧠 How Element Selectors Work
1
Write the tag name
You write a CSS rule like p { color: gray; } using the HTML tag name.
CSS
2
Browser finds matches
The browser scans the HTML and collects every element with that tag name.
Match
3
Styles are applied
Declared properties apply to all matched elements, unless a more specific rule overrides them.
Render
=
✎
Consistent tag styling
Every <p>, <h1>, or <a> shares the same base appearance across the page.
Compatibility
🖥 Browser Compatibility
Element selectors have been supported since the first version of CSS and work in every browser.
✓ Baseline · CSS 1
The original CSS selector
Element selectors work in Chrome, Firefox, Safari, Edge, Opera, and all legacy browsers. They are the foundation of every CSS stylesheet.
100%Global support
Google Chrome1+ · All versions
Full support
Mozilla Firefox1+ · All versions
Full support
Apple Safari1+ · All versions
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
Element (type) selector100% supported
Bottom line: The safest selector in CSS. Use freely for base styles in any project.
Wrap Up
🎉 Conclusion
The CSS element selector is a straightforward yet powerful way to style HTML by tag name. It is the foundation of every stylesheet — setting typography, spacing, and defaults that create a cohesive design across your pages.
Use element selectors for global base styles, then layer classes and ids for component-specific customization. Understanding specificity helps you avoid unexpected overrides.
Prefer semantic HTML tags over generic div styling
❌ Don’t
Style every component with bare tag selectors
Ignore specificity when mixing element and class rules
Remove focus outlines from a and button
Use element selectors for one-off layout tweaks
Rely on div for everything instead of semantic tags
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about element selectors
Use these points when writing your first CSS rules.
5
Core concepts
p01
Tag name
Type selector.
Syntax
all02
All matches
Every tag.
Scope
00103
Low specificity
(0, 0, 1)
Cascade
p.04
+ class
p.intro
Combine
🌐05
100% support
CSS 1.
Compat
❓ Frequently Asked Questions
The element selector — also called the type selector — matches HTML elements by their tag name. Writing p { color: gray; } styles every <p> element on the page.
An element selector targets all elements of a tag type (every p, every h1). A class selector targets only elements with a specific class attribute, regardless of tag.
An element selector has specificity (0, 0, 1) — one type. Class selectors (0, 1, 0) and id selectors (1, 0, 0) override element rules when they conflict.
Yes. p.intro selects only <p> elements that also have class="intro". This is more specific than a bare p selector.
Yes. Element selectors are the most fundamental CSS selectors and have been supported in every browser since CSS was introduced.