One Byte Explainer: matchMedia

Rmag Breaking News

This is a submission for DEV Challenge v24.03.20, One Byte Explainer: Browser API or Feature.

Explainer

matchMedia, which exists on the window, is a method that facilitates checking CSS media queries in JavaScript. You can even use event listeners, with the change event, to detect media changes which can be super useful and, more importantly, cheap!

Additional Context

matchMedia is just so useful for those rare instances where media queries in CSS aren’t enough and it’s so much lighter than manually getting the size of the page and rechecking on every resize 😅.

Leave a Reply

Your email address will not be published. Required fields are marked *