Skip to main content
The MediaQuery class creates a reactive media query that automatically updates when the viewport matches or stops matching the query.

Import

Usage

Responsive design

Multiple breakpoints

Conditional features

Properties

matches
boolean
Whether the media query currently matches. This property is reactive.
media
string
The media query string used to create this instance

Constructor

query
string
required
A media query string (e.g., ‘(min-width: 768px)‘)

Notes

  • Automatically adds and removes event listeners
  • Updates reactively when the match state changes
  • More efficient than using window.matchMedia directly
  • Works server-side (always returns false for matches)
  • Cleanup is handled automatically when component is destroyed

Common media queries

See also