Split.js

1.6.5 · active · verified Sun Apr 19

Split.js is a lightweight, 2kb gzipped utility for creating resizeable split views in web applications. It is currently stable at version 1.6.5 and maintains a consistent release cadence with minor bug fixes and feature enhancements, as seen in recent 1.5.x releases. Key differentiators include its zero-dependency footprint, small size, and high performance due to its pure CSS resizing approach without attaching window event listeners. It is unopinionated, working well with various layout models like `float` and `flex`, and boasts broad browser compatibility, supporting IE9 and early versions of modern browsers. It provides a simple API to create and manage split panels, allowing developers to control initial sizes, minimum/maximum sizes, gutter behavior, and drag intervals.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic horizontal split view with three resizeable panels using Split.js, including initial sizing, minimum panel sizes, custom gutter styling, and event handlers for drag actions. It showcases typical setup for a modern web application using ES Modules.

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Split.js Quickstart</title>
  <style>
    #split-container {
      display: flex; /* Use flexbox for horizontal split */
      height: 300px;
      border: 1px solid #ccc;
      overflow: hidden;
    }
    .split-panel {
      background-color: #f0f0f0;
      padding: 15px;
      overflow: auto;
      flex-grow: 1; /* Allows panels to grow/shrink with split.js */
    }
    .gutter {
      background-color: #eee;
      background-repeat: no-repeat;
      background-position: 50%;
      cursor: col-resize; /* Default for horizontal splits */
    }
    .gutter.gutter-horizontal {
      background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAxCAYAAAB2M2UfAAAAABmJLR0QA/wD/AP+Ad/gAAAAwSURBVDjLYwCCDQgGAgEC/j+P/n/8A4gBCAB+0M2KBAmDAAGg9QYAAAEhB0oBAAEGAAAAAElFTkSuQmCC');
    }
  </style>
</head>
<body>
  <div id="split-container">
    <div id="panel-a" class="split-panel">Panel A</div>
    <div id="panel-b" class="split-panel">Panel B</div>
    <div id="panel-c" class="split-panel">Panel C</div>
  </div>

  <script type="module">
    import Split from 'split.js';

    document.addEventListener('DOMContentLoaded', () => {
      const split = Split(['#panel-a', '#panel-b', '#panel-c'], {
        sizes: [33, 33, 34], // Initial sizes in percentage
        minSize: 100,      // Minimum size for each panel in pixels
        gutterSize: 8,     // Size of the gutter in pixels
        cursor: 'col-resize', // Cursor to show when dragging (for horizontal)
        onDrag: (sizes) => {
          // console.log('Current sizes:', sizes);
        },
        onDragEnd: (sizes) => {
          // console.log('Final sizes:', sizes);
        }
      });

      // To dynamically change sizes (e.g., after an event)
      // setTimeout(() => {
      //   split.setSizes([20, 50, 30]);
      // }, 3000);

      // To destroy the split instance
      // setTimeout(() => {
      //   split.destroy();
      // }, 6000);
    });
  </script>
</body>
</html>

view raw JSON →