# ::before

> The `::before` CSS pseudo-element inserts content before the element's actual content, specified using the `content` property.

## How do I add an icon before text with ::before in CSS?

The pseudo-element used to insert content before the content of an element. It can be used to add decorative elements, such as icons or special symbols without changing the HTML structure.

- Topic: Pseudo Elements
- Type: pseudo-element
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1.5+, Firefox Android 4+, Safari 4+, Safari iOS 3+

## Example

Wrong:

```css
.external::before {
  width: 1em;
  height: 1em;
  background: url(icon.svg);
}
```

Right:

```css
.external::before {
  content: '';
  display: inline-block;
  width: 1em;
  height: 1em;
  background: url(icon.svg);
}
```

Without `content` the pseudo-element isn't created, and as an inline box it ignores `width` and `height`.

## Common mistakes

- Nothing shows because the `content` property is missing.
- Adding `::before` to an `<img>` or `<input>`, where it doesn't render.
- Setting `width` and `height` on an inline `::before`, which ignores them.

## Key points

- Every `::before` rule sets `content`, at least `content: ''`, or nothing renders.
- Essential text isn't placed in `content`, since generated text can't be selected or copied.
- Pseudo-elements are used on elements that can have children, not on `<img>` or `<input>`.

## Interview questions

### Why is my ::before not showing?

Usually `content` is missing. Also check that the element can hold children, since `<img>`, `<input>` and other replaced elements don't render `::before`.

### Do screen readers read ::before content?

Often yes. Screen readers usually announce text from `content`, so decorative symbols can add noise.

### What is the difference between :before and ::before?

None in behavior. The double colon is the current pseudo-element syntax; the single colon still works for compatibility.

## Related cards

- [::after](https://wonderium.dev/css/after.md)
- [content](https://wonderium.dev/css/content.md)
- [Pseudo-element](https://wonderium.dev/css/pseudo-element.md)
- [attr()](https://wonderium.dev/css/attr.md)
- [counter()](https://wonderium.dev/css/counter.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/before
- Last updated: 2026-11-25
