Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::after — generated content after an element's content

The ::after pseudo-element creates styleable content after an element's actual content, but inside the element. The content property specifies that content. The :after spelling is equivalent legacy syntax retained for compatibility.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

selector::after { content: "…"; }
/* Legacy equivalent: selector:after { content: "…"; } */

::after represents a pseudo-element immediately after its originating element's actual content. For layout, it behaves like the last child, not like a sibling following the element. It does not add a real element to the document tree.

The content property specifies the generated content. The values normal and none do not generate this pseudo-element; content: "" allows an empty box for decoration. The box is inline by default; you can change its display and apply properties such as color. On replaced elements, such as images, ::after is suppressed.

:after denotes the same pseudo-element, not a pseudo-class. Browsers must accept this legacy spelling for CSS 2 compatibility; use ::after in new code. In the example, content: " *" appends a space and an asterisk after Example, and color makes the asterisk purple.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>::after example</title>
<style>
  .label::after {
    content: " *";
    color: purple;
  }
</style>
<p class="label">Example</p>
</html>

Result

Example *

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources