# Dash Bootstrap Components: A Responsive Dashboard Layout in Python

> Dash Bootstrap Components tutorial with complete apps: dbc.Container, Row and Col with breakpoints, dbc.Card KPI cards, sidebar and tabs, dbc.Table, Bootswatch themes and matching Plotly figure templates.

Source: https://www.pythoncharts.com/plotly/dash-bootstrap-components/ | Published: 2026-12-06 | Author: Alex Scott | Category: Plotly | Tags: plotly, dash, dashboard, bootstrap, web app

To lay out a Dash dashboard without writing CSS, install `dash-bootstrap-components` and pass a Bootstrap theme to `Dash(external_stylesheets=[dbc.themes.FLATLY])`. Then build the page from `dbc.Container`, `dbc.Row` and `dbc.Col` (a 12-column responsive grid), with `dbc.Card` for tiles and `dbc.Tabs` for sections. The layout in [the intro Dash tutorial](https://www.pythoncharts.com/plotly/dash-tutorial-python-dashboard/) used inline flexbox styles. This post replaces those with Bootstrap's grid, which also stacks the columns on a phone.

Install both packages with `pip install dash dash-bootstrap-components dash-bootstrap-templates`. This post was run with Dash 4.5, `dash-bootstrap-components` 2.0 and `dash-bootstrap-templates` 3.0. The second package gives Plotly charts a template that matches the Bootstrap theme.

## Quick Example: KPI Cards and a Grid

This app shows 90 days of simulated support tickets for four teams (seeded, so you get the same numbers). A dropdown picks the team, three cards show the totals, and two charts share the row. Save it as `app.py`:

```python
import dash_bootstrap_components as dbc
import numpy as np
import pandas as pd
import plotly.express as px
from dash import Dash, Input, Output, callback, dcc, html
from dash_bootstrap_templates import load_figure_template

rng = np.random.default_rng(318)
# team: (tickets opened per weekday, average hours to resolve)
teams = {"Billing": (38, 5.5), "Technical": (62, 11.0), "Accounts": (27, 3.8), "Sales": (19, 7.0)}
days = pd.date_range("2026-09-07", periods=90)
weekday = np.where(days.dayofweek < 5, 1.0, 0.35)       # far fewer tickets at weekends

tickets = pd.concat([
    pd.DataFrame({"date": days, "team": team,
                  "opened": rng.poisson(rate * weekday),
                  "hours": hours * (1 + rng.normal(0, 0.12, len(days)))})
    for team, (rate, hours) in teams.items()
], ignore_index=True)

load_figure_template("flatly")                           # Plotly template matching the theme
app = Dash(external_stylesheets=[dbc.themes.FLATLY])

def kpi(label, value_id):
    return dbc.Card(dbc.CardBody([html.Div(label, className="text-muted"), html.H3(id=value_id)]))

app.layout = dbc.Container([
    html.H2("Support Desk", className="my-3"),
    dbc.Row(dbc.Col(dbc.Select(options=["All teams", *teams], value="All teams", id="team"), md=4),
            class_name="mb-3"),
    dbc.Row([
        dbc.Col(kpi("Tickets opened", "k-opened"), md=4),
        dbc.Col(kpi("Average hours to resolve", "k-hours"), md=4),
        dbc.Col(kpi("Busiest day", "k-busiest"), md=4),
    ], class_name="g-3 mb-3"),
    dbc.Row([
        dbc.Col(dcc.Graph(id="trend"), lg=8),
        dbc.Col(dcc.Graph(id="by-team"), lg=4),
    ], class_name="g-3"),
], class_name="pb-4")

@callback(
    Output("k-opened", "children"),
    Output("k-hours", "children"),
    Output("k-busiest", "children"),
    Output("trend", "figure"),
    Output("by-team", "figure"),
    Input("team", "value"),
)
def update(team):
    data = tickets if team == "All teams" else tickets[tickets["team"] == team]
    daily = data.groupby("date", as_index=False)["opened"].sum()
    daily["7-day average"] = daily["opened"].rolling(7).mean()
    hours = (data["opened"] * data["hours"]).sum() / data["opened"].sum()   # weighted by tickets
    busiest = daily.loc[daily["opened"].idxmax()]

    trend = px.line(daily, x="date", y="7-day average", title="Tickets opened (7-day average)",
                    labels={"date": "", "7-day average": ""})
    trend.update_traces(line_color="#f39c12")             # orange reads on light and dark themes
    trend.update_layout(height=340, margin=dict(l=40, r=10, t=50, b=30))

    per_team = tickets.groupby("team", as_index=False)["opened"].sum()
    per_team["selected"] = (per_team["team"] == team) | (team == "All teams")
    bars = px.bar(per_team, x="opened", y="team", color="selected", orientation="h",
                  title="Opened by team", labels={"opened": "", "team": ""},
                  color_discrete_map={True: "#18bc9c", False: "#cbd5d1"})
    bars.update_layout(height=340, showlegend=False, margin=dict(l=10, r=10, t=50, b=30))

    return (f"{data['opened'].sum():,}", f"{hours:.1f}",
            f"{busiest['date']:%b %d} ({busiest['opened']})", trend, bars)

if __name__ == "__main__":
    app.run(debug=True)
```

![Dash dashboard in the Flatly theme with a team dropdown, three KPI cards, a line chart of tickets opened per day and a bar chart of tickets by team](https://www.pythoncharts.com/plotly/dash-bootstrap-components/images/dash-bootstrap-quick-example.png)

Everything in the layout is a Bootstrap class or component:

- `dbc.Container` centers the content and limits its width. Pass `fluid=True` to use the full window.
- `dbc.Row` and `dbc.Col` form the grid. Each row has 12 columns, and `md=4` means "four columns wide from the medium breakpoint up".
- `class_name="g-3"` on a row adds a gap between its columns, and `my-3`, `mb-3` and `pb-4` are Bootstrap's margin and padding utilities.
- `dbc.Select` is a styled `<select>`. Use `dcc.Dropdown` instead when you need search or multi-select.

## How Does the 12-Column Grid Work?

A row holds 12 units of width. The width keywords on `dbc.Col` are breakpoints, and each one applies from that window width upward:

| Keyword | Applies from | Example |
|---|---|---|
| `xs` | any width | `xs=12` fills the row |
| `sm` | 576 px | `sm=6` is half the row |
| `md` | 768 px | `md=4` is a third of the row |
| `lg` | 992 px | `lg=8` is two thirds |
| `xl` | 1200 px | |
| `xxl` | 1400 px | |

Below its breakpoint a column takes the full width, so it stacks. In the Quick Example the cards stack below 768 px and the charts below 992 px. At a phone width of 420 px the same app looks like this:

![The same Dash dashboard at phone width with the dropdown, three KPI cards and two charts stacked in one column](https://www.pythoncharts.com/plotly/dash-bootstrap-components/images/dash-bootstrap-narrow.png)

Pass several keywords to change the layout as the window grows, for example `dbc.Col(..., xs=12, md=6, lg=4)` for one, two, then three cards per row. A column with no width keyword (`dbc.Col(...)`) shares the leftover space equally.

## Sidebar, Tabs and a Table

For a dashboard with controls on the left, use a narrow column for filters and a wide one for tabbed content. The callback returns one value for each `Output`, as before. Replace everything from `app = Dash(...)` down in the Quick Example:

```python
app = Dash(external_stylesheets=[dbc.themes.FLATLY])

sidebar = dbc.Col([
    html.H5("Filters"),
    dbc.Label("Teams"),
    dbc.Checklist(options=list(teams), value=list(teams), id="teams"),
    html.Hr(),
    dbc.Label("Metric"),
    dbc.RadioItems(options={"opened": "Tickets opened", "hours": "Hours to resolve"},
                   value="opened", id="metric"),
], md=3, class_name="bg-light p-3")

app.layout = dbc.Container([
    html.H2("Support Desk", className="my-3"),
    dbc.Row([
        sidebar,
        dbc.Col(dbc.Tabs([
            dbc.Tab(dcc.Graph(id="weekly"), label="Weekly"),
            dbc.Tab(dcc.Graph(id="weekday"), label="By weekday"),
            dbc.Tab(html.Div(id="table", className="pt-3"), label="Table"),
        ]), md=9),
    ], class_name="g-4"),
], class_name="pb-4")

@callback(
    Output("weekly", "figure"),
    Output("weekday", "figure"),
    Output("table", "children"),
    Input("teams", "value"),
    Input("metric", "value"),
)
def update(picked, metric):
    data = tickets[tickets["team"].isin(picked)].copy()
    data["weekday"] = data["date"].dt.day_name()
    agg = "sum" if metric == "opened" else "mean"
    label = "Tickets opened" if metric == "opened" else "Hours to resolve (mean)"

    weekly = data.groupby([pd.Grouper(key="date", freq="W-MON"), "team"])[metric].agg(agg).reset_index()
    weekly_fig = px.line(weekly, x="date", y=metric, color="team", title=f"{label} per week",
                         labels={"date": "", metric: "", "team": ""})

    order = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
    by_day = data.groupby("weekday")[metric].agg(agg).reindex(order).reset_index()
    weekday_fig = px.bar(by_day, x="weekday", y=metric, title=f"{label} by weekday",
                         labels={"weekday": "", metric: ""})

    summary = data.groupby("team").agg(opened=("opened", "sum"), hours=("hours", "mean")).round(1)
    table = dbc.Table.from_dataframe(summary.reset_index(), striped=True, hover=True)
    return weekly_fig, weekday_fig, table

if __name__ == "__main__":
    app.run(debug=True)
```

![Dash dashboard with a filter sidebar of team checkboxes and metric radio buttons next to a tab strip, with the By weekday tab showing a bar chart of tickets opened by day of the week](https://www.pythoncharts.com/plotly/dash-bootstrap-components/images/dash-bootstrap-sidebar-tabs.png)

`dbc.Tabs` shows one `dbc.Tab` at a time, and the callback fills all of them, including the hidden ones. That works for a few charts. If a tab holds something slow, let the tab decide what to build: give `dbc.Tabs` an `id`, make its `active_tab` an `Input`, and return the content for the active tab only (give each `dbc.Tab` a `tab_id`).

`dbc.Table.from_dataframe()` turns a small data frame into a Bootstrap table. For hundreds of rows, with sorting and filtering, use [Dash AG Grid](https://www.pythoncharts.com/plotly/dash-ag-grid/) instead.

## Switch the Theme, and the Charts Follow

A Bootstrap theme restyles the page, but Plotly charts keep their own white background and fonts. `load_figure_template("flatly")` from `dash-bootstrap-templates` registers a Plotly template with the theme's colors and fonts and makes it the default for every figure. To change the theme, change two lines in the Quick Example, the figure template and the stylesheet:

```python
load_figure_template("darkly")
app = Dash(external_stylesheets=[dbc.themes.DARKLY])
```

![The support dashboard in the dark Darkly theme with dark cards and charts that match the page](https://www.pythoncharts.com/plotly/dash-bootstrap-components/images/dash-bootstrap-darkly.png)

Without `load_figure_template`, the dark page would show white chart rectangles. The name is the lowercase name of a [Bootswatch](https://bootswatch.com/) theme. A few that suit dashboards:

![Four copies of the same dashboard in the Flatly, Darkly, Lux and Minty themes](https://www.pythoncharts.com/plotly/dash-bootstrap-components/images/dash-bootstrap-themes.png)

`dbc.themes` holds more than 20 of them (`FLATLY`, `DARKLY`, `LUX`, `MINTY`, `CYBORG`, `SLATE`, `ZEPHYR` and others). Use a dark theme only if you also want dark charts, and check that your chart colors still have enough contrast on the dark background.

## dbc vs Inline Styles vs Your Own CSS

| | `dash-bootstrap-components` | Inline `style={...}` | CSS in `assets/` |
|---|---|---|---|
| Responsive grid | Built in (`Row`, `Col`, breakpoints) | Flexbox by hand | Media queries by hand |
| Ready-made parts | Cards, tabs, navbars, modals, alerts | None | Whatever you write |
| Theming | One stylesheet, 20+ themes | Per component | Per rule |
| Extra dependency | Yes | No | No |
| Best for | Dashboards that need to look good fast | Tiny apps | Custom designs |

## Practical Tips

- **Use `class_name` on dbc components and `className` on `html` components.** The `html` components raise a `TypeError` for `class_name`.
- **Set the theme in one place.** Pass the stylesheet to `Dash(external_stylesheets=...)` and call `load_figure_template` with the matching name.
- **Give charts a fixed height.** `fig.update_layout(height=340)` keeps cards in a row the same height. Charts in a column otherwise take their height from the figure.
- **Test the stacked layout.** Narrow the browser window below 768 px and check that nothing overflows.
- **A table is not a dashboard.** `dbc.Table` is for a small summary. For large tables, use a data grid instead.

## Similar Topics

- [Dash Tutorial: Build Your First Dashboard in Python](https://www.pythoncharts.com/plotly/dash-tutorial-python-dashboard/)
- [Dash Callbacks: Chained Dropdowns, Pattern-Matching, Store and Clientside](https://www.pythoncharts.com/plotly/dash-callbacks/)
- [How to Build a KPI Dashboard in Streamlit](https://www.pythoncharts.com/streamlit/streamlit-kpi-dashboard/)
