Skip to content
On this page

useMediaQuery

Category
Last Changed
2 weeks ago

Reactive Media Query. Once you've created a MediaQueryList object, you can check the result of the query or receive notifications when the result changes.

Demo

isLargeScreen: false
prefersDark: false

Usage

import { useMediaQuery } from '@vueuse/core'

const isLargeScreen = useMediaQuery('(min-width: 1024px)')
const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)')
import { useMediaQuery } from '@vueuse/core'

const isLargeScreen = useMediaQuery('(min-width: 1024px)')
const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)')

Type Declarations

/**
 * Reactive Media Query.
 *
 * @see https://vueuse.org/useMediaQuery
 * @param query
 * @param options
 */
export declare function useMediaQuery(
  query: string,
  options?: ConfigurableWindow
): Ref<boolean>
/**
 * Reactive Media Query.
 *
 * @see https://vueuse.org/useMediaQuery
 * @param query
 * @param options
 */
export declare function useMediaQuery(
  query: string,
  options?: ConfigurableWindow
): Ref<boolean>

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
Dominik Freier
webfansplz
Eureka
karma
Alex Kozack
Jacob Clevenger

Changelog

v8.8.1 on 7/6/2022
60f9a - fix: check if window.matchMedia is a function (#1765)
v8.8.0 on 7/6/2022
5a64c - fix: strict isSupported check
v8.5.0 on 5/16/2022
0222d - fix: normalize isSupported flag (#1575)
v8.2.1 on 3/30/2022
7edd0 - fix: media query before mount (#1461)
v8.0.1 on 3/14/2022
92ced - fix: removeEventListener in guard target should be med… (#1401)
v7.0.2 on 11/23/2021
7b67d - feat: improve SSR
useMediaQuery has loaded