py-1 [&>p]:inline
This article explains the utility-first Tailwind CSS utility combination py-1 [&>p]:inline, what each part does, when to use it, and practical examples.
What it means
- py-1 — sets vertical padding (padding-top and padding-bottom) to 0.25rem (Tailwind’s spacing scale) on the element.
- [&>p]:inline — uses Tailwind’s arbitrary selector feature to target direct child
elements and apply the
inlinedisplay to them.
Combined, the class string applies small vertical padding to the container and forces its immediate
children to render inline rather than block-level.
Why you might use this
- Preserve vertical spacing on a container while making paragraph children flow inline (useful for mixed inline elements, compact metadata lines, or single-line paragraph fragments).
- Avoid default paragraph spacing (block behavior) without changing every
manually in markup.
- Create compact UI elements where semantic
tags are desired but block layout is not.
Behavior notes
- [&>p]:inline only targets immediate child
elements. Nestedelements deeper than direct children are unaffected. - Inline elements do not accept vertical margins in the same way as block elements; expect layout changes (no automatic line breaks).
- The container’s
py-1still applies vertical padding regardless of children being inline. - If child paragraphs contain block-level descendants (e.g.,
), those descendants may break layout unexpectedly.
Examples
- Compact author line
<div class=“py-1 [&>p]:inline”><p>By Jane Doe</p> <p>•</p> <p>March 24, 2026</p></div>
Renders the three paragraphs inline with small vertical padding on the container.
- Inline tags/labels
<div class=“py-1 [&>p]:inline gap-2”> <p class=“text-sm text-gray-600”>beta</p> <p class=“text-sm text-blue-600”>new</p> <p class=“text-sm”>v1.2</p></div>
Use spacing utilities (gap won’t affect inline children; use margin classes on p instead, e.g., mr-2) to separate inline paragraphs.
Alternatives
- Use
flex items-centeron the container instead of forcingto inline if you need better alignment and spacing control. - Replace
withif semantic requirements allow inline elements by default. - Use
[&>p]:inline-blockif you want inline flow but preserve width/height behaviors.
Quick tips
- Test small-screen wrapping — inline paragraphs will wrap based on content and available width.
- Combine with text and spacing utilities on the child
elements for precise visual control. -
carries paragraph semantics; prefer spans for purely inline UI tokens.