Meta Tags
Nuxt 3 provides several different ways to manage your meta tags.
- Through your
nuxt.config
. - Through the
useHead
composable - Through global meta components
You can customize title
, titleTemplate
, base
, script
, noscript
, style
, meta
, link
, htmlAttrs
and bodyAttrs
.
📦
Nuxt currently uses vueuse/head
to manage your meta tags, but implementation details may change.
Migration
- In your
nuxt.config
, renamehead
tometa
. Consider moving this shared meta configuration into yourapp.vue
instead. (Note that objects no longer have ahid
key for deduplication.) - If you need to access the component state with
head
, you should migrate to usinguseHead
. You might also consider using the built-in meta-components. - If you need to use the Options API, there is a
head()
method you can use when you usedefineNuxtComponent
.
Example: useHead
Nuxt 2
<script>
export default {
data: () => ({
title: 'My App',
description: 'My App Description'
})
head () {
return {
title: this.title,
meta: [{
hid: 'description',
name: 'description',
content: this.description
}]
}
}
}
</script>
Example: Built-in Meta-components
Nuxt 3 also provides meta components that you can use to accomplish the same task. While these components look similar to HTML tags, they are provided by Nuxt and have similar functionality.
Nuxt 2
<script>
export default {
head () {
return {
title: 'My App',
meta: [{
hid: 'description',
name: 'description',
content: 'My App Description'
}]
}
}
}
</script>
👉
- Make sure you use capital letters for these component names to distinguish them from native HTML elements (
<Title>
rather than<title>
). - You can place these components anywhere in your template for your page.
Example: Options API
Nuxt 3 (Options API)
<script>
// if using options API `head` method you must use `defineNuxtComponent`
export default defineNuxtComponent({
head (nuxtApp) {
// `head` receives the nuxt app but cannot access the component instance
return {
meta: [{
name: 'description',
content: 'This is my page description.'
}]
}
}
})
</script>