list-inside list-disc whitespace-normal [li&]:pl-6
This article explains the Tailwind CSS utility combination shown in the title: how it affects list rendering, when to use it, and practical examples you can drop into your project.
What each utility does
- &]:pl-6” data-streamdown=“unordered-list”>
- list-inside: Positions list markers (bullets) inside the content box, so bullets flow with text and wrap normally.
- list-disc: Uses filled circle bullets for unordered lists.
- whitespace-normal: Allows normal wrapping and collapsing of whitespace; lines break as needed
- [li&]:pl-6: Uses Tailwind’s arbitrary selector feature to apply
pl-6(padding-left: 1.5rem) to each li element; the selector targets li scoped inside the parent (the&placeholder is replaced by the parent selector).
Combined, these utilities produce unordered lists whose bullets sit inside the text flow, use disc markers, wrap normally, and whose list items have consistent left padding.
Why use this combination
- Better control over wrapping: With bullets inside, long lines wrap aligned under the text, which can improve readability in narrow containers.
- Consistent indentation: Applying
pl-6to li ensures alignment and spacing even if the default browser styles vary. - Predictable whitespace:
whitespace-normalprevents collapsed or preserved whitespace behaviors from breaking layout when content includes extra spaces or long words.
When to prefer list-inside over list-outside
- Use list-inside when you want wrapped lines of a list item to align with the start of the text (not the bullet).
- Use list-outside when you prefer bullets to sit in the margin and the text block to have a clear left edge; better for designs that require hanging bullets.
Examples
Basic usage (HTML with Tailwind classes):
This is a short item. This is a long list item that will wrap onto multiple lines to demonstrate how the bullet stays inside and the wrapped lines align with the item text rather than the bullet. Item with extra spaces preserved as normal wrapping occurs.
Notes:
- The arbitrary selector
[li&]:pl-6is supported in Tailwind v3+; ensure your Tailwind configuration allows arbitrary variants. - If you need different spacing for nested lists, override with nested selectors or utility classes on nested UL/OL elements.
Accessibility and styling tips
- &]:pl-6” data-streamdown=“unordered-list”>
- Ensure sufficient contrast between bullet color and background; bullets inherit color from text.
- For screen readers, semantic
- /
li::marker { font-size: 0.9em; color: #4b5563; }
Troubleshooting
- &]:pl-6” data-streamdown=“unordered-list”>
- If bullets still render outside, check for conflicting CSS (e.g., reset styles) or parent styles that modify list-style-position.
- If arbitrary selector syntax is rejected, update Tailwind or adjust the selector to a supported form, for example adding a custom plugin or using:
ul > li { padding-left: 1.5rem; }
in your stylesheet.
Summary
Using list-inside list-disc whitespace-normal [li_&]:pl-6 gives you wrapped, readable lists with consistent indentation. It’s a compact Tailwind pattern useful for responsive UIs and content-heavy layouts.
Leave a Reply