J.Joe J.Joe - 5 months ago 10
CSS Question

What does `[lang]` selector do?

What does

[lang]
selector do?

I have seen
[lang|="ar"]
but not
[lang]
.

Is it going to match any h1 with a lang attribute?

h1 [lang] {
font-style: italic;
}

Answer

See for yourself:

h1 [lang] {
  font-style: italic;
}
<h1>Empty</h1>

<h1>
  <span lang="en">en</span>
</h1>

<h1>
  <span lang>anything</span>
</h1>

The [lang] selector selects any element within the h1 with a lang attribute. In this case, it doesn't matter what the attribute's value is, only that it is present.

If you wanted to select any h1 with a lang attribute, the selector would be h1[lang] (no space).