Search code examples
htmlcssattributeslang

How to set the lang global attribute for <html> inside an external CSS file (.css)


I keep getting a warning message when I try to set the lang attribute for the <html> element inside a CSS stylesheet (external .css file).

Inside the CSS stylesheet, I added the following to set the lang attribute for the <html> tag:

html {
  lang: "en-US";
}

However, my editor (VS code) prompts me with a warning message stating the following:

Unknown property: 'lang'css(unknownProperties)

I am not sure if what I did is correct, so I want to know if there is a way to set the lang attribute for the <html> tag inside a .css?


Solution

  • When we usually use inline styles, we may mistakenly assume that the specific attributes of style are level with other attributes of html, but they are not.

    lang is hierarchical with the id, class, style at the same level,and to some extent css is a collection of html style attributes.

    You can't change style(css) to change the value of id or class, the same as lang.(at least now)

    just use lang inside ele.

    I din't found why web used lang as html global attribute why not style attribute but some funny thing.

    desripe of dir in mdn:

    This attribute can be overridden by the CSS properties direction and unicode-bidi, if a CSS page is active and the element supports these properties.

    As the directionality of the text is semantically related to its content and not to its presentation, it is recommended that web developers use this attribute instead of the related CSS properties when possible. That way, the text will display correctly even on a browser that doesn't support CSS or has the CSS deactivated.

    Logically, Lang might be able to fit into style rather than global attributes,but it's one of Global attributes and can't be set in css at least now,so just follow the conventions it when they don't ruin something.