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
🌐
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
March 2, 2025 -

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']

Discussions

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
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
子要素にテキストを含むXPATH div要素を選択する : r/selenium
🌐 r/selenium
CSS selector for all elements with same text content
Just give them all an “.edit” class More on reddit.com
🌐 r/css
27
1
March 2, 2025
🌐
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
🌐
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
🌐
Prismic
prismic.io › blog › css-hover-effects
CSS Hover Effects: 40 Engaging Animations To Try
December 11, 2024 - When hovered, the top slide (with an icon) moves up to reveal the bottom slide containing text. This animation relies on: transform: translateY() (docs): Moves each slide along the vertical axis during hover · transition (docs): Creates a smooth animation effect when both slides’ positions change on hover ... Interactive CodePen loads when it gets near the viewport. ... The CSS hard hover effects by Bruno Rocha creates a dynamic card hover effect, where top layer shrinks on hover to reveal the inner text-filled layer.
🌐
Techgrind
techgrind.io › home › explain › is there a css selector for elements containing certain text?
Is there a CSS selector for elements containing certain text? | Techgrind.io
January 3, 2025 - 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 › Type_selectors
Type selectors - CSS | MDN
November 7, 2025 - The CSS type selector matches elements by node name. In other words, it selects all elements of the given type within a document. ... Type selectors can be namespaced when using @namespace. This is useful when dealing with documents containing multiple namespaces such as HTML with inline SVG ...
🌐
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 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Selectors › Selectors_and_combinators
CSS selectors and combinators - CSS | MDN
For example, the :target simple selector targets element of a URL containing a fragment identifier, and the a:visited compound selector matches all <a> elements that have been visited by a user. The pseudo-classes can be categorized as element display state, input, linguistic, location, resource state, time-dimensional, tree-structural, user action, and functional. Multiple pseudo-classes can be combined to create compound selectors.
🌐
Chrome Web Store
chromewebstore.google.com › detail › lightning-autofill › nlmmgnhgdeffjkdckmikfpnddkbbfkkk
Lightning Autofill - Chrome Web Store
🔤 Text expansion: Expand shortcodes directly or through autocomplete. 📋 Text clips: Insert boilerplate text snippets from the context menu. 🎲 Variables: Generate dynamic content, random data, and more. 🎯 Smart targeting: Find fields using simple text, regular expressions, CSS selectors, or XPaths.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › :has
:has() - CSS | MDN
... body:has(video, audio) { /* styles to apply if the content contains audio OR video */ } body:has(video):has(audio) { /* styles to apply if the content contains both audio AND video */ } Interestingly, we can relate some CSS :has() constructs with the lookahead assertion in regular expressions ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › Attribute_selectors
Attribute selectors - CSS | MDN
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 ...
🌐
Playwright
playwright.dev › assertions
Assertions | Playwright
Playwright will be re-testing the element with the test id of status until the fetched element has the "Submitted" text. It will re-fetch the element and check it over and over, until the condition is met or until the timeout is reached.
🌐
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.
🌐
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.