guides

Class Attribute

Learn how to use the class attribute with Unhead.

When using the htmlAttrs or bodyAttrs options, you can use the class attribute to add classes to the html or body elements.

useHead({
  htmlAttrs: {
    class: 'my-class',
  }
})

For improved reactivity and merging support, you can provide the class as an object or an array.

Class Object

When providing class as an object, the key should be the class and the value will be whether the class should be added or not.

const darkMode = false
useHead({
  htmlAttrs: {
    class: {
      // will be rendered
      dark: darkMode,
      // will not be rendered
      light: !darkMode,
    }
  }
})

Class Array

useHead({
  htmlAttrs: {
    class: ['my-class', 'my-other-class'],
  }
})