Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.6 — Pseudo-elements
CSS · Example 3 of 3

Labels from attributes with attr()

The computed content is the attribute's value as a string: attr() is resolved separately for each element.

Pseudo-elements start with two colons and style a part of an element that has no tag of its own: generated boxes before or after its content, its first letter or line, the placeholder, the selected text or a list marker.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Add a grey / separator between breadcrumb links in <nav class="crumbs"><a>Home</a><a>CSS</a><a>Selectors</a></nav>, but not after the last one.

02

Make the first letter of every .lead paragraph twice the size and dark red.

03

Show the URL of every link in printed-style text after it, using attr().

Explain it without notes

01

What is the difference between a pseudo-class and a pseudo-element? Give two of each.

02

Why does ::before sometimes not appear at all? List the common causes.

03

Is generated content accessible? What should and shouldn't go in content?

04

What is the specificity of p::first-line compared with p:first-child?

Labels from attributes with attr()

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

"2 MB"