Styling HTML Paragraphs Inline with Tailwind: py-1 [&>p]:inline
This article explains how to use the Tailwind CSS utility combination py-1 [&>p]:inline to adjust vertical spacing and make direct child paragraphs render inline. It covers what each part does, why you might use it, examples, and accessibility/maintenance considerations.
What the utilities do
- py-1 — adds vertical padding (padding-top and padding-bottom) of 0.25rem (4px) to the element.
- [&>p]:inline — uses Tailwind’s arbitrary variant syntax to target direct child
elements and apply thedisplay: inlineutility to them.
Together they style a container with slight vertical padding while forcing its immediate paragraph children to behave as inline elements (flowing with surrounding text rather than as block-level paragraphs).
When to use this combination
Use this pattern when you need a parent element to provide vertical spacing but want paragraph children to appear inline (for example, when combining multiple short paragraphs without full block separation, or when integrating paragraphs into an inline block of text while keeping consistent vertical padding on the container).
Example markup
<div class=“py-1 [&>p]:inline”><p>First short paragraph — inline.</p> <p>Second short paragraph — also inline.</p> <span>Normal inline span.</span></div>
Rendered result: both paragraphs behave like inline text, so they flow on the same line where space allows, while the container maintains 0.25rem vertical padding.
Variations
- Make paragraphs inline-block instead:
[&>p]:inline-block - Target all descendant paragraphs (not just direct children):
[&p]:inline - Change padding:
py-2for 0.5rem,py-0.5for 2px, etc.
Accessibility & maintenance notes
- &]:pl-6” data-streamdown=“unordered-list”>
- Inline paragraphs may confuse assistive technologies expecting paragraphs as block-level structural elements; prefer this pattern for short, non-semantic text snippets rather than substantial paragraph content.
- Using arbitrary variants (
[&>p]:…) can reduce clarity for future maintainers; include a brief comment when appropriate. - Test wrapping and spacing across breakpoints; inline paragraphs may overflow or create awkward line breaks on narrow screens.
Quick reference
- py-1 → padding-top/bottom: 0.25rem
Leave a Reply