Badge#
A compact styled chip for status indicators, counts, and tags.
Usage#
A badge is a Label with a fixed pill or square shape — it takes all
the same kwargs (text, icon, font, accent), and accent= colors
it by status.
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#
# Square (default)
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")
# Pill
bs.Badge("Primary", accent="primary", variant="pill")
bs.Badge("Secondary", accent="secondary", variant="pill")
bs.Badge("Info", accent="info", variant="pill")
bs.Badge("Success", accent="success", variant="pill")
bs.Badge("Warning", accent="warning", variant="pill")
bs.Badge("Danger", accent="danger", variant="pill")
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.Row(gap=8, vertical_items="center"):
bs.Label("Inbox", font="heading-md")
bs.Badge("12", accent="primary", variant="pill")
with bs.Row(gap=8, vertical_items="center"):
bs.Label("Alerts", font="heading-md")
bs.Badge("3", accent="danger", variant="pill")
# Status in a data row
with bs.Row(gap=8, vertical_items="center"):
bs.Label("Run-A15")
bs.Badge("Complete", accent="success", variant="pill")
with bs.Row(gap=8, vertical_items="center"):
bs.Label("Run-A14")
bs.Badge("2 warnings", accent="warning")
bs.Badge("Fail", accent="danger", variant="pill")
Widget sizing#
All widgets accept self-placement kwargs via **kwargs. The parent
container determines which options apply — Column / Row parents use
the layout kwargs below, grid-based parents use grid kwargs.
Column (vertical layout)
Used inside a Column, App, or any other container with a column layout.
Children are arranged top-to-bottom, so horizontal aligns each child across
the width and grow shares the vertical space. (vertical does not apply —
the order of the children sets their top-to-bottom position.)
|
Cross-axis placement of the widget: |
|
Claim and fill a share of the leftover vertical space (the layout
direction). |
|
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 |
Row (horizontal layout)
Used inside a Row or any other container with a row layout. Children are
arranged left-to-right, so vertical aligns each child across the height and
grow shares the horizontal space. (horizontal does not apply — the order
of the children sets their left-to-right position.)
|
Cross-axis placement of the widget: |
|
Claim and fill a share of the leftover horizontal space (the layout
direction). |
|
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. |
|
Horizontal placement within the grid cell: |
|
Vertical placement within the grid cell: |
|
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.Row(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.Row(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.Row(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.Column(gap=8):
28 with bs.Row(gap=8):
29 bs.Label("Inbox", font="heading-md")
30 bs.Badge("12", accent="primary", variant="pill")
31
32 with bs.Row(gap=8):
33 bs.Label("Alerts", font="heading-md")
34 bs.Badge("3", accent="danger", variant="pill")
35
36 with bs.Row(gap=8):
37 bs.Label("Run-A15")
38 bs.Badge("Complete", accent="success", variant="pill")
39
40 with bs.Row(gap=8):
41 bs.Label("Run-A14")
42 bs.Badge("2 warnings", accent="warning")
43 bs.Badge("Fail", accent="danger", variant="pill")
44
45app.run()