Skip to main content

Usage

The useHead composable allows you to manage your head tags in a programmatic and reactive way, powered by Unhead. It lets you customize the meta tags, links, scripts, and other elements in the <head> section of your HTML document.
[app/app.vue]
If the data comes from a user or other untrusted source, we recommend you check out useHeadSafe.
The properties of useHead can be dynamic, accepting ref, computed and reactive properties. The meta parameter can also accept a function returning an object to make the entire object reactive.

Parameters

MaybeComputedRef<MetaObject>
required
An object accepting head metadata properties to customize the page’s <head> section. All properties support reactive values (ref, computed, reactive) or can be a function returning the metadata object.
string
Sets the page title.
string | ((title?: string) => string)
Configures a dynamic template to customize the page title. Can be a string with %s placeholder or a function.
Base
Sets the <base> tag for the document.
Array of link objects. Each element is mapped to a <link> tag, where object properties correspond to HTML attributes.
Meta[]
Array of meta objects. Each element is mapped to a <meta> tag, where object properties correspond to HTML attributes.
Style[]
Array of style objects. Each element is mapped to a <style> tag, where object properties correspond to HTML attributes.
Script[]
Array of script objects. Each element is mapped to a <script> tag, where object properties correspond to HTML attributes.
Noscript[]
Array of noscript objects. Each element is mapped to a <noscript> tag, where object properties correspond to HTML attributes.
HtmlAttributes
Sets attributes of the <html> tag. Each object property is mapped to the corresponding attribute.
BodyAttributes
Sets attributes of the <body> tag. Each object property is mapped to the corresponding attribute.

Return Values

ActiveHeadEntry
An object with methods to update or dispose the head entry.
(input: MetaObject) => void
Updates the entry with new input. Will first clear any side effects for previous input.
() => void
Dispose the entry, removing it from the active head. Will queue side effects for removal.

Examples

Basic Meta Tags

[app/pages/about.vue]

Reactive Meta Tags

[app/pages/profile.vue]

Using a Function for Full Reactivity

[app/pages/dynamic.vue]

Adding External Scripts and Styles

[app/pages/external.vue]

Body and HTML Attributes

[app/pages/themed.vue]

Type