Skip to content
On this page

useCssVar

Category
Export Size
990 B
Last Changed
8 months ago

Manipulate CSS variables

Demo

Sample text,
Sample text, --color:

Usage

js
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

typescript
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

v8.9.1 on 7/8/2022
a9ccc - feat(all): use MaybeComputedRef (#1768)
v8.8.0 on 7/6/2022
31417 - fix: remove spaces at both ends (#1741)
v8.6.0 on 5/31/2022
bbb83 - feat: support initialValue (#1619)
v7.6.2 on 2/13/2022
f99ea - feat: support prop be ref (#1236)

Released under the MIT License.