py-1 [&>p]:inline
What it is
The class-like utility py-1 [&>p]:inline appears to combine two small CSS approaches used in utility-first frameworks (like Tailwind CSS) or in utility-style class naming: a vertical padding utility (py-1) and a selector-specific utility ([&>p]:inline) that targets direct child
elements and applies display: inline to them.
How it works
- py-1 — shorthand for “padding-top and padding-bottom of 0.25rem” (Tailwind default scale), adding small vertical spacing to the element.
- [&>p]:inline — a bracketed arbitrary variant that compiles to a selector applying
display: inlineto every direct childof the element. In Tailwind-style arbitrary variants, the&represents the parent selector;&>pbecomes “parent > p”.
Combined, the element gets vertical padding while its direct paragraph children are rendered inline rather than as block-level elements.
Use cases
- Compact inline lists of paragraphs where you want paragraph semantics but inline layout (e.g., a row of term–definition pairs separated visually, or small text snippets that should flow inline within a button-like container).
- Buttons or badges that contain multiple paragraph elements but should remain single-line visually.
- Legacy content where paragraph tags are used for small inline items and you need to override their block behavior without changing the HTML.
Example (conceptual)
HTML structure:
Label:
Value
Rendered result:
- Container has small vertical padding.
- Both paragraphs render inline, appearing side by side.
Accessibility & semantics
- Using
as inline content is semantically unusual; prefer inline elements (span, strong) when content is short and purely inline. If you must keepfor semantic reasons, ensure screen readers and keyboard navigation still interpret content correctly. - Inline paragraphs may affect line breaks; test at different viewport widths.
Browser support & build notes
- This pattern relies on a build tool (Tailwind v3+ or similar) that supports arbitrary variants. The bracketed selector compiles to a CSS rule like:
.parent > p { display: inline; } - If not using a utility framework, you can replicate it in plain CSS:
.container { padding-top: .25rem; padding-bottom: .25rem; }
.container > p { display: inline; }
Alternatives
- Replace
withorand use standard utilities likeinlineon those elements. - Use flexbox (
flex,items-center,gap-x-2) on the container instead of forcing inline on paragraphs.
Summary
py-1 [&>p]:inline is a concise utility-driven way to add small vertical padding to a container while rendering its direct paragraph children inline. It’s handy for quick layout tweaks in utility-first CSS systems but consider semantic HTML and accessibility when choosing this approach.
Leave a Reply