Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

::after

Creates a virtual last child of the element — for icons, marks and decorations after the content.

Syntax

selector::after { content: "…"; }

Examples

An arrow after external links:

<style>
  a[href^="https"]::after { content: " ↗"; }
</style>
 
<p><a href="https://example.com">An external link</a></p>

A short decorative bar under a heading:

<style>
  .title { position: relative; padding-bottom: 8px; }
  .title::after {
    content: "";
    position: absolute; left: 0; bottom: 0;
    width: 40px; height: 3px;
    background: crimson;
  }
</style>
 
<h3 class="title">Underlined with a short bar</h3>

Notes

Like ::before, it needs the content property. An absolutely positioned pseudo-element is placed relative to the nearest positioned ancestor, so give the element itself position: relative.

See also

  • ::before — Creates a virtual first child of the element — for decorative text or shapes.
  • content — The content of the `::before` and `::after` pseudo-elements.
  • position — How an element is positioned: in the normal flow or by offsets.

Related recipes

In the tutorial

  • Pseudo-elements — How to style part of an element or add decorative content — before, after, first-letter, marker, placeholder and selection.

Thanks for reading!

Donate to the site — we work hard for you.