Skip to content
On this page

usePreferredColorScheme

Category
Export Size
1.1 kB
Last Changed
last year

Reactive prefers-color-scheme media query.

Demo

Preferred Color Scheme:
no-preference

Usage

js
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.

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

Type Declarations

typescript
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

Released under the MIT License.