Home CSS Selectors element CSS Type Selector Definition
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.
Syntax
CSS Syntax element { /* declarations */ }
Examples: p · h1 · a · ul · button
Approach
How to Use the Type Selector Write the HTML tag name, then the declarations.
Choose the tag to style (p, h2, li, …). Use that name as the selector — no dot, no hash. Add only styles that should apply to all of those tags. Switch to a class when you need a smaller subset. Selector Specificity Typical 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
Try it
Live Preview Switch which type selector is active. Highlighted text shows what p, h2, or span would match.
Code
CSS Examples Each snippet focuses on the type selector. Use Try It Yourself for a live editor.
1. Style paragraphs 2. Style a heading 3. Style links Example 1 — Style All Paragraphs Set a shared text color for every p.
<style>
p {
color: #334155;
}
</style>
<p>First paragraph</p>
<p>Second paragraph</p>
<h2>Not a paragraph</h2> First paragraph
Second paragraph
Not a paragraph How It Works Selector. Bare p means every paragraph.Both p tags. Share the slate color.h2 skipped. Wrong element type.Scope tip. Use a class if only some paragraphs should change.Example 2 — Style the Main Heading Give every h1 a clear brand color.
<style>
h1 {
color: #2563eb;
}
</style>
<h1>Page title</h1>
<h2>Section title</h2> How It Works Rule. h1 targets that heading level only.Color. Blue applies to the page title.h2 unchanged. Different tag name.Base styles. Type selectors are ideal for site-wide heading defaults.Example 3 — Style All Links Set a default look for every a element.
<style>
a {
color: #1d4ed8;
text-decoration: none;
}
</style>
<p><a href="#">Docs</a> and <a href="#">Blog</a></p> How It Works Selector. a matches every anchor.Both links. Share color and no underline.Global default. Useful as a base before state selectors like :hover.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.
Compatibility
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.
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.
Remember
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 What is the CSS type selector? Also called the element selector, it matches HTML elements by tag name. Writing p { color: gray; } styles every <p> in the document.
How is it different from a class selector? A type selector hits every element of that tag. A class selector hits only elements with that class, of any tag.
What is the specificity of a type selector? One type counts as (0,0,1). A class (0,1,0) or id (1,0,0) overrides it when rules conflict.
Can I combine type and class? Yes. p.intro matches only paragraphs with class intro. See the element.class pattern.
Are type selectors case-sensitive? In HTML documents they are case-insensitive for HTML elements. In XML/XHTML they follow the document’s case rules.
Is the type selector widely supported? 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 Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion