Troubleshooting

py-1 [&>p]:inline

What this selector does

The class pattern py-1 [&>p]:inline is a Tailwind CSS-style utility that combines spacing with a child selector. Broken down:

  • py-1 applies padding on the y-axis (top and bottom) of 0.25rem (4px) assuming default Tailwind spacing.
  • [&>p]:inline uses Tailwind’s arbitrary selector feature to target direct child

    elements and set their display to inline.

Together, the rule means: give the element 0.25rem vertical padding, and make any direct paragraph children display inline.

Why use this pattern

  • Control child layout without extra classes: Useful when you cannot or prefer not to add classes to child elements.
  • Maintain semantic markup: Keep paragraphs (

    ) for semantics while adjusting their display to suit inline layout needs.

  • Utility-first styling: Fits Tailwind’s approach of composing small utilities for precise styling.

Common use cases

  1. Inline list of paragraphs inside a badge or pill where you want paragraph semantics but inline flow.
  2. Components where children are generated by content systems and you can’t edit child tags.
  3. Adjusting paragraph display inside buttons or tags without altering markup.

Example HTML

html
<div class=“py-1 [&>p]:inline”><p>First part —</p>  <p>second part</p></div>

Rendered result: both paragraphs flow inline, separated by default spacing (you may need to add margins or separators).

Notes and caveats

  • Tailwind’s arbitrary selector syntax requires a build setup that supports it (Tailwind v3+).
  • Inline paragraphs may collapse vertical spacing; adjust with margins, padding, or use inline-block if you need width/height.
  • If paragraphs contain block-level children, inline may cause layout issues—test in your target browsers.

Alternatives

  • Add a specific class to child paragraphs (if you control the markup):

    .

  • Use flex on the parent to keep children inline while preserving block semantics: flex flex-row gap-2.
  • Use prose utilities or custom CSS if you need richer typographic control.

Quick tweaks

  • To keep paragraph behavior but allow vertical alignment: [&>p]:inline-block.
  • To add spacing between the inline paragraphs: [&>p]:mr-2.
  • To target all descendant paragraphs (not just direct children): [&_*p]:inline is not valid; use [&:where(p)]:inline carefully or adjust markup.

Conclusion

py-1 [&>p]:inline is a concise Tailwind utility combo for applying vertical padding while forcing direct child paragraphs to behave inline handy in componentized layouts and content-driven UIs.

Your email address will not be published. Required fields are marked *