We conduct a test to see if content from CSS pseudo elements will be indexed in Google
Traditionally when Google (or other search engines) look for text-based content to index – they expect to find this content directly in the HTML of the webpage that is served to them.
This changed somewhat with the rise of sites using JavaScript to serve anywhere from small pieces of content to entire websites.
Google was forced then to invest resources attempting to render and index JavaScript based content as effectively as possible.
But what about text content that is sourced purely from CSS? It is possible to add content to a page using CSS pseudo elements such as ::before and ::after combined with the CSS content property.
See a simple example below:
<p>99 bottles of beer on the wall, 99 bottles of beer.</p>
p::after {content:' Take one down and pass it around,
98 bottles of beer on the wall.'}
Will display as:
99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall.
Year after year as CSS gets more advanced and other features are introduced, such as the ability to do mathematical calculations or count elements using only CSS, the likelihood of devs and designers adopting these features becomes higher.
But will Google be able to render and index this content? Will the text found in the CSS appear and be searchable in Google?
Is using CSS for text best practice?Before we start it is important to note that in the large majority of situations using CSS pseudo elements and the ‘content’ property (instead of HTML) to display any significant amount of text based content on a website is absolutely not best practice for various reasons, including:
F87: Failure of Success Criterion 1.3.1 due to inserting non-decorative content by using :before and :after pseudo-elements and the ‘content’ property in CSS
W3.org
CSS pseudo elements should generally speaking only be used for decorative elements that are non-essential to the consumption of the content on the page.
SEO PollUntil the production of this article – I was not able to find any other SEO-focused articles on this topic, so I thought it could be interesting to dig in and so some research.
I asked the SEO community what they thought in a Twitter poll, with the following results:
Can Google index text content from CSS displayed on a web page in a pseudo element, eg :before, :after?
— Colin McDermott (@ColinMcDermott) June 30, 2021
Taking out users that just wanted to see the results, there is a fairly even split between the three choices with ‘No’ and ‘I don’t know’ getting an equal number of votes (12), and ‘Yes’ trailing behind by just a few votes (9).
TestTo test I created a page that contained zero standard HTML based content and added text content using CSS pseudo elements attached to heading, paragraph, div and link tags – sourced from an external file CSS file.
You can also view the code and resulting page on CodePen here.
To give the URL a little boost to help it get indexed more quickly (or indeed at all) I linked to it temporarily from the footer of the site.
RenderingTo test I also ran the page through the Fetch tool in Search Console and the Mobile Friendly testing tool.
Both showed that Google were able to fully render the CSS content as it appeared to normal users on the page.
ResultsEventually (slightly to my surprise) the page did get indexed in Google despite the complete lack of content.
However checking the resulting listing in Google, and after searching for strings of text from the page – it became clear that no actual content had been indexed.
So we can confirm from this test that: NO – although Google can render it, CSS based content will not currently be indexed in Google.
If you include text content on your site using CSS pseudo elements and the CSS ‘content’ property it is currently not possible for Google to index the text content.
Update (14/7/2021)
The fantastic Jess Peck alerted me to a previous test she conducted on the same subject you can view here, and another post/experiment from Mathias Bynens that doesn’t use any HTML at all.
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | What to do if your Development Site is Indexed by Google | 0 | 4.62 | 21-08-2021 |
| 2 | Ecommerce Navigation SEO Best Practice Guide with Examples | 0 | 5.62 | 20-10-2021 |
| 3 | Pourquoi Google n’indexe pas mes pages : 3 erreurs à corriger dès maintenant | 0 | 7.07 | 27-07-2026 |
| 4 | Yoast SEO Shopify App: What does it do, and is it worth the price? | 0 | 6.75 | 27-01-2022 |
| 5 | W3 Total Cache causing Mobile Friendly Test fails, blocks Google from CSS/JS | 0 | 8.67 | 05-09-2021 |
| 6 | Сколько времени нужно Гуглу, чтобы проиндексировать новый сайт? | 5 | 7 | 23-04-2024 |
| 7 | Нужно ли принудительно индексировать страницы в Google? | 0 | 5 | 13-04-2026 |
| 8 | Ящик "Пандоры". Что нужно знать о публикации офшорных файлов | 0 | 0 | 05-10-2021 |
| 9 | Google | GSC | Core Web Vitals | 0 | 5 | 06-07-2026 |
| 10 | Comment éviter que Claude n'ajoute un filigrane à votre contenu | 0 | 10 | 19-08-2026 |