Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Separator examples · Spacing

With Margins Separator for React

A horizontal separator with vertical margins on the line itself instead of a parent gap.

Framework
UI library

Let the line own its pause. This React Separator carries my-6 itself, in a plain block container with no gap, so the spacing stays attached to the line when the siblings don't share one flex rhythm. Use it when a separator sits between mixed content that shouldn't inherit a common gap.

Preview

Preview width

Account

Billing

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

When should I use margins instead of gap?

When the line sits between mixed siblings that shouldn't share one gap, or when only this break needs a different pause. Prefer a gap when every child belongs to the same stack.

How do I set top and bottom separately?

Use mt-8 mb-4 for an uneven pause: more above to close the previous section, less below to attach the next heading.

Do separator margins collapse?

In a block container like this one, yes: my-6 next to a heading with mt-4 gives 24 pixels, not 40. Inside a flex or grid container margins don't collapse, and they add to the gap.

Can I use negative margins?

Avoid them: negative margins overlap content and break at other type sizes. Adjust the positive value instead.

Should margins change by breakpoint?

my-4 lg:my-8 is reasonable when the desktop layout has more air. Stay on the same spacing scale as the rest of the page.

Can I combine vertical and horizontal margins?

Yes, but a horizontal inset needs a width override, as the Inset Separator example shows: the line is full width by default, so mx-8 alone overflows the parent.