How to set lang attribute on html element with Nuxt?

16,457

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' }
    ]
  },
  ...
}
Share:
16,457
rgmt
Author by

rgmt

I started as C++ developer. I am now trainer in web development. "I should like to help everyone, if possible."

Updated on June 29, 2022

Comments

  • rgmt
    rgmt almost 2 years

    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?

  • JMK
    JMK almost 6 years
    What if you are using different languages (locales)?
  • Dan
    Dan almost 4 years
    This also work with Body bodyAttrs and Head headAttrs