Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set lang attribute on html element with Nuxt?

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?

like image 394
rgmt Avatar asked Jan 13 '18 09:01

rgmt


People also ask

How add lang attribute in HTML?

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.

Is Lang an attribute in HTML?

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.

Under which element should we add the lang attribute?

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.


1 Answers

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' }     ]   },   ... } 
like image 101
yuriy636 Avatar answered Sep 30 '22 12:09

yuriy636