Skip to content

usePreferredColorScheme ​

Category
Export Size
570 B
Last Changed
last month

Reactive prefers-color-scheme media query.

Demo ​

Preferred Color Scheme:
no-preference

Usage ​

js
import { usePreferredColorScheme } from '@vueuse/core'

const preferredColor = usePreferredColorScheme()

Component Usage ​

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

vue
<template>
  <UsePreferredColorScheme v-slot="{ colorScheme }">
    Preferred Color Scheme: {{ colorScheme }}
  </UsePreferredColorScheme>
</template>

Type Declarations ​

typescript
export type ColorSchemeType = "dark" | "light" | "no-preference"
/**
 * Reactive prefers-color-scheme media query.
 *
 * @see https://vueuse.org/usePreferredColorScheme
 * @param [options]
 */
export declare function usePreferredColorScheme(
  options?: ConfigurableWindow,
): ComputedRef<ColorSchemeType>

Source ​

Source • Demo • Docs

Contributors ​

Anthony Fu
Anthony Fu
丶远方
vaakian X
wheat
Alex Kozack
Le Minh Tri
Antério Vieira

Changelog ​

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)

Released under the MIT License.