CSS: “:before”, “:after”

By Xah Lee. Date: . Last updated: .

CSS :before and :after lets you add text or image into HTML content.

For example, a example use is for Question and Answers:

How to do this?

This way.

The “Q:” and “A:” are actually not in HTML. They are added using CSS. If you turn off CSS in your browser, they'll disappear.

Here's the CSS code:

p.x3465:before {
    content:"Q: ";

Here's the HTML code:

<p class="x3465">How to do this?</p>
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.