Understanding the Tailwind-style Selector: py-1 [&>p]:inline
This article explains what the utility-like class py-1 [&>p]:inline does, when to use it, and how to reproduce the same behavior in plain CSS. It’s written assuming a Tailwind CSS-style syntax (the […] group and & are from Tailwind’s arbitrary variants), but the concepts apply to any utility or CSS you write.
What this selector means
- py-1 — sets vertical padding (padding-top and padding-bottom) to a small value. In Tailwind,
py-1equalspadding-top: 0.25rem; padding-bottom: 0.25rem;. - [&>p]:inline — is an arbitrary variant that targets direct child
elements of the element the class is applied to, and appliesdisplay: inlineto thosechildren. - Combined, the host element gets small vertical padding, and its immediate
children are rendered inline rather than block.
Why you might use this
- To keep vertical spacing on a container while forcing paragraph children to flow inline (useful for inline text segments that must still be inside
tags for semantics or accessibility). - To style components where markup is constrained (e.g., CMS that forces
wrappers) but you want inline layout for paragraphs. - To create compact lists of text nodes inside a padded container without paragraph block breaks.
Example HTML (Tailwind)
Assuming Tailwind with JIT and arbitrary variants enabled:
First sentence.
Second sentence.
Rendered result: the container has 0.25rem vertical padding; the two
elements display inline, so their text flows on the same line (wrapping as needed) without the default paragraph breaks.
Equivalent plain CSS
If you’re not using Tailwind, the same behavior can be achieved with:
.my-container { padding-top: 0.25rem; padding-bottom: 0.25rem;}.my-container > p { display: inline;}
And HTML:
First sentence.
Second sentence.
Accessibility and semantics
- Inline paragraphs still remain semantic
elements, which can be useful for screen readers and content structure. - Be cautious: forcing inline display may affect reading order or spacing; ensure it doesn’t confuse assistive tech or keyboard navigation.
- If the visual intent is inline text, consider whether
or other inline elements would be more appropriate semantically.
Variations and extensions
- Use
inline-blockinstead ofinlineif you need paragraph dimensions (width/height) preserved. - Target deeper paragraphs with selectors like
[&p]:inline(no direct-child) or[&>p:first-child]:font-boldfor more specific behavior in Tailwind. - Combine with responsive prefixes:
md:[&>p]:inlineto apply only at medium screens and above.
Quick checklist
- &]:pl-6” data-streamdown=“unordered-list”>
- Ensure Tailwind’s JIT and arbitrary variants are enabled before using
[…]syntax. - Confirm that paragraphs must remain
for semantic reasons; otherwise consider inline tags. - Test across browsers and assistive technologies to confirm readability and layout.
This pattern is a concise way to mix container spacing utilities with fine-grained control over direct-child elements when using utility-first CSS systems or when writing equivalent plain CSS.
Leave a Reply