Prajila V P
Prajila V P

Reputation: 5317

How can I add html Element Attributes in react

How can I add an attribute to html element in React js. I want to set <html lang="en"> to solve WCAG Level A validation issue.

I added html-element-attributes module but no idea about how to use it.

Anybody please help to get a way to add this lang attribute to html element?

Upvotes: 4

Views: 3426

Answers (2)

Aras
Aras

Reputation: 70

I added the lang property directly by creating a div surrounding the code on my app.js file.

  return (
    <Provider store={store}>
      <CacheProvider>
        <div lang='en'>
          <Head>
            ...
          </Head>
          <SidebarProvider>
            <ThemeProvider>
              <LocalizationProvider dateAdapter={AdapterDateFns}>
                <CssBaseline />
                {getLayout(<Component {...pageProps} />)}
              </LocalizationProvider>
            </ThemeProvider>
          </SidebarProvider>
        </div>
      </CacheProvider>
    </Provider>
  );

I am sharing the complete code in order to give the context. The only difference I made for this purpose was to add the div.

Upvotes: 0

Fawaz
Fawaz

Reputation: 3560

you need React helmet for this. Put this block in any top level component's render:

<Helmet>
  <html lang="en" />
</Helmet>

Upvotes: 5

Related Questions