CSS :before selector
Complete CSS Selector Reference Manual
Example
Each
Insert content before an element:
p:before
{
content:"Read this: ";
}
Try it »
Definition and description
:before selector inserts content before the selected element.
Usecontent property to specify the content to be inserted.
Browser support
The numbers in the table indicate the first browser version that supports this property.
| Selector | |||||
|---|---|---|---|---|---|
| ::before | 4.0 | 9.0 | |||
| Partially supported from 8.0 | 3.5 | 3.1 | 7.0 | ||
| Partially supported from 4.0 |
Note: before must have a DOCTYPE declared to work in IE8 .
Related Articles
CSS Tutorial: CSS Pseudo-elements
CSS selector reference manual: CSS :after selector
More examples
Example
Insert content after each
Content and style inserted before:
p:before
{
content:"Read this -";
background-color:yellow;
color:red;
font-weight:bold;
}
Try it »
Complete CSS Selector Reference Manual