py-1 [&>p]:inline
What it is
This is a Tailwind CSS utility-first class pattern using Tailwind’s arbitrary variants and JIT-friendly syntax. It combines a spacing utility (py-1) with a parent-focused arbitrary selector ([&>p]:inline) that applies styles to direct child
elements.
Breakdown
- py-1 — Adds vertical padding (padding-top and padding-bottom) of 0.25rem (4px) by default.
- [&>p]:inline — An arbitrary variant selector that targets direct child
elements of the element carrying the class and sets their display to
inline.
When to use it
- You have a container element that needs small vertical padding, and you want any direct paragraph children to render inline instead of block (for tighter inline flow, no vertical breaks).
- Useful when mixing textual elements where paragraphs should behave like inline text segments (e.g., inline citations, labels) without changing global
styles.
Example HTML
<div class=“py-1 [&>p]:inline”><p>This paragraph will render inline, flowing with surrounding content.</p> <p>This one will also be inline and sit directly after the previous paragraph without a block break.</p></div>
Generated CSS (what Tailwind produces)
- py-1 → padding-top: 0.25rem; padding-bottom: 0.25rem;
- [&>p]:inline → selector: .[&>p]:inline > p { display: inline; } (Tailwind compiles the arbitrary variant to a selector that targets direct child p elements)
Notes & caveats
- Using inline paragraphs may affect semantics and accessibility—semantically a
is a block-level paragraph; if you only need inline text, consider or .
- Browser default margins on
are overridden when display becomes inline; you may still need to reset margins if present.
- Ensure your Tailwind configuration allows arbitrary variants (Tailwind JIT/3.x+ supports this).
- For broader descendant selection (not only direct children), use [&p]:inline instead of [&>p]:inline.
Alternatives
- &]:pl-6” data-streamdown=“unordered-list”>
- Use specific inline elements (span, em) for semantic correctness.
- Apply classes directly to the
elements:
…
- Use prose or component classes if working with rich text where many elements need consistent styling.
Summary
py-1 [&>p]:inline is a concise Tailwind pattern to add small vertical padding to a container while forcing its direct paragraph children to behave inline—handy for tight inline flows but consider semantics and accessibility before using it.
Leave a Reply