content
Inserts generated content in the ::before and ::after pseudo-elements.
- Initial value
normal- Inherited
- No
- Animatable
- no
- Applies to
- ::before and ::after pseudo-elements (partly also ordinary elements)
- JavaScript
getComputedStyle(element, "::before").content
Example
#.external::after {
content: " ↗";
font-size: 0.8em;
}
.required label::after {
content: " *";
color: #f43f5e;
}<style>.ext::after { content: " ↗"; font-size: .8em; } .req::after { content: " *"; color: #f43f5e; }</style>
<p style="margin: 0 0 8px;"><a class="ext" href="#" style="color: #c4b5fd;">MDN documentation</a></p>
<label class="req">Email address</label>Definition and usage
#The content property specifies what appears in the ::before and ::after pseudo-elements. Without it, these pseudo-elements aren’t created at all, so even decorations without text require content: "".
The value can be a string, an element attribute value (attr(data-label)), a counter (counter()), a quotation mark (open-quote), or an image (url()).
Content from content is for ornaments, icons, and helper labels. Screen readers may read it, but it can’t be selected or copied, so don’t put important information there.
Syntax
#content: normal | none | "<string>" | attr(<attribute>) | counter(…) | open-quote | close-quote | url(…) [ / "<alt text>" ]?;Values
#string
A fixed string before the content.- The value of the element’s
data-labelattribute. - An opening quotation mark, depending on the page language.
empty string
An empty pseudo-element, e.g. as a coloured bar.
Values in practice
#"★ "
.demo::before { content: "★ "; }attr(data-label)
data-label attribute..demo::before { content: attr(data-label); }open-quote
.demo::before { content: open-quote; }
.demo::after { content: close-quote; }""
.demo::before { content: ""; display: inline-block; width: 24px; height: 4px; vertical-align: middle; background: #a78bfa; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Remember
content: ""on every decorative pseudo-element, otherwise you won’t see it on the page. - Don’t insert content via
contentwithout which the page is incomprehensible. Such text can’t be copied.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.