Tailoring CSS for Nested Ordered Lists: list-inside list-decimal whitespace-normal [li&]:pl-6
When building nested ordered lists in modern web layouts, controlling numbering, spacing, and indentation is essential for readability and visual hierarchy. The utility combination list-inside list-decimal whitespace-normal [li&]:pl-6 (commonly used in utility-first CSS frameworks like Tailwind CSS) provides a concise way to achieve a clean, readable nested ordered list. This article explains what each utility does, why you might combine them, and how to apply them practically with examples and tips.
What each utility does
- list-inside — Places list markers (numbers) inside the content box, so the numbers are part of the flow and wrap with the list item text.
- list-decimal — Uses decimal numbering (1., 2., 3.) for ordered lists.
- whitespace-normal — Ensures text wraps normally within list items, preventing forced unbroken lines.
- [li&]:pl-6 — A selector-targeted utility that applies left padding (pl-6) to each direct
lichild; the bracketed form targets thelielements inside the list via a selector variant (e.g., Tailwind’s arbitrary variants). This increases indentation for each item without moving the marker created bylist-insidetoo far from the text.
Why combine them
- &]:pl-6” data-streamdown=“unordered-list”>
- Readability:
list-insidekeeps numbers aligned with wrapped text, improving legibility on narrow viewports. - Consistent wrapping:
whitespace-normalensures long items wrap naturally rather than overflowing. - Controlled indentation:
[li&]:pl-6gives predictable left padding to list items, creating a consistent left edge and visual rhythm, especially useful when list items contain multiple lines or nested elements. - Semantic numbering:
list-decimalprovides clear, accessible numbering for ordered sequences.
Practical examples
Basic ordered list with utilities (Tailwind CSS):
&]:pl-6”>
This is a short item. This is a longer list item that will wrap to multiple lines and demonstrates how the marker stays inside the flow. Item with nested content:
Nested item one. Nested item two with a long line that wraps to show indentation.
Notes:
- The bracketed variant
[li&]:pl-6targetslichildren; syntax can vary by framework/version. In Tailwind, you might need a plugin or the exact arbitrary selector syntax supported by your setup. - If markers overlap with text at small widths, increase padding or use
list-outsideinstead, then adjust margins.
Accessibility and cross-browser tips
- &]:pl-6” data-streamdown=“unordered-list”>
- Test wrapping and marker positioning in multiple browsers; some older browsers render list markers differently.
- Ensure sufficient contrast and font sizing for readability.
- Keep semantic HTML (use
- /
- ) rather than faking lists with CSS for screen reader compatibility.
- and
When not to use this combo
- If you need markers outside the content block for a more traditional look—use
list-outside. - For compact UIs where extra padding is undesirable—omit the
[li&]:pl-6or use a smaller padding value.
Quick troubleshooting
- &]:pl-6” data-streamdown=“unordered-list”>
- Markers not aligned: verify the arbitrary selector syntax is supported and that no conflicting padding/margin exists.
- Unexpected wrapping: check
white-spaceinheritance and removewhitespace-nowrapif present. - Nested lists losing style: ensure utility classes are applied to nested
This utility combination gives a practical, readable approach to ordered lists that wrap and nest gracefully. Adjust padding and list placement to match your visual design while keeping markup semantic for accessibility.
Leave a Reply