API Reference

boxen

Small utility that draws a box around text with configurable padding, margin, border style, and alignment.

Official Documentation ↗
CompatibilityThis documentation covers version v9.0.0. Check the official docs for the latest API surface.

Installation

npmnpm install boxen
pnpmpnpm add boxen

Methods

Overview

boxen draws a configurable box around text for CLI banners and alerts, with options for border style, padding, and alignment. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • boxen — Returns a string with the text wrapped in a box drawn with box-drawing characters.
  • borderStyle — Selects a predefined or custom border character set for the box.
  • padding — Controls the interior spacing between the border and the text.

Example

import boxen from 'boxen';

console.log(boxen('Hello', { padding: 1, borderStyle: 'round' }));

Notes

Recent versions are ESM-only, so require no longer works. Width defaults to the longest line plus padding, which can be forced.

Verification

Render text with a round border and confirm the output starts and ends with the expected box-drawing characters.

API reference evidence

Fetched from official sources on 2026-11-08T19:23:00+08:00 via WebFetch https://raw.githubusercontent.com/sindresorhus/boxen/main/index.d.ts;WebFetch https://raw.githubusercontent.com/sindresorhus/boxen/main/readme.md.

FAQ

Why does boxen fail with require?
Recent versions are ESM-only, so use a dynamic import('boxen') or make the calling module ESM.
How do I align multi-line text?
Set textAlignment to "left", "center", or "right"; the box width then follows the longest line or a set width.
How do I control the box width?
Pass width to set an explicit outer width, or let boxen size to the widest text line plus padding.