---
title: '::after (:after)'
slug: Web/CSS/::after
tags:
  - CSS
  - Layout
  - Pseudo-element
  - Reference
  - Selector
  - Web
browser-compat: css.selectors.after
---
{{CSSRef}}

In CSS, **`::after`** creates a [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) that is the last child of the selected element. It is often used to add cosmetic content to an element with the {{CSSxRef("content")}} property. It is inline by default.

```css
/* Add an arrow after links */
a::after {
  content: "→";
}
```

> **Note:** The pseudo-elements generated by `::before` and `::after` are [contained by the element's formatting box](https://www.w3.org/TR/CSS2/generate.html#before-after-content), and thus don't apply to _[replaced elements](/en-US/docs/Web/CSS/Replaced_element)_ such as {{HTMLElement("img")}}, or to {{HTMLElement("br")}} elements.

## Syntax

{{CSSSyntax}}

> **Note:** CSS3 introduced the `::after` notation (with two colons) to distinguish [pseudo-classes](/en-US/docs/Web/CSS/Pseudo-classes) from [pseudo-elements](/en-US/docs/Web/CSS/Pseudo-elements). Browsers also accept `:after`, introduced in CSS2.

## Examples

### Simple usage

Let's create two classes: one for boring paragraphs and one for exciting ones. We can use these classes to add pseudo-elements to the end of paragraphs.

#### HTML

```html
<p class="boring-text">Here is some plain old boring text.</p>
<p>Here is some normal text that is neither boring nor exciting.</p>
<p class="exciting-text">Contributing to MDN is easy and fun.</p>
```

#### CSS

```css
.exciting-text::after {
  content: " <- EXCITING!";
  color: green;
}

.boring-text::after {
  content: " <- BORING";
  color: red;
}
```

#### Result

{{EmbedLiveSample('Simple_usage', 500, 150)}}

### Decorative example

We can style text or images in the {{CSSxRef("content")}} property almost any way we want.

#### HTML

```html
<span class="ribbon">Look at the orange box after this text. </span>
```

#### CSS

```css
.ribbon {
  background-color: #5BC8F7;
}

.ribbon::after {
  content: "This is a fancy orange box.";
  background-color: #FFBA10;
  border-color: black;
  border-style: dotted;
}
```

#### Result

{{EmbedLiveSample('Decorative_example', 450, 20)}}

### Tooltips

This example uses `::after`, in conjunction with the [`attr()`](</en-US/docs/Web/CSS/attr()>) CSS expression and a `data-descr` [custom data attribute](/en-US/docs/Web/HTML/Global_attributes/data-*), to create tooltips. No JavaScript is required!

We can also support keyboard users with this technique, by adding a `tabindex` of `0` to make each `span` keyboard focusable, and using a CSS `:focus` selector. This shows how flexible `::before` and `::after` can be, though for the most accessible experience a semantic disclosure widget created in some other way (such as with [details and summary](/en-US/docs/Web/HTML/Element/details) elements) is likely to be more appropriate.

#### HTML

```html
<p>Here we have some
  <span tabindex="0" data-descr="collection of words and punctuation">text</span> with a few
  <span tabindex="0" data-descr="small popups that appear when hovering">tooltips</span>.
</p>
```

#### CSS

```css
span[data-descr] {
  position: relative;
  text-decoration: underline;
  color: #00F;
  cursor: help;
}

span[data-descr]:hover::after,
span[data-descr]:focus::after {
  content: attr(data-descr);
  position: absolute;
  left: 0;
  top: 24px;
  min-width: 200px;
  border: 1px #aaaaaa solid;
  border-radius: 10px;
  background-color: #ffffcc;
  padding: 12px;
  color: #000000;
  font-size: 14px;
  z-index: 1;
}
```

#### Result

{{EmbedLiveSample('Tooltips', 450, 120)}}

## Accessibility concerns

Using an `::after` pseudo-element to add content is discouraged, as it is not reliably accessible to screen readers.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{CSSxRef("::before")}}
- {{CSSxRef("content")}}
