Styling the First Line of a Paragraph Using ::first-line
The ::first-line pseudo-element in CSS allows you to style only the first line of a block-level element. This is helpful for adding emphasis, decorative effects, or visual hierarchy to the start of a paragraph.
::first-line targets only the first rendered line of text within a block element.
It can be styled with text-related properties such as color, font-size, font-weight, letter-spacing, and word-spacing.
It works exclusively on block-level elements like <p>, <div>, or <section>.
It cannot insert content; it only modifies the appearance of the existing text.
Here, only the first line of the paragraph is styled differently, providing emphasis while the rest of the paragraph remains normal.
Use ::first-line to highlight or emphasize the start of paragraphs.
Stick to text-related CSS properties for consistent results.
Consider responsive layouts, as the first line may wrap differently on various screen sizes.
Combine with ::first-letter for advanced typographic effects.
How would you make the first line of a paragraph red and bold using CSS?
What happens if you try to set margin-top on ::first-line? Why?
A designer says the first line of all article paragraphs should be italicized, but it’s not working on mobile — what would you check?
We’re seeing inconsistent first-line styling across browsers in our blog component — how would you debug and fix this?
We’re building a rich-text editor where users can style the first line of paragraphs — how would you implement this reliably without breaking layout or performance on long-form content?
How would you handle first-line styling in a component that dynamically switches between block and inline-display based on screen size?
Our content platform has legacy CSS that uses JavaScript to simulate first-line styling — how would you migrate to native CSS ::first-line without breaking existing layouts or accessibility?
When designing a global typography system, how do you balance the use of ::first-line with accessibility, performance, and internationalization concerns across 50+ languages?