Favorites

DOM Element.matches() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element.matches()
DOM Element MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The matches() method checks whether an element would be selected by a given CSS selector.

Description

The matches() method tests whether the element would be selected by the given CSS selectors. It's useful in event handlers and filters, for example checking whether an element is :checked, has a class or matches a media-dependent state like :hover.

It accepts the same selectors as querySelector(), including complex ones such as 'nav a:not(.active)', and throws a SyntaxError for invalid selectors. Unlike closest(), it only checks the element itself.

A common use is filtering event targets in delegated listeners, such as if (e.target.matches('.delete')) ..., and checking pseudo-classes that reflect state, such as :focus-visible, :invalid or :popover-open.

Syntax

element.matches(selectors)

Parameters

  • selectorsA string of one or more CSS selectors.

Return Value

true if the element matches the selectors, otherwise false.

Example

<input type="checkbox" id="agree"> <label for="agree">I agree</label>
const input = document.getElementById('agree');
console.log(input.matches('input[type=checkbox]'));
console.log(input.matches(':checked'));
input.checked = true;
console.log(input.matches(':checked'));

Browser Support

The following information will show you the current browser support for the Element.matches() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee