A type selector is simply the HTML tag name written without any prefix, p, h1, div, and it matches every element of that type anywhere in the document, regardless of nesting or attributes — it's the broadest, least specific kind of named selector, carrying the lowest specificity of any selector other than the universal selector, which means it's easily overridden by class or ID selectors targeting the same elements. Type selectors are typically used for broad, foundational styling that should apply consistently across an entire site, like default margins on paragraphs or a base font on the body.
1Understanding Basic Selectors
A type selector is simply the HTML tag name written without any prefix, p, h1, div, and it matches every element of that type anywhere in the document, regardless of nesting or attributes — it's the broadest, least specific kind of named selector, carrying the lowest specificity of any selector other than the universal selector, which means it's easily overridden by class or ID selectors targeting the same elements. Type selectors are typically used for broad, foundational styling that should apply consistently across an entire site, like default margins on paragraphs or a base font on the body.
Type selectors carry the lowest specificity of any named selector, so use them for broad, foundational defaults, like resetting margins or setting a base font, that you expect more specific class or ID selectors to override later as needed.
p {
line-height: 1.6;
color: #333;
}2Practical Example
Here is a real-world application of Basic Selectors showing how it is used in production CSS code.
button {
padding: 8px 16px;
border-radius: 4px;
}3Best Practices
Follow these guidelines when working with Basic Selectors:
1. Use type selectors for broad, site-wide defaults that should apply everywhere unless more specifically overridden
2. Avoid relying on type selectors for anything needing precise, individual targeting, since they match every instance of that element with no way to exclude specific ones
3. Layer more specific class or ID selectors on top of type-selector defaults, rather than trying to make type selectors themselves handle exceptions
Tip: Type selectors carry the lowest specificity of any named selector, so use them for broad, foundational defaults, like resetting margins or setting a base font, that you expect more specific class or ID selectors to override later as needed.
p {
line-height: 1.6;
color: #333;
}