CSS chapters

Chapter 11 of 17

Generated content and pseudo-elements

Try this in our CSS Compiler →

The idea

The content property can create text in ::before or ::after. Use it for decoration rather than essential instructions, since accessibility support and text selection vary. Important words belong in HTML. A pseudo-element needs content to generate its box.

Worked example

h1::after { content: " ★"; color: teal; }

What to check

The star is decorative. A form label, error message or primary instruction should not depend on this CSS-generated text.

Practice task

Add a decorative separator with a pseudo-element, then disable the stylesheet and check that no essential information disappears.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on