EN
CSS - style first line of the text only
3 points
In this article, we would like to show you how to style only the first line of the text using CSS.
Quick solution:
xxxxxxxxxx
1
div::first-line {
2
color: blue;
3
}
Note:
The
::first-line
CSS pseudo-element applies styles to the first line of the specified element.
Screenshot:

In this example, we use ::first-line
pseudo-element to specify the style for the first line of the div
element only.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
div::first-line {
7
color: blue;
8
}
9
10
</style>
11
</head>
12
<body>
13
<div>
14
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
15
</div>
16
</body>
17
</html>