# :required

> The `:required` CSS pseudo-class applies to form elements that have the `required` attribute set.

## How do I style required form fields with CSS?

The pseudo-class that selects form elements with the `required` attribute. It applies to fields that must be filled out before a form can be submitted, enabling specific styling to indicate the importance of these fields to the user.

- Topic: Pseudo Classes
- Type: pseudo-class
- Browser support: Chrome 10+, Chrome Android 18+, Edge 12+, Firefox 4+, Firefox Android 4+, Safari 5+, Safari iOS 5+

## Example

Wrong:

```css
input:required::after {
  content: ' *';
  color: red;
}
```

Right:

```css
label:has(+ input:required)::after {
  content: ' *';
  color: #c00;
}
```

Inputs can't have `::after` content, so the asterisk goes on the label next to the required field.

## Common mistakes

- Adding an asterisk with `::after` on the input, where it never shows.
- Marking fields required only visually, so the browser and screen readers don't know.

## Key points

- Required fields have the `required` attribute, not only a CSS asterisk or class.
- The required state is also visible in the label text, not just from color or `::after` content.
- Code does not expect `:required` to match custom controls without the `required` attribute.

## Interview questions

### Which elements can match :required?

`input`, `select` and `textarea` with the `required` attribute.

### Do I still need aria-required if I use required?

No. The native `required` attribute is already announced, so `aria-required` is only for custom controls.

## Related cards

- [:optional](https://wonderium.dev/css/optional.md)
- [:invalid](https://wonderium.dev/css/invalid.md)
- [\[aria-required\]](https://wonderium.dev/a11y/aria-required.md)
- [`<input>`](https://wonderium.dev/html/input.md)
- [Accessible Forms](https://wonderium.dev/a11y/accessible-forms.md)

---

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