Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby set lang attribute to html

Tags:

html

gatsby

lang

How would you do it? modify the public folder doesn't seem to work... make your own build and host it how it is? maybe there is a function that I still don't know. Any help is appreciated.

like image 554
Vincenzo Avatar asked Oct 23 '20 16:10

Vincenzo


People also ask

How can I write 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?

The HTML lang attribute is used to identify the language of text content on the web. This information helps search engines return language specific results, and it is also used by screen readers that switch language profiles to provide the correct accent and pronunciation.

Can I use HTML with Gatsby?

Gatsby uses a React component to server render the <head> and other parts of the HTML outside of the core Gatsby application. And then make modifications as needed. If you need to insert custom HTML into the <head> or <footer> of each page on your site, you can use html.


1 Answers

Gatsby recommends using react helmet for this. You can find a lot of best practices around this topic if you look at the Gatsby documentation - how to add meta data.

Follow the step by step guide in the documentation. React helmet is really powerful. Coming back to your question, that's how you can alter the HTML language attribute:

<Helmet
  htmlAttributes={{
    lang: 'en',
  }}
/>

like image 158
Andre Avatar answered Sep 18 '22 16:09

Andre