CSS Element Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
HTML Tags

What You’ll Learn

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.

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.

📝 Syntax

The syntax for the element (type) selector is:

syntax.css
element {
  /* CSS properties */
}

Replace element with any HTML tag name:

element-examples.css
h1 { color: #2563eb; }
p  { color: #64748b; }
div { padding: 1rem; }
a  { color: #2563eb; }
h1 p div a ul body

Specificity Comparison

SelectorExampleSpecificity
Element (type)p(0, 0, 1)
Class.intro(0, 1, 0)
ID#header(1, 0, 0)
Element + classp.intro(0, 1, 1)

Syntax Rules

  • Use the exact HTML tag name: p, not P (HTML tags are case-insensitive, but use lowercase in CSS).
  • One rule affects every matching element on the page unless overridden.
  • Chain with classes: p.lead is more specific than bare p.
  • Group selectors with commas: h1, h2, h3 { } shares styles across tags.
  • Element selectors are the lowest-specificity type selector — classes and ids win conflicts.

Related Topics

  • .class — target elements by class attribute
  • #id — target a unique element by id
  • element element — descendant combinator
  • color — often set on element selectors
  • font-family — base typography on body

⚡ Quick Reference

QuestionAnswer
Also known asType selector, tag selector
What it targetsAll elements with a given HTML tag name
Syntaxtagname { } — e.g. p { }
Specificity(0, 0, 1) per element
Common useBase typography, resets, global defaults
Browser supportAll browsers (since CSS 1)

When to Use Element Selectors

Element selectors are ideal for consistent, page-wide defaults:

  • Typography baselines — Set font, color, and line-height on body, p, and headings.
  • Link styling — Default a color and underline across the site.
  • List formatting — Indent and space ul, ol, and li elements.
  • Form defaults — Base padding and border on input and textarea.
  • CSS resets — Normalize margins on h1h6, p, and body.

👀 Live Preview

This demo uses element selectors to style h1, p, and div tags:

Welcome to My Website

This paragraph is styled with the element selector p.

Every paragraph on the page shares the same base styles.

This div has its own element selector styles.

Examples Gallery

Practice element selectors with headings and paragraphs, typography scales, list styling, and element.class combinations.

📜 Core Patterns

Style HTML tags directly by element name.

Example 1 — Basic element selectors

Style all h1, p, and div elements with distinct rules.

element-basic.css
h1 {
  color: #2563eb;
  font-size: 2rem;
  text-align: center;
}

p {
  color: #64748b;
  line-height: 1.6;
}

div {
  background: #f1f5f9;
  padding: 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.4rem;
}
Try It Yourself

How It Works

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.

element-typography.css
body {
  font-family: system-ui, sans-serif;
  color: #334155;
  line-height: 1.6;
}

h1 { font-size: 2rem; color: #1e293b; }
h2 { font-size: 1.5rem; color: #1e293b; }
h3 { font-size: 1.25rem; color: #334155; }

a {
  color: #2563eb;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}
Try It Yourself

How It Works

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.

Example 3 — List element selectors

Style ul, ol, and li for clean, readable lists.

element-lists.css
ul {
  list-style-type: disc;
  padding-left: 1.5rem;
  margin: 0.75rem 0;
}

ol {
  list-style-type: decimal;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.35rem;
  color: #475569;
  line-height: 1.55;
}
Try It Yourself

How It Works

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.

element-class.css
p {
  color: #64748b;
  font-size: 1rem;
  line-height: 1.6;
}

p.lead {
  font-size: 1.125rem;
  color: #1e293b;
  font-weight: 500;
}
Try It Yourself

How It Works

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".

💬 Usage Tips

  • Start with defaults — Use element selectors for site-wide base styles before adding classes.
  • Group related tagsh1, h2, h3 { font-family: serif; } shares one rule.
  • Combine with classesbutton.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.

⚠️ Common Pitfalls

  • Unintended global stylingdiv { 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 broadlya { 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 typosparagaraph is not a valid selector; match real HTML tag names.

♿ Accessibility

  • Use semantic HTML — Style real heading levels (h1h6) 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.

🖥 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 Chrome 1+ · All versions
Full support
Mozilla Firefox 1+ · All versions
Full support
Apple Safari 1+ · All versions
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
Element (type) selector 100% supported

Bottom line: The safest selector in CSS. Use freely for base styles in any project.

🎉 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.

💡 Best Practices

✅ Do

  • Set typography defaults on body and headings
  • Reset browser default margins on h1h6 and p
  • Group shared styles: h1, h2, h3 { }
  • Use element.class for targeted 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

Key Takeaways

Knowledge Unlocked

Five things to remember about element selectors

Use these points when writing your first CSS rules.

5
Core concepts
all 02

All matches

Every tag.

Scope
001 03

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.

Practice in the Live Editor

Open the HTML editor and experiment with element selectors for h1, p, div, and list tags.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful