Why does CSS content not appear on my pseudo-element?
Quick answer
For ::before or ::after to appear, a matching rule needs a usable content value. Missing content, normal, or none means the pseudo-element is not generated. Try a visible text value, then check that the selector matches and inspect the computed content value for a competing declaration. ::after cannot be applied to replaced elements such as <img>. [S1] [S2] [S3]
The question, the details, the next step.
A practical checklist
Confirm you are targeting
::beforeor::afteron the intended element.Temporarily set
content: "TEST"to check whether generated text appears.Verify that the selector matches the element you expect.
If the target is an
<img>, try a wrapper element instead.Inspect the computed
contentvalue and check for competing declarations.Remove temporary test content and restore the intended output.
A few more useful answers
Why does `::after` work on a wrapper but not directly on an image?
The ::after reference says it cannot be applied to replaced elements such as <img>. Targeting a wrapper is a practical way to place generated content adjacent to the image instead. [S2]
What should the computed `content` value tell me?
It can help confirm whether the intended rule wins for the pseudo-element. If another applicable declaration determines the final value, inspect the cascade and the selector that supplied it. [S3]
Sources
References used for this guide.
- [S1] MDN: CSS content property requirements and behavior developer.mozilla.org · Checked
- [S2] MDN: ::after rendering conditions and replaced elements developer.mozilla.org · Checked
- [S3] MDN: CSS property value processing and the cascade developer.mozilla.org · Checked
