Skip to content
On this page

usePreferredColorScheme

Category
Last Changed
7 months ago

Reactive prefers-color-scheme media query.

Demo

Preferred Color Scheme:
no-preference

Usage

import { usePreferredColorScheme } from '@vueuse/core'

const preferredColor = usePreferredColorScheme()
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.

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

Type Declarations

export declare 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>
export declare 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

SourceDemoDocs

Contributors

Anthony Fu
wheat
Alex Kozack
Le Minh Tri
Antério Vieira

Changelog

No recent changes
usePreferredColorScheme has loaded