Panel
IPanel draws a bordered box around any renderable. It supports an inline header and footer, six border kinds, configurable padding, and an Expand mode for full-width layout.
![]()
When to use
- Highlighting a region of output - errors, warnings, summary boxes.
- Wrapping text or another widget so it visually stands apart.
- Grouping related fields with a heading.
Basic usage
pascal
AnsiConsole.Write(
Widgets.Panel(Widgets.Markup('[bold]hello[/] world'))
.WithHeader('Greeting')
.WithBorder(TBoxBorderKind.Rounded));1
2
3
4
2
3
4
Renders:
╭── Greeting ───────╮
│ hello world │
╰───────────────────╯1
2
3
2
3
The body can be any IRenderable:
pascal
panel := Widgets.Panel(table).WithHeader('Results');
panel := Widgets.Panel(tree).WithHeader('Project');
panel := Widgets.Panel(barChart).WithBorder(TBoxBorderKind.Heavy);1
2
3
2
3
Configuration
| Method | Purpose |
|---|---|
WithHeader(value) | Inline header rendered on the top border. Markup is supported. |
WithFooter(value) | Inline footer on the bottom border. |
WithBorder(kind) | Border glyphs — Square / Rounded / Heavy / Double / Ascii / None. |
WithBorder(value : IBoxBorder) | Pass a custom IBoxBorder instance. |
WithBorderStyle(value) | Style (colour / decorations) applied to the border characters. |
WithPadding(cells) | Inner whitespace around the body. Default 1. |
WithExpand(value) | When True the panel fills the available width. Default False (panel sizes to content). |
pascal
AnsiConsole.Write(
Widgets.Panel(Widgets.Markup('[lime]operational[/]'))
.WithHeader('[bold yellow]System status[/]')
.WithFooter('Last checked: 10:24 UTC')
.WithBorder(TBoxBorderKind.Heavy)
.WithBorderStyle(TAnsiStyle.Plain.WithForeground(TAnsiColor.Aqua))
.WithPadding(2)
.WithExpand(True));1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Composition
Panels nest:
pascal
AnsiConsole.Write(
Widgets.Panel(
Widgets.Panel(Widgets.Text('inner'))
.WithBorder(TBoxBorderKind.Square))
.WithHeader('outer')
.WithBorder(TBoxBorderKind.Rounded));1
2
3
4
5
6
2
3
4
5
6
A panel with a markup string body is shorthand:
pascal
// Equivalent to: Widgets.Panel(Widgets.Markup('[b]hi[/]')).WithHeader(...)
Widgets.Panel('[b]hi[/]').WithHeader('Greeting');1
2
2
API reference
Widgets.Panel(child)— wraps anyIRenderable.Widgets.Panel(markup)— markup-string shortcut.IPanel— full interface.- Demo:
demos/snippets/PanelRule.
See also
- Box border reference — every
TBoxBorderKindglyph. - Padder — when you only need padding and no border.
- Rule — for a separator without a body.
- Layout — when you need multiple panels arranged side-by-side.