CSS ::before pseudo-element
- Previous page ::backdrop
- Next Page ::file-selector-button
- Go Up One Level CSS Pseudo-element Reference Manual
Definition and usage
CSS ::before
Pseudo-elements are used to insert some content before the specified element's content.
Usage content
The attribute specifies the content to be inserted. The value of content can be:
- String: content: "Hello world!";
- Image: content: url(myimage.jpg);
- No content: content: none;
- Counter: content: counter(li);
- Quotation marks: content: open-quote;
- Attribute value: content: " (" attr(href) ")";
Tip:Note that the content inserted is still within the specified element. The inserted content will be added before the other content inside the element.
Usage ::after
Insert some content after the content of a specific element.
Example
Example 1
Insert a string before the content of each <p> element:
p::before { content: "Read this: "; }
Example 2
Insert a string before the content of each <p> element and set the style of the inserted content:
p::before { content: "Read this -"; background-color: yellow; color: red; font-weight: bold; }
CSS syntax
::before { css declarations; }
Technical details
Version: | CSS2 |
---|
Browser support
The numbers in the table specify the first browser version that fully supports this pseudo-element.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4.0 | 9.0 | 3.5 | 3.1 | 7.0 |
Related pages
Tutorial:CSS pseudo-element
Reference:CSS ::after pseudo-element
- Previous page ::backdrop
- Next Page ::file-selector-button
- Go Up One Level CSS Pseudo-element Reference Manual