Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Selectors

The type (element) selector

Reference for the CSS type selector: match elements by tag name such as p, h1 or button, with specificity, case rules, namespaces and usage notes.

A type selector matches every element with a given tag name. p matches all paragraphs, h2 matches all second-level headings and button matches all buttons. It is the most basic selector and the usual way to set base styles for the whole document.

Type selectors have low specificity (0,0,1), so a class or ID selector will beat them. That is exactly why they work well for defaults.

CSS
h2 {
  color: #1c7ed6;
}

Try it

Styling by tag name

Syntax and arguments

CSS
p { }          /* all <p> elements */
a, button { }  /* a selector list: both types */
nav a { }      /* <a> elements inside <nav> */
svg|circle { } /* with a namespace (rare) */
Part Description
Tag name Written without angle brackets. HTML tag names are matched case-insensitively, so P and p are the same in an HTML document.
Compound with others In a compound selector the type comes first: a.external:hover is valid, while .externala would be read as one class name.
Namespace `ns

Specificity is 0,0,1: one type selector counts as one element-level component.

Usage notes

  • Case sensitivity. In HTML documents, tag names in selectors are case-insensitive. In XML and XHTML served as XML, and in SVG inside XML documents, they are case-sensitive. Lowercase is the convention.
  • SVG in HTML. Elements inside an inline <svg> can be selected by type, for example svg circle. Attributes like viewBox have case rules of their own; the tag names here are fine in lowercase.
  • Set a baseline, not a layout. Use type selectors for typography and defaults (body, h1, p, a). For components, prefer classes, because div or span rules leak into everything.
  • Unknown elements. A type selector can target custom elements like my-card, because custom element names are valid tag names.
  • Specificity gotcha. a class always outranks any number of types, so .item (0,1,0) beats ul li (0,0,2).
  • Pseudo-elements. p::first-line has specificity 0,0,2, because the pseudo-element counts like a type.

Browser support

Supported in every browser.