Badge#

A compact styled chip for status indicators, counts, and tags. Inherits all Label kwargs but renders with a fixed pill or square shape.

Badge — light theme Badge — dark theme

Usage#

Variants#

'square' (default) gives a rounded rectangle. 'pill' gives a fully rounded capsule shape, common for counts and status tags.

bs.Badge("Square",  accent="primary")
bs.Badge("Pill",    accent="primary", variant="pill")
bs.Badge("99+",     accent="danger",  variant="pill")

Accent colors#

bs.Badge("Primary",   accent="primary")
bs.Badge("Secondary", accent="secondary")
bs.Badge("Info",      accent="info")
bs.Badge("Success",   accent="success")
bs.Badge("Warning",   accent="warning")
bs.Badge("Danger",    accent="danger")
Badge accent colors — light theme Badge accent colors — dark theme

In context#

Badges are commonly placed inline with other widgets — next to a title, in a table cell, or in a sidebar item.

# Next to a heading
with bs.HStack(gap=8, anchor_items="center"):
    bs.Label("Inbox", font="heading-md")
    bs.Badge("12", accent="primary", variant="pill")

# Status in a data row
with bs.HStack(gap=8, anchor_items="center"):
    bs.Label("Run-A15")
    bs.Badge("Complete", accent="success", variant="pill")
    bs.Badge("2 warnings", accent="warning")
Badge in context — light theme Badge in context — dark theme

Widget sizing#

All widgets accept self-placement kwargs via **kwargs. The parent container determines which options apply — stack-based parents use stack kwargs, grid-based parents use grid kwargs. Unrecognised keys are silently ignored.

Stack#

Used inside VStack, HStack, App, and other stack containers.

fill

Fill direction: 'x', 'y', 'both', or 'none'.

expand

Grow to consume extra space in the parent. True or False.

anchor

Alignment when the widget does not fill the available slot: 'n', 's', 'e', 'w', 'center', 'nw', etc.

margin

External spacing in pixels. Accepts an integer (equal on all sides), a 2-tuple (horizontal, vertical), or a 4-tuple (left, top, right, bottom).

margin_x

Horizontal external spacing (left and right). Accepts an integer or a 2-tuple (left, right) for asymmetric spacing. Overrides the horizontal component of margin=.

margin_y

Vertical external spacing (top and bottom). Accepts an integer or a 2-tuple (top, bottom) for asymmetric spacing. Overrides the vertical component of margin=.

Grid#

Used inside a Grid container.

row / column

Zero-based row and column indices.

rowspan / columnspan

Number of rows or columns to span.

sticky

Alignment and fill within the grid cell. Any combination of 'n', 's', 'e', 'w' — e.g. 'ew' stretches horizontally, 'nsew' fills the entire cell.

margin

External spacing in pixels. Accepts an integer, a 2-tuple (horizontal, vertical), or a 4-tuple (left, top, right, bottom).

margin_x

Horizontal external spacing. Accepts an integer or (left, right).

margin_y

Vertical external spacing. Accepts an integer or (top, bottom).

API#

The complete reference for Badge lives on the Widgets API page. At a glance:

Badge

Compact styled chip for status indicators, counts, and tags.

Full Example#

 1
 2with bs.App(title="Badge Demo", padding=20, gap=16) as app:
 3
 4    # Variants
 5    bs.Label("Variants", font="heading-sm")
 6    with bs.HStack(gap=8):
 7        bs.Badge("Square",  accent="primary")
 8        bs.Badge("Pill",    accent="primary",  variant="pill")
 9        bs.Badge("99+",     accent="danger",   variant="pill")
10        bs.Badge("New",     accent="success",  variant="pill")
11        bs.Badge("Beta",    accent="warning",  variant="pill")
12
13    # Accent colors — square
14    bs.Label("Accent Colors — Square", font="heading-sm")
15    with bs.HStack(gap=8):
16        for accent in ("primary", "secondary", "info", "success", "warning", "danger"):
17            bs.Badge(accent.title(), accent=accent)
18
19    # Accent colors — pill
20    bs.Label("Accent Colors — Pill", font="heading-sm")
21    with bs.HStack(gap=8):
22        for accent in ("primary", "secondary", "info", "success", "warning", "danger"):
23            bs.Badge(accent.title(), accent=accent, variant="pill")
24
25    # In context — heading with count
26    bs.Label("In Context", font="heading-sm")
27    with bs.VStack(gap=8):
28        with bs.HStack(gap=8, anchor_items="center"):
29            bs.Label("Inbox", font="heading-md")
30            bs.Badge("12", accent="primary", variant="pill")
31
32        with bs.HStack(gap=8, anchor_items="center"):
33            bs.Label("Alerts", font="heading-md")
34            bs.Badge("3", accent="danger", variant="pill")
35
36        with bs.HStack(gap=8, anchor_items="center"):
37            bs.Label("Run-A15")
38            bs.Badge("Complete", accent="success",  variant="pill")
39
40        with bs.HStack(gap=8, anchor_items="center"):
41            bs.Label("Run-A14")
42            bs.Badge("2 warnings", accent="warning")
43            bs.Badge("Fail",       accent="danger",  variant="pill")
44
45app.run()