# :modal

> The `:modal` CSS pseudo-class selects an element that is in a modal state and blocks interaction with the rest of the page.

## How do I style a modal dialog in CSS?

The pseudo-class that matches an element which excludes all interaction with elements outside it until it is closed. For example, a `<dialog>` opened with the `showModal()` method or an element in fullscreen mode.

- Topic: Pseudo Classes
- Type: pseudo-class
- Browser support: Chrome 105+, Chrome Android 105+, Edge 105+, Firefox 103+, Firefox Android 103+, Safari 15.6+, Safari iOS 15.6+

## Example

Wrong:

```js
const dialog = document.querySelector('dialog');
dialog.show();
```

Right:

```js
const dialog = document.querySelector('dialog');
dialog.showModal();
```

`showModal()` puts the dialog in the top layer, so `:modal` and `::backdrop` apply and the page behind becomes inert.

## Common mistakes

- Opening the dialog with `show()` or the `open` attribute, so `:modal` never matches.

## Key points

- The dialog is opened with `showModal()`, so `:modal` and `::backdrop` apply.
- Styles target `dialog:modal` instead of a class added by JavaScript.
- Selectors are scoped to `dialog` where needed, since fullscreen elements also match `:modal`.

## Interview questions

### What is the difference between :modal and :open on a dialog?

`:open` matches any open dialog. `:modal` matches only one opened with `showModal()`, which blocks the rest of the page.

### Does a fullscreen element match :modal?

Yes. An element shown with `requestFullscreen()` also matches `:modal`, so scope selectors to `dialog:modal` when needed.

## Related cards

- [`<dialog>`](https://wonderium.dev/html/dialog.md)
- [::backdrop](https://wonderium.dev/css/backdrop.md)
- [dialog](https://wonderium.dev/a11y/dialog.md)
- [:open](https://wonderium.dev/css/open.md)
- [\[inert\]](https://wonderium.dev/html/inert.md)

---

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