EN
CSS - set text line height
0 points
In this article, we would like to show you how to
Quick solution:
xxxxxxxxxx
1
.my-element {
2
line-height: 20px;
3
}
Note:
The
line-height
property can be set to:
- keyword value (e.g.
line-height: normal
),- unitless value (e.g.
line-height: 2.5
),- length value (e.g.
line-height: 3em
),- percentage value (e.g.
line-height: 35%
),- global value (e.g.
line-height: inherit
).
In this section, we present some div
elements with example line-height
values.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div {
7
border: 1px solid lightgray;
8
padding: 0 5px;
9
}
10
11
.text-1 {
12
line-height: 1.2; /* usually a default value */
13
}
14
15
.text-2 {
16
line-height: 3em;
17
}
18
19
.text-3 {
20
line-height: 100px;
21
}
22
23
</style>
24
</head>
25
<body>
26
<div class="text-1">This element line height is 1.2 (normal)</div>
27
<div class="text-2">This element line height is 3em</div>
28
<div class="text-3">This element line height is 100px</div>
29
</body>
30
</html>
Note:
line-height: 1.2
in most cases is the default value, equivalent toline-height: normal
. However, this depends on the user agent and element'sfont-family
.