Skip to content
On this page

useCssVar

Manipulate CSS variables

Demo

Category
Last Changed
2 months ago
Sample text,
Sample text, --color:

Usage

import { useCssVar } from '@vueuse/core'

const el = ref(null)
const color = useCssVar('--color', el)

const elv = ref(null)
const key = ref('--color')
const colorVal = useCssVar(key, elv)

const someEl = ref(null)
const color = useCssVar('--color', someEl, { initialValue: '#eee' })
import { useCssVar } from '@vueuse/core'

const el = ref(null)
const color = useCssVar('--color', el)

const elv = ref(null)
const key = ref('--color')
const colorVal = useCssVar(key, elv)

const someEl = ref(null)
const color = useCssVar('--color', someEl, { initialValue: '#eee' })

Type Declarations

export interface UseCssVarOptions extends ConfigurableWindow {
  initialValue?: string
}
/**
 * Manipulate CSS variables.
 *
 * @see https://vueuse.org/useCssVar
 * @param prop
 * @param target
 * @param initialValue
 * @param options
 */
export declare function useCssVar(
  prop: MaybeComputedRef<string>,
  target?: MaybeElementRef,
  { window, initialValue }?: UseCssVarOptions
): Ref<string>
export interface UseCssVarOptions extends ConfigurableWindow {
  initialValue?: string
}
/**
 * Manipulate CSS variables.
 *
 * @see https://vueuse.org/useCssVar
 * @param prop
 * @param target
 * @param initialValue
 * @param options
 */
export declare function useCssVar(
  prop: MaybeComputedRef<string>,
  target?: MaybeElementRef,
  { window, initialValue }?: UseCssVarOptions
): Ref<string>

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
木荣
JD Solanki
btea
Alex Kozack

Changelog

No recent changes

Released under the MIT License.