Using the file nuxt.config.js
file, head
contents can be customized to add some meta, or other things:
module.exports = { /* ** Headers of the page */ head: { title: 'awesome title', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: 'Nuxt.js project' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ] }, ... }
But I can't find anything in the documentation to set attributes on the html
element -- I want to set the lang
attribute. Is there a way to do that?
Always add a lang attribute to the html tag to set the default language of your page. If this is XHTML 1. x or an HTML5 polyglot document served as XML, you should also use the xml:lang attribute (with the same value). If your page is only served as XML, just use the xml:lang attribute.
HTML lang AttributeThe lang attribute specifies the language of the element's content. Common examples are "en" for English, "es" for Spanish, "fr" for French, and so on.
Quick answer. Note that you should use the html element rather than the body element, since the body element doesn't cover the text inside the document's head element. When the page contains content in another language, add a language attribute to an element surrounding that content.
Source: Declaring language in HTML tag · Issue #388 · nuxt/nuxt.js
head
supports a htmlAttrs
property. It will map each key:value of the object as attribute:value
module.exports = { head: { htmlAttrs: { lang: 'en' }, title: 'awesome title', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: 'Nuxt.js project' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ] }, ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With