The element.class selector combines a tag name with a class name for precise targeting. Use it when the same class appears on different HTML elements but needs different styles.
01
Tag + class
No space.
02
p.intro
Paragraphs only.
03
Specificity
Beats .class.
04
div.card
Not span.card.
05
Reuse class
Same name.
06
Precision
Fewer conflicts.
Fundamentals
Introduction
The CSS element.class selector lets you apply styles to specific HTML elements that possess a particular class attribute. It combines a type selector (the element name) with a class selector for greater precision than .class alone.
This pattern is a powerful way to target elements with greater control, making your web design more flexible while keeping class names reusable across different tags.
Definition and Usage
Write the HTML tag immediately followed by a dot and the class name — with no space between them. For example, p.highlight matches only <p class="highlight">, not a <div class="highlight">.
💡
Beginner Tip
Do not confuse p.highlight (no space — one element with both tag and class) with p .highlight (with space — a .highlight element nested inside a <p>).
Foundation
📝 Syntax
The syntax for the element.class selector is:
syntax.css
element.class{/* CSS properties */}
Replace element with the HTML tag and class with the class name. The selector applies only to instances of that element that have the specified class.
.btn sets shared sizing and typography. button.btn and a.btn add element-specific colors so actions and navigation links look distinct but feel cohesive.
Example 4 — li.nav-item navigation
Target only list items with the nav-item class inside a navigation menu.
li.nav-item removes bullets only from navigation list items, leaving other <li> elements elsewhere on the page unaffected.
Tips
💬 Usage Tips
Use meaningful class names — Names like intro, card, and nav-item make CSS easier to read.
Combine with other selectors — Chain with ids or attribute selectors for even more precision when needed.
Start with .class — Add the element prefix only when you need tag-specific overrides.
Keep HTML semantic — Use the correct tag; do not rely on CSS alone to change element meaning.
Document shared classes — When one class name spans multiple tags, note which element.class rules apply where.
Watch Out
⚠️ Common Pitfalls
Typos in class names — Class names are case-sensitive; p.Intro will not match class="intro".
Accidental space — p .highlight is a descendant selector, not element.class.
Wrong tag — div.highlight will not style <p class="highlight">.
Over-specificity — Adding element prefixes everywhere makes CSS harder to override later.
Multiple classes — Ensure chained selectors like p.intro.featured match elements that have all listed classes.
A11y
♿ Accessibility
Use semantic HTML — Choose the correct element (button for actions, a for links) rather than styling the wrong tag.
Color contrast — Ensure text styled with element.class meets WCAG contrast requirements.
Do not hide content — Avoid using selectors to visually remove important information from sighted users.
Focus states — Add :focus-visible styles for interactive elements like a.btn.
Meaningful structure — Use headings (h1.title) in proper order for screen reader navigation.
🧠 How element.class Works
1
Browser finds elements
The engine scans the DOM for elements matching the tag name, such as all <p> elements.
DOM
2
Filter by class
Only elements whose class attribute includes the specified class name remain.
Filter
3
Apply CSS rules
Matching elements receive the declared properties from the element.class rule.
Style
=
🎨
Precise styling
Only the intended tag + class combinations are styled, reducing unintended side effects.
Compatibility
🖥 Browser Compatibility
The element.class compound selector is supported in all modern browsers and has been available since CSS1.
✓ Baseline · Universal support
Compound selectors everywhere
element.class works reliably in Chrome, Firefox, Safari, Edge, and Opera.
99%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
element.class compound selector99% supported
Bottom line:element.class is safe for all projects that combine tag names with class attributes.
Wrap Up
🎉 Conclusion
The CSS element.class selector is a fundamental tool that empowers you to style elements precisely and effectively. By combining a tag name with a class name, you gain higher specificity and tighter control over which elements receive your styles.
Use it when the same class name appears on different HTML elements but needs different visual treatments — keeping your code organized, reusable, and maintainable.
Use these points when combining tag names with classes.
5
Core concepts
p.intro01
No space
Tag + class.
Syntax
0,1,102
Specificity
Beats .class.
Cascade
div03
Tag filter
One element.
Precision
card04
Reuse
Same class.
Pattern
🌐05
99% support
All browsers.
Compat
❓ Frequently Asked Questions
The element.class selector combines an HTML tag name with a class name — such as p.intro or div.card — to style only elements of that tag that also have the specified class.
.card matches any element with class="card". div.card is more specific — it only matches div elements that have that class, ignoring spans or articles with the same class name.
No. element.class is written with no space (p.highlight). A space would mean a descendant selector: p .highlight matches a .highlight element inside a p.
Yes. div.card (0,1,1) beats .card (0,1,0) because the element type adds one point to the type column in the specificity calculation.
Yes. Combining type and class selectors has been supported in every browser since CSS1 and works reliably in all modern projects.