Indent starting from the second line of a paragraph with CSS
Indent subsequent lines of a paragraph via CSS by applying a negative text-indent coupled with a corresponding positive margin:
This method pulls all lines, excluding the initial one, back by 1em. It then shoves the total paragraph to the right by an identical magnitude, upholding alignment.
Traditional hanging indent with padding
Homemade hanging indent
You could consider utilizing a hanging indent effect – traditionally seen in typography – achieved by amalgamating padding-left
and text-indent
. This combo makes the body text appear as if it's hanging under the first line.
This technique provides an indent to all lines, whilst text-indent
returns the first line to its original position. Consequently, only the second and following lines appear indented.
Indenting lists
For indenting list items (li
), you could pair margin-left
with a negative text-indent
:
This will generate a consistent hanging indent across all list items, excluding the presentation of bullet points or numbers.
Going beyond with advanced indentation techniques
Image-induced indentation
Stepping into the realm of creativity, you could use images for indentation. Either an SVG or a single-pixel image could be useful here:
Regulating the width
and height
of the ::before
pseudo-element lets you control your indentation area. Ideal for the times when the indentation region must be independent of the enclosing div
width.
Word-perfect baseline with SVG
For precise influence over text, you might consider adopting an SVG image to indent the text. Specifically, modulate the SVG's Y attribute to decide the baseline depth:
The vertical-align
property synchronizes the SVG with the text, affording control over the text baseline.
Multi-line bold statement with floats
There are times when you want the first few words to span over two rows. That’s when the float
property comes to the rescue:
This style enforces the first line to stand out, while subsequent lines are wrapped under, giving a unique indentation style.
Troubleshooting and Optimizations
Responsive design obligations
Whilst creating these indents, remember to make them responsive. You might need media queries to adjust indentation for different screen sizes.
Establishing cross-browser compatibility
Verify your designs across multiple browsers. Text-indent
and float
properties might render differently, so ensure to test them effectively.
Accessibility matters
Keep accessibility in the picture. Guarantee that the indentation isn’t impeding the legibility or navigation for disabled users.
Was this article helpful?