Any way to set the <html> element "lang" attribute from Elm?

WCAG guidelines state that the html element must have a “lang” attribute that specifies the main language used in the web page. It is possible to set it dynamically from Javascript, but I did not find a way to set it from Elm. Elm can run Javascript via ports, but because the html element is part of the DOM won’t Elm overwrite it if I change it that way, since I use Browser.Document?

In order to do this, you’ll need to compile the elm to .js and provide your own html file. It sounds like you already know how to do this if you know how to use ports. You can simply provide the value in the html itself, or if it needs to be able to change, you can use Javascript as you suggest. Elm will only modify the contents of the node passed on in init on the Javascript side, so the html element will not be modified by Elm itself.

1 Like