If I read the specification correctly, no.
You can match on an element, the name of an attribute in the element, and the value of a named attribute in an element. I don't see anything for matching content within an element, though.
Answer from Dean J on Stack OverflowW3Schools
w3schools.com › css › css_selectors.asp
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Styling_basics › Basic_selectors
Basic CSS selectors - Learn web development | MDN
A type selector is sometimes called a tag name selector or element selector because it selects an HTML tag/element in your document. In the example below, we have used the span, em and strong selectors. Try editing the following example (click "Play" to open it in the MDN Playground) to add ...
Videos
20:34
CSS Selectors Tutorial for Beginners - YouTube
18:47
CSS Selectors - beyond the very basics - YouTube
05:20
Learn CSS Selectors In 5 Minutes - YouTube
19:38
Learn Every CSS Selector In 20 Minutes - YouTube
11:31
CSS Combinators you need to know (and a selector too) - YouTube
14. How to Use CSS Selectors | Building Web Applications 🌐 - ...
GeeksforGeeks
geeksforgeeks.org › css › css-selectors
CSS Selectors - GeeksforGeeks
Basic selectors in CSS are simple ... all elements on the page and applies the same style universally. Example: Setting the font color for every element....
Published 1 week ago
Programiz
programiz.com › css › selectors
CSS Selectors (With Examples)
Here, the code applies CSS styling to all <h1> and <p> elements. Notice that we have used , to separate the HTML elements.. The attribute selector selects elements based on specific attribute values.
W3Schools
w3schools.com › cssref › css_selectors.php
CSS Selectors Reference
The attribute selector selects HTML elements with a given attribute set. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Selectors
CSS selectors - CSS | MDN
January 7, 2026 - The CSS selectors module defines the patterns to select elements to which a set of CSS rules are then applied along with their specificity. The CSS selectors module provides us with more than 60 selectors and five combinators. Other modules provide additional pseudo-class selectors and ...
Top answer 1 of 16
640
If I read the specification correctly, no.
You can match on an element, the name of an attribute in the element, and the value of a named attribute in an element. I don't see anything for matching content within an element, though.
2 of 16
301
Looks like they were thinking about it for the CSS3 spec but it didn't make the cut.
:contains() CSS3 selector http://www.w3.org/TR/css3-selectors/#content-selectors
SitePoint
sitepoint.com › blog › css › css selectors cheat sheet
CSS Selectors Cheat Sheet — SitePoint
November 13, 2024 - In this example, the selector will match all elements that have a class of box and that are immediate children of the #container element. That means, unlike the descendant combinator, there can’t be another element wrapping .box—it has to be a direct child element. ... In this example, the CSS from the previous code example will apply only to the first <div> element that has a class of box.
TutorialsPoint
tutorialspoint.com › css › css_selectors.htm
CSS - Selectors
The syntax for the pseudo-class selector is as follows: a :hover { background-color: peachpuff; color: green; font-size: 2em; } The following example demonstrates the use of a pseudo-class selector.
Shay Howe
learn.shayhowe.com › advanced-html-css › complex-selectors
Complex Selectors - Learn to Code Advanced HTML & CSS
Selectors are one of the most important parts of CSS, and this lessons discusses selectors, old and new, and how to best put them to use inside a website.
Codecademy
codecademy.com › learn › fscp-web-development-fundamentals › modules › fecp-learn-css-selectors-and-visual-rules › cheatsheet
Web Development Fundamentals: Learn CSS: Selectors and Visual Rules Cheatsheet | Codecademy
In this example, only color: blue will be implemented as it has an ID selector whereas color: red has a type selector. ... The CSS ID selector matches elements based on the contents ...
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › Universal_selectors
Universal selectors - CSS | MDN
November 17, 2025 - Note: The universal selector (*) matches elements only. It does not directly match pseudo-elements by itself. To match all ::before pseudo-elements on a page, for example, you would have to use a selector like *::before.
W3C
w3.org › TR › selectors-4
Selectors Level 4
January 22, 2026 - For example, the :lang() selector depends on the document language (e.g. HTML) to define how an element is associated with a language. As a slightly different example, the ::first-line pseudo-element depends on the host language (e.g. CSS) to define what a ::first-line pseudo-element represents ...
Simmons University
web.simmons.edu › ~grabiner › comm244 › weekfour › selectors.html
CSS Selectors
To match a specific class attribute, we always start the selector with a period, to signify that we are looking for a class value. The period is followed by the ... For example, if we wanted all elements with a class of "highlight" to have a different background color, we would use the following CSS rule:
Acquia
docs.acquia.com › web-governance › pageassist-setup-css-selectors
PageAssist setup with CSS selectors
The selector below will select the 2nd p element in this example: ... Takes the parent element of the selected element. We have created a series of custom CSS selectors that do NOT exist in normal CSS and only in the PageAssist system.
Testmuai
testmuai.com › testmu ai › learning hub › css selectors in selenium
CSS Selectors in Selenium: A Complete Guide to Locating Web Elements
February 3, 2026 - Select the Target Element: Click the Select Element icon in the top-left corner of the Developer Tools window. Then, click on the web element you want to inspect, for example, the “Enter Message” field in the Simple Form Demo. Copy the CSS Selector: Right-click on the highlighted HTML element in the DOM and select: Copy > Copy selector.