CSS Type Selector

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The type selector (also called the element selector) matches elements by their tag name — for example p, h1, or a.

It styles every element of that type in the document. Prefer a class when you need only some paragraphs or buttons. Combine both with element.class when the tag and class must match together.

Baseline · Widely available.

Not deprecated. Core CSS since CSS1. Extremely broad browser support.

CSS Syntax

syntax.css
element { /* declarations */ }

Examples: p · h1 · a · ul · button

Selector Forms

PatternMatchesTry it
pEvery paragraphTry it
h1Every top-level headingTry it
aEvery anchor linkTry it
spanEvery inline spanTry it

How to Use the Type Selector

Write the HTML tag name, then the declarations.

  1. Choose the tag to style (p, h2, li, …).
  2. Use that name as the selector — no dot, no hash.
  3. Add only styles that should apply to all of those tags.
  4. Switch to a class when you need a smaller subset.
SelectorSpecificityTypical use
p(0, 0, 1)Base typography for all paragraphs
.intro(0, 1, 0)Selected elements by class
#hero(1, 0, 0)One unique element
p.intro(0, 1, 1)Tag + class together

Live Preview

Switch which type selector is active. Highlighted text shows what p, h2, or span would match.

Sky-blue highlight = elements matched by the chosen type selector.

Sample markup

Heading

A paragraph of text.

Another span inside a paragraph.

p — both paragraphs match

CSS Examples

Each snippet focuses on the type selector. Use Try It Yourself for a live editor.

Example 1 — Style All Paragraphs

Set a shared text color for every p.

CSS
<style>
  p {
    color: #334155;
  }
</style>

<p>First paragraph</p>
<p>Second paragraph</p>
<h2>Not a paragraph</h2>
Try It Yourself

How It Works

  1. Selector. Bare p means every paragraph.
  2. Both p tags. Share the slate color.
  3. h2 skipped. Wrong element type.
  4. Scope tip. Use a class if only some paragraphs should change.

Example 2 — Style the Main Heading

Give every h1 a clear brand color.

CSS
<style>
  h1 {
    color: #2563eb;
  }
</style>

<h1>Page title</h1>
<h2>Section title</h2>
Try It Yourself

How It Works

  1. Rule. h1 targets that heading level only.
  2. Color. Blue applies to the page title.
  3. h2 unchanged. Different tag name.
  4. Base styles. Type selectors are ideal for site-wide heading defaults.

Example 3 — Style All Links

Set a default look for every a element.

CSS
<style>
  a {
    color: #1d4ed8;
    text-decoration: none;
  }
</style>

<p><a href="#">Docs</a> and <a href="#">Blog</a></p>
Try It Yourself

How It Works

  1. Selector. a matches every anchor.
  2. Both links. Share color and no underline.
  3. Global default. Useful as a base before state selectors like :hover.
  4. Narrow later. Use nav a or a class for special links.

Edge Cases & Pitfalls

If too much of the page changes, check these first.

scope

Type selectors are broad

div or p can restyle the whole site. Prefer classes for component-level looks.

specificity

Easy to override

Specificity is only (0,0,1). Classes and ids win conflicts — which is usually what you want.

vs class

No leading dot

p is a type. .p is a class named “p”. The dot changes the meaning completely.

ns

Namespaces (advanced)

With @namespace, forms like svg|a limit matches to a namespace. Rare in everyday HTML pages.

custom

Custom elements work too

A tag like my-card can be selected as my-card { … } the same way as built-in tags.

Browser Support

The type (element) selector is a browser CSS selector. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

type selector

Supported everywhere CSS is supported (CSS1-era). Safe for all teaching and production use.

100% Core support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 3.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 3+
Full support
element Universal

Bottom line: No prefixes. No polyfills. It is not a runtime API.

Key Takeaways

  • Role: match every element of a given HTML tag name.
  • Syntax: the tag alone — p, h1, a (no . or #).
  • Specificity: (0,0,1) — classes and ids override it.
  • Tip: use for base styles; use classes for component variants.

One line: a type selector styles every element that uses that HTML tag name.

Frequently Asked Questions

Also called the element selector, it matches HTML elements by tag name. Writing p { color: gray; } styles every <p> in the document.
A type selector hits every element of that tag. A class selector hits only elements with that class, of any tag.
One type counts as (0,0,1). A class (0,1,0) or id (1,0,0) overrides it when rules conflict.
Yes. p.intro matches only paragraphs with class intro. See the element.class pattern.
In HTML documents they are case-insensitive for HTML elements. In XML/XHTML they follow the document’s case rules.
Yes. It has been in CSS since CSS1 and is Baseline Widely available. It is a browser selector, not a Node.js feature.

Next: universal (*)

Learn how the * selector matches every element.

* tutorial →

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.

8 people found this page helpful