Before and after selector in css

Photo by Andrew Neel on Unsplash

Before and after selector in css

Definition and Usage

The ::after selector inserts something after the content of each selected element(s).

Use the content property to specify the content to insert.

Use the ::before selector to insert something before the content.

Example

Insert content after every <p> element, and style the inserted content:

p::after {

content: " - Remember this";

background-color: yellow;

color: red;

font-weight: bold;

}

Example

Insert content before every <p> element's content, and style the inserted content:

p::before {

content: "Read this -";

background-color: yellow;

color: red;

font-weight: bold;

}