Function window.matchMedia()
The Window interface’s matchMedia()
method returns
a new MediaQueryList
object that can then be used
to determine if the document matches the media
query string.
let mql = window.matchMedia("(max-width: 600px)");
window.matchMedia('(prefers-color-scheme: dark)');
Return value:
A new MediaQueryList
object for the media query.
Use this object’s properties and events to detect
matches and to monitor for changes to those
matches over time.
MediaQueryList properties:
- matches Read only A boolean value that returns true if the document currently matches the media query list, or false if not.
- media Read only A string representing a serialized media query.