The Separator component is a visual divider that helps organize content by creating clear boundaries between sections. It can be used horizontally or vertically to improve content structure and readability.
import { Separator } from '@/components/separator'export default function SeparatorExample() {return (<div className="space-y-4"><p>Content above</p><Separator orientation="horizontal" /><p>Content below</p></div>)}
Preview: <div class="space-y-4"> <p>Content above</p>
<p>Content below</p> </div>
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | The orientation of the separator |
color | 'default' | 'primary' | 'secondary' | 'accent' | 'muted' | 'destructive' | 'success' | 'warning' | 'default' | The color theme of the separator |
variant | 'solid' | 'dashed' | 'dotted' | 'solid' | The style variant of the separator |
size | 'sm' | 'md' | 'lg' | 'md' | The size/thickness of the separator |
className | string | - | Additional CSS classes |
<div className="space-y-4"><p>First section</p><Separator orientation="horizontal" /><p>Second section</p></div>
Preview: <div class="space-y-4"> <p>First section</p>
<p>Second section</p> </div>
<div className="flex items-center space-x-4"><span>Left content</span><Separator orientation="vertical" /><span>Right content</span></div>
Preview: <div class="flex items-center space-x-4 h-8"> <span>Left content</span>
<span>Right content</span> </div>
<div className="space-y-4"><p>Section 1</p><Separator orientation="horizontal" /><p>Section 2</p><Separator orientation="horizontal" /><p>Section 3</p></div>
Preview: <div class="space-y-4"> <p>Section 1</p>
<p>Section 2</p>
<p>Section 3</p> </div>
<Separator color="primary" />
Preview:
<Separator color="secondary" />
Preview:
<Separator color="accent" />
Preview:
<Separator color="success" />
Preview:
<Separator color="warning" />
Preview:
<Separator color="destructive" />
Preview:
<Separator color="muted" />
Preview:
<Separator variant="dashed" />
Preview:
<Separator variant="dotted" />
Preview:
<Separator variant="solid" />
Preview:
<Separator size="sm" />
Preview:
<Separator size="md" />
Preview:
<Separator size="lg" />
Preview:
<Separator color="primary" variant="dashed" size="lg" />
Preview:
<div className="flex h-32"><div className="flex-1">Left content</div><Separator orientation="vertical" color="accent" size="lg" /><div className="flex-1">Right content</div></div>
Preview: <div class="flex h-32"> <div class="flex-1">Left content</div>
<div class="flex-1">Right content</div> </div>
<nav className="space-y-2"><a href="#" className="block py-2">Home</a><a href="#" className="block py-2">About</a><Separator orientation="horizontal" /><a href="#" className="block py-2">Settings</a><a href="#" className="block py-2">Profile</a></nav>
<form className="space-y-6"><div><h3 className="text-lg font-semibold">Personal Information</h3><p className="text-gray-600">Enter your personal details</p>{/* Form fields */}</div><Separator orientation="horizontal" /><div><h3 className="text-lg font-semibold">Contact Information</h3><p className="text-gray-600">Enter your contact details</p>{/* Form fields */}</div></form>
<div className="border rounded-lg p-4 space-y-4"><div><h3 className="font-semibold">Card Title</h3><p className="text-gray-600">Card description</p></div><Separator orientation="horizontal" /><div className="flex justify-between"><span>Action 1</span><span>Action 2</span></div></div>
<div className="flex h-64"><div className="flex-1 p-4"><h3 className="font-semibold">Main Content</h3><p>Main content area</p></div><Separator orientation="vertical" /><div className="flex-1 p-4"><h3 className="font-semibold">Sidebar</h3><p>Sidebar content</p></div></div>
Use appropriate spacing around separators for better visual hierarchy.
// ✅ Good - Proper spacing<div className="space-y-4"><p>Content above</p><Separator orientation="horizontal" /><p>Content below</p></div>
Use consistent orientation throughout your application.
// ✅ Good - Consistent horizontal separators<div className="space-y-4"><div>Section 1</div><Separator orientation="horizontal" /><div>Section 2</div><Separator orientation="horizontal" /><div>Section 3</div></div>
Use separators to create logical content divisions.
// ✅ Good - Semantic divisions<div className="space-y-6"><section><h2>Introduction</h2><p>Introduction content</p></section><Separator orientation="horizontal" /><section><h2>Main Content</h2><p>Main content</p></section></div>
Ensure proper accessibility with ARIA attributes.
// ✅ Good - Accessible separator<Separatororientation="horizontal"role="separator"aria-orientation="horizontal"/>
Use separators to create clear visual hierarchy.
// ✅ Good - Clear hierarchy<div className="space-y-4"><h1 className="text-2xl font-bold">Page Title</h1><Separator orientation="horizontal" /><div className="space-y-2"><h2 className="text-lg font-semibold">Section Title</h2><p>Section content</p></div></div>
You can customize the separator appearance using CSS classes:
<Separatororientation="horizontal"className="bg-blue-500 h-0.5"/>
Use different colors for different contexts:
// Light separator<Separator orientation="horizontal" className="bg-gray-200" />// Dark separator<Separator orientation="horizontal" className="bg-gray-800" />// Colored separator<Separator orientation="horizontal" className="bg-blue-500" />
Use different thicknesses for different emphasis levels:
// Thin separator<Separator orientation="horizontal" className="h-px" />// Medium separator<Separator orientation="horizontal" className="h-0.5" />// Thick separator<Separator orientation="horizontal" className="h-1" />
Create dynamic separators based on content:
const renderSeparator = (type: 'section' | 'subsection' | 'minor') => {switch (type) {case 'section':return <Separator orientation="horizontal" className="h-1 bg-gray-400" />;case 'subsection':return <Separator orientation="horizontal" className="h-0.5 bg-gray-300" />;case 'minor':return <Separator orientation="horizontal" className="h-px bg-gray-200" />;default:return <Separator orientation="horizontal" />;}};
Show separators conditionally:
<div className="space-y-4">{items.map((item, index) => (<div key={item.id}><div>{item.content}</div>{index < items.length - 1 && (<Separator orientation="horizontal" />)}</div>))}</div>
Use different separators for different screen sizes:
<div className="flex flex-col md:flex-row"><div className="flex-1 p-4"><h3>Content</h3></div>{/* Horizontal on mobile, vertical on desktop */}<Separatororientation="horizontal"className="md:hidden"/><Separatororientation="vertical"className="hidden md:block"/><div className="flex-1 p-4"><h3>Sidebar</h3></div></div>
- Divider: For more complex dividers
- Spacer: For spacing between elements
- Card: For content containers
- Box: For simple containers
- Grid: For layout containers
For the complete API reference and advanced usage patterns, see the Separator API documentation.
