::first-line

W3C CSS Snapshot 2026

Style the first displayed line in a block of text. Its length depends on the available width.

On this page

Syntax and values

Value or syntaxWhat it does
p::first-lineTargets the first line after line wrapping.

Try the example

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>::first-line</title>
  <style>
p { max-width: 18ch; }
p::first-line { color: teal; }
  </style>
</head>
<body>
<p>Bring your notebook to the workshop and check in at the front desk before the session starts.</p>
</body>
</html>

What to expect Only the words on the first line are teal.

Official references