Build an admin dashboard with Tailwind: a collapsing sidebar, top bar, stat cards, a bar chart made of divs, an orders table, search, an empty state and dark mode.
35 min read0/5 questions
Admin dashboards are some of the most common screens a front-end developer builds. Almost every product has one behind the login: a shop sees its orders, a school sees its classes, a support team sees its tickets. They look complicated, but they are made of a handful of repeating parts: a navigation sidebar, a top bar, number cards, a chart and a table. In this project you will build one for Roastery, a made-up online coffee shop, entirely with Tailwind. Each step has a live editor, and the last one puts everything together into a working dashboard with search, an empty state and a dark mode toggle.
Step 1: Plan the screen
Before writing classes, sketch the regions and decide how they behave on a small screen.
Sidebar: the logo and links to Overview, Orders, Products, Customers and Settings. On a wide screen it is a column on the left. On a narrow one it hides behind a Menu button.
Top bar: the page title, the theme toggle and the signed-in user.
Stat cards: four key numbers with their change since last week.
Chart: orders per day this week.
Orders table: recent orders with a coloured status badge, plus a search box.
A note on the previews. They are only about 400 to 600 pixels wide, so viewport prefixes like lg: would never switch on here. Instead, this project uses container queries: the dashboard sits in a box marked @container, and classes like @lg:flex respond to that box's width. Each stage that changes layout has Narrow and Wide buttons, and you can also drag the corner of the dashed box. In a real app you would usually use lg: for the page shell; container queries remain a great fit for panels that appear at different widths.
Step 2: The shell and a collapsing sidebar
The shell is a flex container. On narrow widths it is a column, so the sidebar (when open) sits above the content. From @lg (32rem, 512px) it becomes a row and the sidebar is always visible.
HTML + TailwindEdit the code, the preview updates live
Click Narrow: the sidebar hides and a Menu button appears. Click Menu to open it. Three classes do the work on the nav: hidden by default, @lg:flex on wide containers, and group-data-[open=true]:flex, which shows it whenever the parent marked group has data-open="true". The script only flips that data attribute and aria-expanded, which tells screen reader users whether the menu is open. Styling from a data attribute keeps the JavaScript tiny: it changes state, and the classes decide how state looks.
Quick check
Why does group-data-[open=true]:flex win over hidden on the same element?
Need a nudge? A hint rules out a wrong answer.
Step 3: Stat cards
Four numbers are the first thing people look at. Each card is a small definition: a label and a value, so a dl (description list) is a good semantic fit. The grid gives one column on tiny containers, two from @xs (20rem) and four from @2xl (42rem).
HTML + TailwindEdit the code, the preview updates live
tabular-nums makes every digit the same width, so numbers line up and do not jiggle when they update. Notice the change line says +8.2% and -3.1% in words and symbols, not only in green and red: about one in twelve men has some colour vision deficiency, and the sign carries the meaning for them. Drag the box narrower and watch the grid drop from two columns to one.
Step 4: A bar chart made of divs
For a simple chart you do not need a library. Each day is a list item, and each bar is a div whose height is a percentage of the column.
HTML + TailwindEdit the code, the preview updates live
The tallest day is scaled to 70 percent so the number above and the label below still fit, and every other bar is its value divided by 176, times 70. The busiest day is darker and bold. Change Monday to height: 65% and its bar jumps up.
Why style="height: 33%" and not a class? Because these numbers come from data. In a real app they arrive from an API, and Tailwind can only generate classes it finds written in your files. Data-driven values belong in style (or in a CSS variable read by a class like h-(--bar)). Classes are for design decisions that you know at build time.
The values are printed as text, so the chart works without hover and is readable by screen readers. For a chart with many points, a common approach is to also offer the numbers as a table.
Quick check
In React, your teammate builds each bar's class with a template literal that puts the data value inside h-[...%]. What happens?
Need a nudge? A hint rules out a wrong answer.
Step 5: An orders table with status badges
Tables are for tabular data, and orders are exactly that. Each status gets a badge: a small rounded label with a tinted background, darker text and a thin inset ring for definition.
HTML + TailwindEdit the code, the preview updates live
A few details carry a lot of weight here. scope="col" tells assistive technology that each th labels its column. Money is right-aligned with tabular-nums, so the decimal points line up. The Date column is hidden @sm:table-cell: less important columns disappear on narrow containers, and the outer overflow-x-auto lets the table scroll sideways rather than squash. Every badge has a word, so status never depends on colour alone. Drag the box narrow to watch the Date column go.
Match the pairs0/5 matched
Match each class to the job it does in the table.
Choose an item, then its match on the other side.
Step 6: Search and an empty state
A table that can be filtered also needs to say what happened when nothing matches. An empty state is the message and next step you show instead of a blank space. It is easy to forget and very noticeable when missing.
HTML + TailwindEdit the code, the preview updates live
<div class="max-w-md rounded-xl border border-slate-200 bg-white"> <div class="p-3"> <label for="q" class="sr-only">Search orders</label> <input id="q" type="search" placeholder="Try Maya, or zzz" class="w-full rounded-lg border border-slate-300 px-3 py-1.5 text-sm placeholder:text-slate-400 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-indigo-500"> </div> <ul id="list" class="divide-y divide-slate-100 text-sm"> <li class="px-4 py-2">#1048 Maya Chen</li> <li class="px-4 py-2">#1047 Tom Okafor</li> <li class="px-4 py-2">#1046 Lena Ruiz</li> </ul> <div id="empty" hidden class="m-3 rounded-lg border-2 border-dashed border-slate-200 p-6 text-center"> <p class="font-medium">No orders match <span id="term"></span></p> <p class="mt-1 text-sm text-slate-500">Try an order number or a customer name.</p> <button id="clear" class="mt-3 rounded-lg bg-slate-900 px-3 py-1.5 text-sm font-medium text-white hover:bg-slate-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500">Clear search</button> </div></div><script> const q = document.getElementById("q"); const items = [...document.querySelectorAll("#list li")]; function filter() { const text = q.value.trim().toLowerCase(); let shown = 0; for (const li of items) { li.hidden = !li.textContent.toLowerCase().includes(text); if (!li.hidden) shown++; } document.getElementById("empty").hidden = shown > 0; document.getElementById("term").textContent = '"' + q.value.trim() + '"'; } q.addEventListener("input", filter); document.getElementById("clear").addEventListener("click", () => { q.value = ""; filter(); q.focus(); });</script>
Preview
Type zzz and the empty state appears with a way out. Click Clear search and focus goes back to the input, so keyboard users are not left stranded. The search term is inserted with textContent, never innerHTML, so whatever someone types is treated as text and not as HTML. The label is sr-only: invisible on screen, but announced by screen readers, which a placeholder alone is not.
Step 7: Dark mode and states
The theme toggle uses the class strategy you saw in the layout and states lesson. One line switches dark: from following the operating system to following a .dark class:
@custom-variant dark (&:where(.dark, .dark *));
Then each surface gets a dark partner: bg-white dark:bg-slate-900, border-slate-200 dark:border-slate-800, text-slate-500 dark:text-slate-400. A few rules make dark mode look intentional rather than inverted:
Use layers of near-black, not pure black. The page is slate-950, cards are slate-900, hover rows are a little lighter again.
Lighten accents.text-emerald-700 is readable on white but too dark on slate; switch to dark:text-emerald-400.
Tint badges with opacity.dark:bg-emerald-400/10 keeps the hue while staying dark.
Every interactive element also needs its states. Links and buttons get hover: colours and a focus-visible: outline so keyboard users can always see where they are. With more than a few themes or many components, the semantic tokens approach from the design systems lesson (bg-surface, text-content) saves a lot of repeated dark: classes.
The full dashboard
Here is everything together. Try the Narrow and Wide buttons, open the menu, toggle dark mode, search the table for Lena and then for zzz, and press Tab to walk through the focus styles.
HTML + TailwindEdit the code, the preview updates live
Some things to try on your own: add a sixth row with a new Shipped status in sky blue, give the Overview link a small count badge, or change the chart to show revenue instead of orders. Each one is a few classes, because the structure already exists.
Put it in order6 steps
Put the order you built this dashboard in.
Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Step 8: Cutting it into React components
Notice how much repeats in that final file: five sidebar links with identical classes, four stat cards, seven bars, five rows, four badge styles. In HTML you copy and paste. In React each repeat becomes a component rendered from data in a loop, so the classes are written once.
The dashboard as React components
app/
dashboard/
layout.tsxDashboardShell around every page
page.tsxfetches stats, chart and orders
components/
dashboard/
DashboardShell.tsxclient: menu open state
SidebarNav.tsxlinks, highlights current page
TopBar.tsxtitle, ThemeToggle, avatar
StatCard.tsxlabel, value, change
BarChart.tsxbars from an array of numbers
OrdersTable.tsxclient: search and empty state
ui/
Badge.tsxstatus to classes map
ThemeToggle.tsxclient: toggles .dark
The boundaries follow two rules. First, a component per repeated shape: StatCard, a bar in BarChart, a row in OrdersTable, and Badge. Second, keep interactivity at the edges. Only the pieces with state need "use client": the shell (menu open or closed), the theme toggle and the searchable table. Stat cards and the chart can be server components that simply render data. The badge shows the variants map pattern from the previous lessons:
const STATUS = { paid: "bg-emerald-50 text-emerald-800 ring-emerald-600/20", pending: "bg-amber-50 text-amber-800 ring-amber-600/20", refunded: "bg-slate-100 text-slate-700 ring-slate-500/20", failed: "bg-red-50 text-red-800 ring-red-600/20",} as const;export function Badge({ status }: { status: keyof typeof STATUS }) { return ( <span className={cn("inline-flex rounded-full px-2 py-0.5 text-xs font-medium capitalize ring-1 ring-inset", STATUS[status])}> {status} </span> );}
Quick check
Which of these dashboard components most needs to be a client component?
Need a nudge? A hint rules out a wrong answer.
That is your third finished project, and the last one in this course. The wrap-up that follows lines up everything you have learned and walks through one real job that uses it all.
Key terms
dashboard
A screen that summarises key data, usually with navigation, number cards, charts and tables.
container query
A style that responds to a parent element's width instead of the viewport, written with @container and @sm: style variants.
empty state
The message and next action shown when a list or search has nothing to display.
status badge
A small label with a word and a colour that shows the state of an item, such as Paid or Failed.
tabular-nums
A Tailwind class that makes digits equal width so numbers line up in columns.
aria-expanded
An attribute that tells assistive technology whether a control's menu or panel is open.
client component
A React component that runs in the browser so it can hold state and handle events.