Divider

Horizontal or vertical separator line, with optional centred label.

import { ... } from '@corndev/ui'

or
Home
About
Contact

HTML

No JavaScript required — these classes are the whole component.

<hr class="" data-orientation="horizontal" />

<div class="" data-orientation="horizontal" data-labelled>
  <span class="corn-divider-label">or</span>
</div>

Classes

ClassDescription
.corn-divider
.corn-divider-labelThe label span inside a labelled divider

Attributes

AttributeValues
data-orientationhorizontal|vertical
data-labelledpresent or absent

Vanilla JS

Optional. createDivider only adds and removes the classes and attributes above, so the HTML is equivalent. Reach for it when you need to change options at runtime.

import { createDivider } from '@corndev/ui';
import '@corndev/ui/theme';

const el = document.querySelector('#target');
const instance = createDivider(el, { /* options */ });

Options

OptionTypeDefaultDescription
orientation'horizontal'|'vertical''horizontal'Rule direction. A vertical divider stretches to fill a flex parent.
labelledbooleanfalseDraw the rules as pseudo-elements either side of a centred label. Requires a container element with a .corn-divider-label child — apply it to a <div>, never an <hr>.

React

Divider — from @corndev/ui-react.

Props

PropTypeDefaultDescription
orientation'horizontal'|'vertical''horizontal'Rule direction. A vertical divider stretches to fill a flex parent.
labelReact.ReactNodeundefinedCentred label. Supplying it switches the element from <hr> to a <div> and applies the labelled treatment.
classNamestringundefined

Horizontal

import '@corndev/ui/theme';

<hr class="" data-orientation="horizontal" />

With label

Add data-labelled and a .corn-divider-label span to centre text between the lines. Use a <div> here rather than an <hr> — the labelled variant draws its rules with pseudo-elements and so needs a child element.

<div class="" data-orientation="horizontal" data-labelled>
  <span class="corn-divider-label">or</span>
</div>

Vertical

Use data-orientation="vertical" inside a flex container to draw a vertical separator between inline elements.

<div style="display: flex; align-items: center; gap: 8px;">
  <span>Home</span>
  <div class="" data-orientation="vertical"></div>
  <span>About</span>
  <div class="" data-orientation="vertical"></div>
  <span>Contact</span>
</div>