EN
CSS - style HTML elements depending on content language
3 points
In this article, we would like to show you how to style HTML elements depending on content language in CSS.
Quick solution:
xxxxxxxxxx
1
div:lang(en-US) {
2
background: yellow;
3
}
Note:
The
div
element can be replaced with any other selector or use*
to style all elements (e.g.*:lang(en-US)
).
In this example, we create styles for div
elements with three different languages using :lang()
pseudo class.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div:lang(en) {
7
background: yellow;
8
}
9
10
div:lang(es) {
11
background: gold;
12
}
13
14
div:lang(fr) {
15
background: orange;
16
}
17
18
div:lang(de) {
19
background: red;
20
}
21
22
</style>
23
</head>
24
<body>
25
<div lang="en">English</div>
26
<div lang="es">Española</div>
27
<div lang="fr">Français</div>
28
<div lang="de">Deutsch</div>
29
</body>
30
</html>