---
title: "Border Layout"
description: "Border Layout component - north, south, west and east around a center, every divider draggable (it reuses the Resizer): north/south or west/east dominant, horizontal and vertical splits, nested splits, grips, dashed / dotted / double / gap dividers, custom handles, collapsible and remembered panels."
slug: "border-layout"
---

import { DocPage, PageHeader, SkillPanel, SourceFiles, StatesSection, DocLink, SkillField, SkillText, SkillRow, ApiPill, ApiSection } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="border-layout" title="Border Layout" component="border-layout">
  An application frame in five regions - north, south, west and east around a center - with every divider draggable. It reuses the <DocLink href="resizer.html">Resizer</DocLink>: each side is a <code>.resizer</code> wrapping its pane, and inside a border layout its handle becomes a full-length divider you drag or move with the arrow keys. Leave regions out and the same frame is a horizontal split, a vertical split or three columns; nest it for more. North/south or west/east dominant, grips, dashed / dotted / double / gap dividers, custom handles, collapsible and remembered panels - after shadcn's Resizable.
</PageHeader>

<SkillPanel component="border-layout">
  <SkillField label="Native basis">
<SkillText>A CSS grid with named areas; each resizable region is a <code>.resizer</code> whose one handle - a <code>role="separator"</code> - becomes the divider.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas" title="the five regions"><code>grid-template-areas</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/Element/setPointerCapture" title="the drag (the Resizer's)"><code>setPointerCapture()</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/separator_role" title="each divider is a window splitter"><code>role="separator"</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver" title="the center keeps its minimum"><code>ResizeObserver</code></ApiPill>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage" title="remembered sizes, through a persisted() store"><code>localStorage</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.border-layout</code>
    <code>.border-layout-north</code>
    <code>.border-layout-south</code>
    <code>.border-layout-west</code>
    <code>.border-layout-east</code>
    <code>.border-layout-center</code>
    <code>.border-layout-pane</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Data attributes">
<SkillText><code>data-dominant</code> (<code>ns</code>, <code>we</code>), <code>data-center-min</code>, <code>data-collapsible</code>, <code>data-save</code>, <code>data-frame="none"</code>, <code>data-divider</code> (<code>dashed</code>, <code>dotted</code>, <code>double</code>, <code>thick</code>, <code>none</code>, <code>gap</code>), <code>data-grip</code> (<code>dots</code>, <code>bar</code>, <code>none</code>); on a region's resizer: <code>data-min</code> / <code>data-max</code>, <code>data-collapsible</code>, <code>data-divider</code>, <code>data-grip</code>; on a fixed region: <code>data-fit</code> with <code>--border-layout-fit-min</code> / <code>-max</code>; several Panels on one side: a <code>.border-layout-stack</code> as the pane (dividers between them, a panel's <code>data-min</code>; <code>data-direction</code> <code>row</code> / <code>column</code>, <code>data-exclusive</code> - one panel open, <code>data-keep</code> - the n opened last; deep navigation: <code>data-levels</code> with <code>--panel-size</code> per level, <code>data-drill</code>); <code>--border-layout-divider-color</code> / <code>-width</code>, <code>--border-layout-accent</code>; events <code>resizer-resize</code>, <code>border-layout-collapse</code>, <code>border-layout-stack-change</code>; API <code>df$.shadcn.borderLayout</code>.</SkillText>
  </SkillField>
</SkillPanel>

```html example label="Border layout" hint="Five regions on a grid: north and south span the width (the default, data-dominant='ns'), west and east sit between them around the center. Every side is a .resizer wrapping its pane - drag a line, or Tab to it and use the arrow keys (they move the line the way they point; Home / End jump to the limits). The center never drops below 120px."
<div class="border-layout" style="height: 22rem">
  <div class="resizer border-layout-north"
    ><header class="border-layout-pane" style="height: 3.25rem" aria-label="North"
      ><span class="text-sm font-medium">North</span
      ><span class="text-xs text-muted-foreground block">drag the line below</span></header
    ></div
  >
  <div class="resizer border-layout-west"
    ><nav class="border-layout-pane" style="width: 11rem" aria-label="West"
      ><span class="text-sm font-medium">West</span
      ><span class="text-xs text-muted-foreground block">drag the line →</span></nav
    ></div
  >
  <main class="border-layout-center border-layout-pane"
    ><span class="text-sm font-medium">Center</span
    ><span class="text-xs text-muted-foreground block">takes what the sides leave</span></main
  >
  <div class="resizer border-layout-east"
    ><aside class="border-layout-pane" style="width: 10rem" aria-label="East"
      ><span class="text-sm font-medium">East</span
      ><span class="text-xs text-muted-foreground block">← drag the line</span></aside
    ></div
  >
  <div class="resizer border-layout-south"
    ><footer class="border-layout-pane" style="height: 4.5rem" aria-label="South"
      ><span class="text-sm font-medium">South</span
      ><span class="text-xs text-muted-foreground block">drag the line above</span></footer
    ></div
  >
</div>
```

```html example label="West and east dominate" schema="none" hint="data-dominant='we': west and east run the full height, north and south sit between them above and below the center - the frame of an IDE with full-height sidebars."
<div class="border-layout" data-dominant="we" style="height: 22rem">
  <div class="resizer border-layout-north"
    ><header class="border-layout-pane" style="height: 3.25rem" aria-label="North"
      ><span class="text-sm font-medium">North</span
      ><span class="text-xs text-muted-foreground block">drag the line below</span></header
    ></div
  >
  <div class="resizer border-layout-west"
    ><nav class="border-layout-pane" style="width: 11rem" aria-label="West"
      ><span class="text-sm font-medium">West</span
      ><span class="text-xs text-muted-foreground block">drag the line →</span></nav
    ></div
  >
  <main class="border-layout-center border-layout-pane"
    ><span class="text-sm font-medium">Center</span
    ><span class="text-xs text-muted-foreground block">takes what the sides leave</span></main
  >
  <div class="resizer border-layout-east"
    ><aside class="border-layout-pane" style="width: 10rem" aria-label="East"
      ><span class="text-sm font-medium">East</span
      ><span class="text-xs text-muted-foreground block">← drag the line</span></aside
    ></div
  >
  <div class="resizer border-layout-south"
    ><footer class="border-layout-pane" style="height: 4.5rem" aria-label="South"
      ><span class="text-sm font-medium">South</span
      ><span class="text-xs text-muted-foreground block">drag the line above</span></footer
    ></div
  >
</div>
```

```html example label="Horizontal split" schema="none" hint="Just west and a center: two panes side by side, the regions left out take no room. The west pane starts at 50%; a drag writes px."
<div class="border-layout" style="height: 12rem">
  <div class="resizer border-layout-west"
    ><div class="border-layout-pane" style="width: 50%" aria-label="One"
      ><span class="text-sm font-medium">One</span></div
    ></div
  >
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Two</span></main>
</div>
```

```html example label="Vertical split" schema="none" hint="Just north and a center: two panes stacked."
<div class="border-layout" style="height: 16rem">
  <div class="resizer border-layout-north"
    ><div class="border-layout-pane" style="height: 50%" aria-label="One"
      ><span class="text-sm font-medium">One</span></div
    ></div
  >
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Two</span></main>
</div>
```

```html example label="Three columns" schema="none" hint="West, center, east - a mail client: folders, the list, the reading pane."
<div class="border-layout" style="height: 14rem">
  <div class="resizer border-layout-west"
    ><nav class="border-layout-pane" style="width: 9rem" aria-label="Folders"
      ><span class="text-sm font-medium">Folders</span></nav
    ></div
  >
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Messages</span></main>
  <div class="resizer border-layout-east"
    ><aside class="border-layout-pane" style="width: 40%" aria-label="Reading pane"
      ><span class="text-sm font-medium">Reading pane</span></aside
    ></div
  >
</div>
```

```html example label="Nested splits" schema="none" hint="A border layout in the center of another, with data-frame='none': a horizontal split whose right side is split vertically. Each divider belongs to its own layout."
<div class="border-layout" style="height: 18rem">
  <div class="resizer border-layout-west"
    ><nav class="border-layout-pane" style="width: 12rem" aria-label="Sidebar"
      ><span class="text-sm font-medium">Sidebar</span></nav
    ></div
  >
  <div class="border-layout-center">
    <div class="border-layout" data-frame="none" style="height: 100%">
      <div class="resizer border-layout-north"
        ><div class="border-layout-pane" style="height: 55%" aria-label="Editor"
          ><span class="text-sm font-medium">Editor</span></div
        ></div
      >
      <div class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Terminal</span></div>
    </div>
  </div>
</div>
```

```html example label="Regions that fit their content" schema="none" hint="data-fit on a fixed region (no resizer): it is as high as its content, between --border-layout-fit-min and --border-layout-fit-max (half the layout by default), and scrolls past the maximum. Add steps: the south grows until it reaches half the frame, then its list scrolls and the editor keeps the rest. The north keeps at least a fifth of the frame. CSS only - the layout is a size container for the bounds, so it takes its height from outside."
<div class="border-layout" style="height: 20rem">
  <header class="border-layout-north border-layout-pane" data-fit style="--border-layout-fit-min: 20cqh">
    <span class="text-sm font-medium">Toolbar - at least a fifth of the frame</span>
  </header>
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Editor</span></main>
  <footer class="border-layout-south border-layout-pane" data-fit>
    <div class="flex items-center justify-between gap-2 mb-2">
      <span class="text-sm font-medium">Steps</span>
      <button class="btn" data-size="sm" data-variant="outline" type="button" id="fit-add">Add a step</button>
    </div>
    <ol class="text-sm m-0" id="fit-steps">
      <li>Build</li>
      <li>Test</li>
    </ol>
  </footer>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    df$('#fit-add').on('click', () => {
      const steps = df$('#fit-steps');
      steps.append(df$(`<li>Step ${steps.children().toArray().length + 1}</li>`));
    });
  });
</script>
```

```html example label="Several panels on one side" schema="none" hint="A .border-layout-stack as the region's pane holds several Panels - top to bottom in west / east, side by side in north / south. Drag the line between two panels (or Tab to it and use the arrows) to share the room; minimize one and the others take its room; minimize all and the region folds to vertical tabs, like a single Panel. Maximize fills the layout."
<div class="border-layout" style="height: 26rem">
  <div class="resizer border-layout-west">
    <div class="border-layout-stack" style="width: 15rem" aria-label="Explorer">
      <section class="card panel" aria-labelledby="stk-files">
        <header class="panel-header">
          <i data-lucide="folder" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="stk-files">Files</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Files" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Files" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">src/, tests/, README.md</p></div>
      </section>
      <section class="card panel" aria-labelledby="stk-outline">
        <header class="panel-header">
          <i data-lucide="list-tree" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="stk-outline">Outline</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Outline" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Outline" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">init(), render(), save()</p></div>
      </section>
      <section class="card panel" aria-labelledby="stk-updates">
        <header class="panel-header">
          <i data-lucide="activity" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="stk-updates">Updates</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Updates" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Updates" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">Three files changed</p></div>
      </section>
    </div>
  </div>
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Editor</span></main>
  <div class="resizer border-layout-south">
    <div class="border-layout-stack" style="height: 7rem">
      <section class="card panel" aria-labelledby="stk-terminal">
        <header class="panel-header">
          <i data-lucide="terminal" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="stk-terminal">Terminal</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Terminal" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Terminal" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">bun run build</p></div>
      </section>
      <section class="card panel" aria-labelledby="stk-problems">
        <header class="panel-header">
          <i data-lucide="triangle-alert" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="stk-problems">Problems</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Problems" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Problems" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">No problems</p></div>
      </section>
    </div>
  </div>
</div>
```

```html example label="One panel open at a time" schema="none" hint="data-exclusive on the stack keeps one panel open, like an accordion: open one (its chevron, or a double-click on its tab) and the open one minimizes. Both start minimized here, so the east side starts as two vertical tabs; minimize the open one and it folds back."
<div class="border-layout" style="height: 20rem">
  <main class="border-layout-center border-layout-pane"
    ><p class="text-sm text-muted-foreground m-0">The center takes what the east side leaves.</p></main
  >
  <div class="resizer border-layout-east">
    <div class="border-layout-stack" style="width: 15rem" data-exclusive aria-label="Inspector and outline">
      <section class="card panel" aria-labelledby="one-inspector" data-minimized>
        <header class="panel-header">
          <i data-lucide="info" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="one-inspector">Inspector</h3>
          <div class="panel-tools">
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Inspector" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">width 240, height 120, fill: card</p></div>
      </section>
      <section class="card panel" aria-labelledby="one-outline" data-minimized>
        <header class="panel-header">
          <i data-lucide="list-tree" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="one-outline">Outline</h3>
          <div class="panel-tools">
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Outline" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">Header, Hero, Pricing, Footer</p></div>
      </section>
    </div>
  </div>
</div>
```

```html example label="Side by side in one region" schema="none" hint="data-direction='row' lays the stack's panels side by side on any side - here on the east, as columns. With data-exclusive one is open and the others are vertical tabs beside it; open a tab and the open column folds to its tab. data-direction='column' stacks them top to bottom in north / south."
<div class="border-layout" style="height: 20rem">
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Document</span></main>
  <div class="resizer border-layout-east">
    <div class="border-layout-stack" style="width: 24rem" data-direction="row" data-exclusive aria-label="Side tools">
      <section class="card panel" aria-labelledby="row-comments">
        <header class="panel-header">
          <i data-lucide="message-square" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="row-comments">Comments</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Comments" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Comments" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">Three open threads</p></div>
      </section>
      <section class="card panel" aria-labelledby="row-history" data-minimized>
        <header class="panel-header">
          <i data-lucide="history" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="row-history">History</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize History" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize History" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">Edited 2 minutes ago</p></div>
      </section>
      <section class="card panel" aria-labelledby="row-share" data-minimized>
        <header class="panel-header">
          <i data-lucide="users" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="row-share">Sharing</h3>
          <div class="panel-tools">
            <label class="swap panel-maximize">
              <input type="checkbox" aria-label="Maximize Sharing" />
              <span class="swap-off"><i data-lucide="maximize-2"></i></span>
              <span class="swap-on"><i data-lucide="minimize-2"></i></span>
            </label>
            <label class="swap panel-minimize">
              <input type="checkbox" aria-label="Minimize Sharing" />
              <span class="swap-off"><i data-lucide="chevron-up"></i></span>
              <span class="swap-on"><i data-lucide="chevron-down"></i></span>
            </label>
          </div>
        </header>
        <div class="panel-body"><p class="text-sm m-0">Four people can edit</p></div>
      </section>
    </div>
  </div>
</div>
```

```html example label="Deep navigation: levels side by side" schema="none" hint="A row stack with data-levels is a trail: each level keeps its own width and the region is their sum. Pick a section, then a book - every pick adds a level (push), data-keep='2' folds the earlier ones to bars, and the center gets their room. With data-drill a folded level is a breadcrumb: click its bar (or Tab to it, Enter) and the levels after it go."
<div class="border-layout" style="height: 22rem">
  <div
    class="border-layout-stack border-layout-west"
    id="lv-trail"
    data-direction="row"
    data-levels
    data-keep="2"
    data-drill
    aria-label="Library"
  >
    <section class="card panel" id="lv-sections" style="--panel-size: 11rem" aria-labelledby="lv-sections-t">
      <header class="panel-header">
        <i data-lucide="library" class="panel-icon" aria-hidden="true"></i>
        <h3 class="panel-title" id="lv-sections-t">Sections</h3>
        <div class="panel-tools">
          <label class="swap panel-minimize">
            <input type="checkbox" aria-label="Minimize Sections" />
            <span class="swap-off"><i data-lucide="chevron-left"></i></span>
            <span class="swap-on"><i data-lucide="chevron-right"></i></span>
          </label>
        </div>
      </header>
      <div class="panel-body">
        <div class="flex flex-col gap-1">
          <button class="btn justify-start" data-variant="ghost" data-size="sm" type="button" data-lv-section="Fiction"
            >Fiction</button
          >
          <button class="btn justify-start" data-variant="ghost" data-size="sm" type="button" data-lv-section="History"
            >History</button
          >
          <button class="btn justify-start" data-variant="ghost" data-size="sm" type="button" data-lv-section="Science"
            >Science</button
          >
        </div>
      </div>
    </section>
  </div>
  <main class="border-layout-center border-layout-pane">
    <div class="grid gap-2 text-sm">
      <span class="font-medium">Center</span>
      <output id="lv-out" class="text-muted-foreground">Pick a section</output>
    </div>
  </main>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const books = {
      Fiction: [
        ['Dune', 'Frank Herbert, 1965'],
        ['Emma', 'Jane Austen, 1815'],
        ['Ulysses', 'James Joyce, 1922'],
      ],
      History: [
        ['SPQR', 'Mary Beard, 2015'],
        ['Postwar', 'Tony Judt, 2005'],
        ['The Guns of August', 'Barbara Tuchman, 1962'],
      ],
      Science: [
        ['Cosmos', 'Carl Sagan, 1980'],
        ['The Gene', 'Siddhartha Mukherjee, 2016'],
        ['Silent Spring', 'Rachel Carson, 1962'],
      ],
    };
    const trail = df$('#lv-trail').get(0);
    const bl = df$.shadcn.borderLayout;
    const level = (id, title, icon, size, body) =>
      `<section class="card panel" id="${id}" style="--panel-size: ${size}" aria-labelledby="${id}-t">
        <header class="panel-header">
          <i data-lucide="${icon}" class="panel-icon" aria-hidden="true"></i>
          <h3 class="panel-title" id="${id}-t">${title}</h3>
          <div class="panel-tools"><label class="swap panel-minimize"><input type="checkbox" aria-label="Minimize ${title}" />
            <span class="swap-off"><i data-lucide="chevron-left"></i></span><span class="swap-on"><i data-lucide="chevron-right"></i></span></label></div>
        </header>
        <div class="panel-body">${body}</div>
      </section>`;
    const add = (markup) => {
      bl.push(trail, markup);
      globalThis.lucide?.createIcons();
    };
    df$(trail).on('click', (e) => {
      const section = e.target.closest('[data-lv-section]');
      const book = e.target.closest('[data-lv-book]');
      if (section) {
        const name = section.dataset.lvSection;
        bl.pop(trail, 0);
        const list = books[name]
          .map(
            ([t]) =>
              `<button class="btn justify-start" data-variant="ghost" data-size="sm" type="button" data-lv-book="${t}">${t}</button>`,
          )
          .join('');
        add(level('lv-items', name, 'folder', '12rem', `<div class="flex flex-col gap-1">${list}</div>`));
      } else if (book) {
        const name = book.dataset.lvBook;
        const by = Object.values(books)
          .flat()
          .find(([t]) => t === name)[1];
        bl.pop(trail, 1);
        add(level('lv-details', name, 'book-open', '14rem', `<p class="text-sm m-0">${by}</p>`));
      }
    });
    // the trail's levels: open ones by title, folded ones in brackets
    df$(trail).on('border-layout-stack-change', (e) => {
      const name = (p) => p.querySelector('.panel-title').textContent;
      df$('#lv-out').text(
        e.detail.panels.map((p) => (e.detail.open.includes(p) ? name(p) : '[' + name(p) + ']')).join(' / '),
      );
    });
  });
</script>
```

```html example label="Levels on the east side" schema="none" hint="On the east side the levels run from the edge toward the center - the deepest next to the center. Three levels are authored open with data-keep='2', so the outermost starts as a bar. Drag the line after a level to change its own width."
<div class="border-layout" style="height: 18rem">
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Editor</span></main>
  <div
    class="border-layout-stack border-layout-east"
    id="lv-east"
    data-direction="row"
    data-levels
    data-keep="2"
    aria-label="Inspector"
  >
    <section class="card panel" id="lv-project" style="--panel-size: 10rem" aria-labelledby="lv-project-t">
      <header class="panel-header">
        <i data-lucide="briefcase" class="panel-icon" aria-hidden="true"></i>
        <h3 class="panel-title" id="lv-project-t">Project</h3>
        <div class="panel-tools">
          <label class="swap panel-minimize">
            <input type="checkbox" aria-label="Minimize Project" />
            <span class="swap-off"><i data-lucide="chevron-left"></i></span>
            <span class="swap-on"><i data-lucide="chevron-right"></i></span>
          </label>
        </div>
      </header>
      <div class="panel-body"><p class="text-sm m-0">defuss-shadcn</p></div>
    </section>
    <section class="card panel" id="lv-folder" style="--panel-size: 10rem" aria-labelledby="lv-folder-t">
      <header class="panel-header">
        <i data-lucide="folder" class="panel-icon" aria-hidden="true"></i>
        <h3 class="panel-title" id="lv-folder-t">Folder</h3>
        <div class="panel-tools">
          <label class="swap panel-minimize">
            <input type="checkbox" aria-label="Minimize Folder" />
            <span class="swap-off"><i data-lucide="chevron-left"></i></span>
            <span class="swap-on"><i data-lucide="chevron-right"></i></span>
          </label>
        </div>
      </header>
      <div class="panel-body"><p class="text-sm m-0">src/components</p></div>
    </section>
    <section class="card panel" id="lv-file" style="--panel-size: 12rem" aria-labelledby="lv-file-t">
      <header class="panel-header">
        <i data-lucide="file" class="panel-icon" aria-hidden="true"></i>
        <h3 class="panel-title" id="lv-file-t">File</h3>
        <div class="panel-tools">
          <label class="swap panel-minimize">
            <input type="checkbox" aria-label="Minimize File" />
            <span class="swap-off"><i data-lucide="chevron-left"></i></span>
            <span class="swap-on"><i data-lucide="chevron-right"></i></span>
          </label>
        </div>
      </header>
      <div class="panel-body"><p class="text-sm m-0">border-layout.ts</p></div>
    </section>
  </div>
</div>
```

```html example label="Custom handle" schema="none" hint="The divider is a .resizer-handle: --border-layout-divider-color / -width / --border-layout-accent retheme it, and plain CSS on its ::before (the line) and ::after (the grip) makes any handle - here a bold primary rail with a round knob."
<style>
  .rail-layout {
    --border-layout-divider-color: color-mix(in oklch, var(--primary) 35%, transparent);
    --border-layout-divider-width: 3px;
    --border-layout-accent: var(--primary);
  }
  .rail-layout > .resizer > .resizer-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    translate: -50% -50%;
    width: 1rem;
    height: 1rem;
    border-radius: 999px;
    background: var(--primary);
    box-shadow:
      0 0 0 3px var(--background),
      var(--shadow-sm);
  }
</style>
<div class="border-layout rail-layout" style="height: 12rem">
  <div class="resizer border-layout-west"
    ><div class="border-layout-pane" style="width: 40%" aria-label="Custom"
      ><span class="text-sm font-medium">Custom</span></div
    ></div
  >
  <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  <div class="resizer border-layout-south"
    ><div class="border-layout-pane" style="height: 3.5rem" aria-label="South"
      ><span class="text-sm font-medium">South</span></div
    ></div
  >
</div>
```

```html example label="Grips" schema="none" hint="data-grip on the layout draws a handle on every divider: dots (a small dotted card) or bar (a pill); on one region's resizer it overrides the layout - data-grip='none' switches it off there."
<div class="flex flex-col gap-4">
  <div class="border-layout" data-grip="dots" style="height: 9rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 40%" aria-label="dots"
        ><span class="text-sm font-medium">dots</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
  <div class="border-layout" data-grip="bar" style="height: 9rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 40%" aria-label="bar"
        ><span class="text-sm font-medium">bar</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
    <div class="resizer border-layout-east" data-grip="none"
      ><div class="border-layout-pane" style="width: 25%" aria-label="no grip"
        ><span class="text-sm font-medium">no grip</span></div
      ></div
    >
  </div>
</div>
```

```html example label="Divider styles" schema="none" hint="data-divider: solid (the default), dashed, dotted, double, thick, none - invisible but still draggable - and gap, where the regions float as cards in a gutter and the divider lives in the gap. Set it on one region's resizer to style just that divider."
<div class="grid gap-3" style="grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr))">
  <div class="border-layout" data-divider="dashed" style="height: 8rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 45%" aria-label="dashed"
        ><span class="text-sm font-medium">dashed</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
  <div class="border-layout" data-divider="dotted" style="height: 8rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 45%" aria-label="dotted"
        ><span class="text-sm font-medium">dotted</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
  <div class="border-layout" data-divider="double" style="height: 8rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 45%" aria-label="double"
        ><span class="text-sm font-medium">double</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
  <div class="border-layout" data-divider="thick" style="height: 8rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 45%" aria-label="thick"
        ><span class="text-sm font-medium">thick</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
  <div class="border-layout" data-divider="none" data-grip="bar" style="height: 8rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 45%" aria-label="none"
        ><span class="text-sm font-medium">none</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
  <div class="border-layout" data-divider="gap" data-grip="bar" style="height: 8rem">
    <div class="resizer border-layout-west"
      ><div class="border-layout-pane" style="width: 45%" aria-label="gap"
        ><span class="text-sm font-medium">gap</span></div
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Center</span></main>
  </div>
</div>
```

```html example label="Collapsible and remembered" schema="none" hint="data-collapsible: double-click a divider (or focus it and press Enter) to fold its region away - the divider stays to bring it back, and dragging it unfolds. data-save='…' remembers sizes and folded regions across visits (a persisted store in localStorage) - resize, reload the page, it comes back as you left it. The buttons use df$.shadcn.borderLayout."
<div class="flex flex-col gap-2">
  <div class="flex flex-wrap items-center gap-2">
    <button class="btn" data-variant="outline" data-size="sm" type="button" data-toggle="west">Toggle west</button>
    <button class="btn" data-variant="outline" data-size="sm" type="button" data-toggle="south">Toggle south</button>
    <button class="btn" data-variant="ghost" data-size="sm" type="button" id="bl-reset">Reset</button>
    <output class="text-sm text-muted-foreground" id="bl-sizes"></output>
  </div>
  <div
    class="border-layout"
    id="bl-saved"
    data-collapsible
    data-save="docs-demo"
    data-grip="dots"
    style="height: 16rem"
  >
    <div class="resizer border-layout-west"
      ><nav class="border-layout-pane" style="width: 12rem" aria-label="Files"
        ><span class="text-sm font-medium">Files</span
        ><span class="text-xs text-muted-foreground block">double-click the divider</span></nav
      ></div
    >
    <main class="border-layout-center border-layout-pane"><span class="text-sm font-medium">Editor</span></main>
    <div class="resizer border-layout-south"
      ><footer class="border-layout-pane" style="height: 5rem" aria-label="Terminal"
        ><span class="text-sm font-medium">Terminal</span
        ><span class="text-xs text-muted-foreground block">Enter on the divider folds it</span></footer
      ></div
    >
  </div>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const layout = df$('#bl-saved').get(0);
    const show = () =>
      df$('#bl-sizes').text(
        Object.entries(df$.shadcn.borderLayout.sizes(layout))
          .map(([k, v]) => `${k} ${v}px`)
          .join(' · '),
      );
    df$('[data-toggle]').on('click', function () {
      df$.shadcn.borderLayout.toggle(layout, this.dataset.toggle);
    });
    df$('#bl-reset').on('click', () => layout.api.setState('default'));
    df$(layout).on('resizer-resize', show);
    df$(layout).on('border-layout-collapse', show);
    setTimeout(show, 50);
  });
</script>
```

```html example label="An application window" schema="none" height="36" hint="The frame of an app, in a Window: a menubar in the north, a file tree in the west, the editor in the center, an outline in the east and a terminal (a code mockup) in the south - west and east dominate. Every divider drags; View folds and unfolds the panels through df$.shadcn.borderLayout."
<div class="window-desktop" style="height: 30rem">
  <dialog
    class="window"
    open
    data-resizable
    style="--window-x: 0.75rem; --window-y: 0.75rem; --window-w: calc(100% - 1.5rem); --window-h: calc(100% - 1.5rem)"
  >
    <header class="window-titlebar">
      <i data-lucide="app-window" class="window-icon"></i>
      <h2 class="window-title">Studio - border-layout.css</h2>
      <form method="dialog" class="window-controls">
        <button type="button" class="window-minimize" aria-label="Minimize"></button>
        <button type="button" class="window-maximize" aria-label="Maximize"></button>
        <button class="window-close" aria-label="Close"></button>
      </form>
    </header>
    <div class="window-body" data-flush>
      <div class="border-layout" id="ide" data-dominant="we" data-frame="none" data-collapsible style="height: 100%">
        <div class="resizer border-layout-west"
          ><nav class="border-layout-pane" style="width: 11rem" aria-label="Files">
            <p class="text-xs text-muted-foreground m-0 mb-2">EXPLORER</p>
            <ul class="text-sm m-0 ps-4 flex flex-col gap-1"
              ><li>components/</li
              ><li>border-layout.css</li
              ><li>border-layout.ts</li
              ><li>resizer.ts</li></ul
            >
          </nav></div
        >
        <div
          class="border-layout-north"
          style="height: 2.5rem; display: flex; align-items: center; padding-inline: 0.25rem"
        >
          <div class="menubar" data-variant="ghost" role="menubar" aria-label="Studio" id="ide-menu">
            <button class="menubar-trigger" data-dropdown-trigger="ide-view">View</button>
            <div id="ide-view" role="menu" popover class="dropdown-content" aria-label="View" style="min-width: 12rem">
              <button role="menuitem" class="dropdown-item" tabindex="-1" data-value="west">Toggle files</button>
              <button role="menuitem" class="dropdown-item" tabindex="-1" data-value="east">Toggle outline</button>
              <button role="menuitem" class="dropdown-item" tabindex="-1" data-value="south">Toggle terminal</button>
              <div class="dropdown-separator" role="separator"></div>
              <button role="menuitem" class="dropdown-item" tabindex="-1" data-value="reset">Reset layout</button>
            </div>
          </div>
        </div>
        <main
          class="border-layout-center"
          style="
            background: #24292e;
            color: #e1e4e8;
            font: 13px/1.6 var(--font-mono);
            padding: 0.75rem 1rem;
            white-space: pre;
          "
          >.border-layout { display: grid; grid-template-areas: "west north east" "west center east" "west south east";
          }</main
        >
        <div class="resizer border-layout-east"
          ><aside class="border-layout-pane" style="width: 9rem" aria-label="Outline">
            <p class="text-xs text-muted-foreground m-0 mb-2">OUTLINE</p>
            <ul class="text-sm m-0 ps-4"
              ><li>.border-layout</li
              ><li>regions</li
              ><li>dividers</li></ul
            >
          </aside></div
        >
        <div class="resizer border-layout-south"
          ><div style="height: 6rem" aria-label="Terminal">
            <div class="mockup-code" data-chrome="none" data-size="sm" style="height: 100%; border-radius: 0">
              <pre data-prefix="$"><code>bun run e2e</code></pre>
              <pre data-prefix=">" data-tone="success"><code>border-layout.e2e: all checks passed</code></pre>
            </div>
          </div></div
        >
      </div>
    </div>
  </dialog>
</div>
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const layout = df$('#ide').get(0);
    df$('#ide-menu').on('dropdown:select', (e) => {
      if (e.detail.value === 'reset') layout.api.setState('default');
      else df$.shadcn.borderLayout.toggle(layout, e.detail.value);
    });
  });
</script>
```

<StatesSection>
  <p class="text-sm text-muted-foreground m-0 mb-3">Named states via the shared State API, driven per layout through the bound <code>api</code>:</p>
  <ul class="text-sm text-muted-foreground m-0 mb-3 ps-5">
    <li><code>default</code> - every region open; setting it restores the authored sizes</li>
    <li><code>collapsed</code> - one or more regions folded: <code>\{ regions: ['west', 'south'] \}</code> or <code>\{ region: 'west' \}</code></li>
  </ul>
  <p class="text-sm text-muted-foreground">The first example carries <code>data-state-demo</code>; <code>bun run screenshots</code> drives it via <code>el.api.setState(name)</code> and captures <code>screenshots/\{mode\}/border-layout-\{state\}.png</code>.</p>

Machine contract - verified against <a class="link" href="../schemas/border-layout.schema.json"><code>border-layout.schema.json</code></a> by <code>bun run verify</code>:

```states
| State | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `collapsed` | `boolean` | `true`, `false` | `false` | One or more regions folded away (the schema folds west); `default` opens them all. |
```

</StatesSection>

<ApiSection component="border-layout" />

<SourceFiles component="border-layout" section="css" />

<SourceFiles component="border-layout" section="js" jsTitle="JS" />

</DocPage>
