Badge#
A compact styled chip for status indicators, counts, and tags. Inherits all
Label kwargs but renders with a fixed pill or square shape.
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")
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")
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 direction: |
|
Grow to consume extra space in the parent. |
|
Alignment when the widget does not fill the available slot:
|
|
External spacing in pixels. Accepts an integer (equal on all
sides), a 2-tuple |
|
Horizontal external spacing (left and right). Accepts an integer
or a 2-tuple |
|
Vertical external spacing (top and bottom). Accepts an integer
or a 2-tuple |
Grid#
Used inside a Grid container.
|
Zero-based row and column indices. |
|
Number of rows or columns to span. |
|
Alignment and fill within the grid cell. Any combination of
|
|
External spacing in pixels. Accepts an integer, a 2-tuple
|
|
Horizontal external spacing. Accepts an integer or |
|
Vertical external spacing. Accepts an integer or |
API#
The complete reference for Badge lives on the
Widgets API page. At a glance:
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()