CSS ::after Pseudo Element

The ::after pseudo-element is a generated content element that adds any kind of content after the content.

The value is defined by the content property.

By default, the ::after pseudo-element is inline.

The ::after pseudo-element can be used to insert any kind of content, including characters, strings of text, and images.

It can be animated, positioned or floated like any other content.

The ::after pseudo-element can also be used with one colon notation :after which is supported by all the browsers as well.

Version

CSS2

Syntax

::after {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p::after { 
      content: " - William Shakespeare.";
      }
    </style>
  </head>
  <body>
    <h2>::after selector example</h2>
    <p>"Be or not to be"</p>
  </body>
</html>

In the given example, styles can be added to the content:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p::after { 
      content: " - William Shakespeare.";
      background-color: #eee;
      color: #1c87c9;
      padding:5px 3px;
      border: 2px dashed #000;
      margin-left:5px;
      }
    </style>
  </head>
  <body>
    <h2>::after selector example</h2>
    <p>"Be or not to be"</p>
  </body>
</html>

Browser support

4.0+ 12.0+ 2.0+ 3.1+ 10.0+

Practice Your Knowledge

Which statement is wrong about ::after pseudo element




Related articles