Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. [CSS Selector] E:after

[CSS Selector] E:after

Using 'selector:after', you can generate the last child element of an element. This is commonly called the ':after pseudo-element'. It does not work in IE7 or earlier.

When generating a ':after pseudo-element', the 'content' property is required. Without a 'content' property, the ':after pseudo-element' will not be generated. If you want to generate a ':after pseudo-element' without any text content, pass an empty string to the 'content' property.

Sample Code

div:after { content: "Hello World";} /* Generates a ':after pseudo-element' containing the text "Hello World". */
p:after {} /* No 'content' property is specified, so the ':after pseudo-element' is not generated. */
div.div1:after { content: ""; display: block; height: 10px; background-color: red;} /* To output no text, pass an empty string like this. */

Browser Result

div:after { content: "Hello World";} /* Generates a ':after pseudo-element' containing the text "Hello World". */
p:after {} /* No 'content' property is specified, so the ':after pseudo-element' is not generated. */
div.div1:after { content: ""; display: block; height: 10px; background-color: red;} /* To output no text, pass an empty string like this. */

<div> The ':after pseudo-element' is being generated.</div>
<p>The ':after pseudo-element' is not generated because the 'content' property is not specified.</p>
<div class="div1">A red line is being generated using the ':after pseudo-element'.</div>

The default 'display' property value of the ':after pseudo-element' is 'inline'.

Note that the ':after pseudo-element' is generated not after the specified element, but at the position of the last child element inside the specified element.

<p>

<!-- The ':after pseudo-element' is generated around here. -->
</p>
<!-- Not here -->

Browser Support

Chrome Chrome
1+
Firefox Firefox
1.5+
Safari Safari
4+
3 and earlier ×
Edge Edge
12+
Supported in all versions.
IE IE
11
10
9
8
7 ×
6 ×
Opera Opera
7+
6
5
4
Supported as ':after'
3 and earlier ×
iOS Safari iOS Safari
3.2+
2 and earlier ×
Android Android Browser
4.4+
3 and earlier ×
Chrome Android Chrome Android
Latest
Same support as desktop version.
Firefox Android Firefox Android
Latest
Same support as desktop version.

* Version information is based on MDN.

If you find any errors or copyright issues, please .