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 Overflow
🌐
ScrapingBee
scrapingbee.com › webscraping-questions › css_selectors › how-to-select-html-elements-by-text-using-css-selectors
How to select HTML elements by text using CSS Selectors? | ScrapingBee
There used to be a way to select HTML elements by text using CSS Selectors by making use of :contains(text). However, this has been deprecated for a long time and is no longer supported by the W3C standard. If you want to select an element by ...
Discussions

selenium - A way to match on text using CSS locators - Software Quality Assurance & Testing Stack Exchange
1 CSS Selector using ':contains' fails with `invalid element state: Failed to execute 'querySelector' on 'Document: is not a valid selector'` 12 Is jQuery faster than CSS/Xpath selectors for IE 8.0 in Selenium1? 5 Selenium - Find exact text match using CSS locators More on sqa.stackexchange.com
🌐 sqa.stackexchange.com
CSS selector for all elements with same text content
Just give them all an “.edit” class More on reddit.com
🌐 r/css
27
1
November 1, 2024
CSS attribute selector to find any word/text in a page and apply CSS.
Unfortunately there's no CSS selector for text content, as CSS can only select the elements on a page, not the text nodes on a page. The clue, in this instance, is in the name - it's an attribute selector - it only selects things via attributes, and text nodes don't have any! To do what you're after will require some javascript to wrap your target nodes in a HTML tag that can then be selected through your CSS; if it's part of a search feature then I would recommend the element . More on reddit.com
🌐 r/css
11
13
March 15, 2023
CSS selector (id contains part of text) - Stack Overflow
I have a question. I have elements something like this: element with id = someGenerated Some:Same:0:name element with id = someGenerated Some:Same:0:surname element... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › css › is-there-any-selector-for-elements-containing-certain-text-in-css
Is there any selector for elements containing certain text in CSS ? - GeeksforGeeks
July 23, 2025 - Example 2: In this example the CSS [attribute~=value] selector is used to target elements with a specific attribute containing a word, such as title~=gfg1, which colors GFG2 red.
🌐
Siteimprove
help.siteimprove.com › support › solutions › articles › 80001043350-non-standard-css-selectors-that-can-be-used-in-policy
Non-standard CSS selectors that can be used in Policy
October 18, 2022 - If you don’t want to specify which element(s) to match, you can leave out the element and search for just :contains("text"). That matches the element(s) that contains the string “text” and every ancestor element all the way up to body, which can make it almost useless. This selector is the same as :contains("text") above, but it’s case-insensitive.
Find elsewhere
🌐
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
🌐
TutorialsPoint
tutorialspoint.com › article › is-there-any-selector-for-elements-containing-certain-text-in-css
Is there any selector for elements containing certain text in CSS?
October 1, 2024 - To select elements containing certain text in CSS, we can use CSS attribute selectors. We can either use pre-defined attribute or we can add custom attribute in the HTML document.
🌐
Reddit
reddit.com › r/css › css selector for all elements with same text content
r/css on Reddit: CSS selector for all elements with same text content
November 1, 2024 -

I have buttons on a page with the same text content "Edit".

What CSS selector to use to style them all?

Here is an example...

<button onclick="o('10178','e')">Edit</button>
<button onclick="o('6915','e')">Edit</button>
<button onclick="o('2800','e')">Edit</button>

I tried this, but it didn't work...

button[text()='Edit']

🌐
Techgrind
techgrind.io › explain › is-there-a-css-selector-for-elements-containing-certain-text
Is there a CSS selector for elements containing certain text?
No built-in CSS feature exists for selecting or styling elements purely by their text content. :contains() is a jQuery (or similar library) extension, not a CSS selector.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › Attribute_selectors
Attribute selectors - CSS - MDN Web Docs
The CSS attribute selector matches elements based on the element having a given attribute explicitly set, with options for defining an attribute value or substring value match. ... /* <a> elements with a title attribute */ a[title] { color: purple; } /* <a> elements with an href matching ...
🌐
Google Groups
groups.google.com › g › selenium-users › c › SEMa-ytXgYs
Text in CSS selector
One can use Javascript to do that search (querySelectorAll + text) Protractor has cssContainingText.js for long time .
🌐
W3Schools
w3schools.com › css › css_attribute_selectors.asp
CSS Attribute Selectors
The [attribute~="value"] selector is used to select elements with an attribute value containing a specific word.
🌐
Playwright
playwright.dev › other locators
Other locators | Playwright
For example, css=article >> text=Hello captures the element with the text Hello, and *css=article >> text=Hello (note the *) captures the article element that contains some element with the text Hello.
🌐
Repeato
repeato.app › home › using css selectors to locate elements by exact text
Using CSS Selectors to Locate Elements by Exact Text - Repeato
July 16, 2024 - This script locates elements containing the specified text by first selecting the parent and then searching for the child element. For those using Selenium, the By.LINK_TEXT locator is a practical alternative to CSS selectors for finding elements by their exact text:
🌐
Packtpub
subscription.packtpub.com › book › programming › 9781849515740 › 1 › ch01lvl1sec16 › locating-elements-using-text
Locating Elements | Selenium Testing Tools Cookbook
June 16, 2025 - CSS selectors provide the contains() pseudo-class which can be used to see if an element contains the specified text.
🌐
BrowserStack
browserstack.com › home › guide › mastering selenium css selectors in 2026
CSS Selector in Selenium: Locate Elements with Examples | BrowserStack
December 10, 2025 - Matching a substring (contains: *): Locate the web element by matching the substring. ... The complete String here is “Navbar_logo__26S5Y” therefore only a substring of the String i.e: “logo_ ” is considered to locate the element. ... Mastering these CSS selector types helps you target elements more reliably, but real applications often behave differently across browsers and devices.