::before - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:before

Description

The ::before selector selects content before the content of each selected element.

To set the content use the content property.

You can use the ::after selector to insert content after the original content inside an element.

Example

Insert content before every <p> element's content

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
p::before {<!--from  ww  w.j a  v  a2 s . c o m-->
    content: "news:";
    background-color: red;
    color: red;
    font-weight: bold;
}
</style>
</head>
<body>

<p>this is a test</p>
<p>this is another test</p>

</body>
</html>

Related Tutorials