How to keep indent for second line in ordered lists via CSS?
Aligning the second line in ordered lists can be implemented by manipulating CSS properties. Applying list-style-position: inside;
to the <ol>
element ensures list markers positioning inside. On the <li>
element, utilize padding-left
to establish an indent, and text-indent
with a negative value to perfectly align consecutive lines:
This CSS recipe ensures multiline list items receive consistent indentation, concocting a clear, organized aesthetic for your content.
Customized list numbering and alignment
Custom numbering with counters
Deliver an extra punch of stylization and uniformity across your lists with CSS counters. The counter-reset
and counter-increment
properties give you the reins over numbering, ensuring indentation remains unaltered across nested lists:
Now you are the counter wizard, behold the power!
Right alignment for prolonged consistency
Gain prolonged alignment consistency across your lists, especially dealing with variable number lengths. Apply text-align: right;
alongside display: table-cell;
to form a stylish look with right-aligned numbering:
Old is gold: IE8 compatibility
Ensure oldies-but-goldies like IE8 don't feel left out by using the :before
pseudo-element. With the addition of list-style: none;
on <ol>
, the second-line indentation remains consistent on these browsers:
Welcome to the vintage club, stylist!
Advancing with flexbox/grid
Looking to up the ante? Use Flexbox or Grid for aligning list items. These modern layout methods introduce dynamic and responsive list styling:
Each list, now a perfectly aligned gymnast!
Power of CSS variables
Round up your stylists and introduce CSS variables, streamlining your list styles:
A bit of CSS magic, and your lists are donning a uniform style!
Animated lists
Tease the user interaction with a subtle sprinkle of CSS animation or transition:
Use animations like a pinch of salt, just enough to enhance the flavor.
Was this article helpful?