Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Theme
Mode
Accessibility
Vuetify

Sign in

Sign in with your preferred provider to access your account.

useMediaQuery

A composable for reactive CSS media query matching with automatic cleanup.


Intermediate100% coverageFeb 4, 2026

Usage

The useMediaQuery composable wraps the browser’s matchMedia API, providing reactive updates when the media query state changes. It supports static strings, refs, and getter functions for dynamic queries.

Landscape orientation: false
Width >= 768px: false
768px
<script setup lang="ts">
  import { useMediaQuery } from '@vuetify/v0'
  import { shallowRef } from 'vue'

  const { matches: isLandscape } = useMediaQuery('(orientation: landscape)')

  const minWidth = shallowRef(768)
  const { matches: isWide } = useMediaQuery(() => `(min-width: ${minWidth.value}px)`)
</script>

<template>
  <div class="flex flex-col gap-4">
    <div class="flex items-center gap-3">
      <span
        class="w-3 h-3 rounded-full"
        :class="isLandscape ? 'bg-success' : 'bg-error'"
      />
      <span>Landscape orientation: <strong>{{ isLandscape }}</strong></span>
    </div>

    <div class="flex items-center gap-3">
      <span
        class="w-3 h-3 rounded-full"
        :class="isWide ? 'bg-success' : 'bg-error'"
      />
      <span>Width >= {{ minWidth }}px: <strong>{{ isWide }}</strong></span>
    </div>

    <div class="flex items-center gap-4 pt-4 border-t border-divider">
      <label class="text-sm">Min width threshold:</label>
      <input
        v-model.number="minWidth"
        class="flex-1"
        max="1920"
        min="320"
        step="10"
        type="range"
      >
      <span class="w-16 text-right font-mono text-sm">{{ minWidth }}px</span>
    </div>
  </div>
</template>

Architecture

useMediaQuery wraps the browser’s matchMedia API with Vue reactivity and SSR safety:

Media Query Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Media Query Hierarchy

Reactivity

Property/MethodReactiveNotes
matchesShallowRef, readonly
queryComputed, accepts MaybeRefOrGetter
mediaQueryListShallowRef, readonly (MediaQueryList or null)
Tip

Dynamic queries Pass a ref or getter to useMediaQuery for dynamic query updates. The composable re-evaluates when the query changes.

API Reference

The following API details are for the useMediaQuery composable.

Functions

useMediaQuery

(query: MaybeRefOrGetter<string>) => MediaQueryContext

Reactive media query matching.

usePrefersDark

() => MediaQueryContext

Check if the user prefers dark color scheme.

usePrefersReducedMotion

() => MediaQueryContext

Check if the user prefers reduced motion.

usePrefersContrast

() => MediaQueryContext

Check if the user prefers more contrast.

Properties

matches

Readonly<ShallowRef<boolean>>

Whether the media query currently matches

query

ComputedRef<string>

The current media query string

mediaQueryList

Readonly<ShallowRef<MediaQueryList>>

The underlying MediaQueryList (null on server)

Methods

stop

() => void

Stop listening and clean up

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/