Skip to content

Lesson 51 of 52Project

Project: A Tailwind Dashboard

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.

  1. 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.
  2. Top bar: the page title, the theme toggle and the signed-in user.
  3. Stat cards: four key numbers with their change since last week.
  4. Chart: orders per day this week.
  5. 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 + Tailwind
<div class="mb-2 flex gap-2 text-xs"> <button data-width="340px" class="rounded border border-slate-300 px-2 py-1">Narrow</button> <button data-width="100%" class="rounded border border-slate-300 px-2 py-1">Wide</button></div><div id="frame" class="@container resize-x overflow-auto border border-dashed border-slate-300" style="width: 100%"> <div id="shell" data-open="false" class="group flex min-h-72 flex-col bg-slate-100 @lg:flex-row"> <nav id="sidebar" aria-label="Main" class="hidden shrink-0 flex-col gap-1 border-b border-slate-200 bg-white p-3 group-data-[open=true]:flex @lg:flex @lg:w-44 @lg:border-r @lg:border-b-0"> <p class="px-2 pb-2 font-bold tracking-tight">Roastery</p> <a href="#" aria-current="page" class="rounded-md bg-slate-900 px-2 py-1.5 text-sm font-medium text-white">Overview</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900">Orders</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900">Products</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900">Customers</a> </nav> <div class="flex min-w-0 flex-1 flex-col"> <header class="flex items-center gap-3 border-b border-slate-200 bg-white px-4 py-3"> <button id="menu" aria-expanded="false" aria-controls="sidebar" class="rounded-md border border-slate-300 px-2 py-1 text-sm @lg:hidden">Menu</button> <h1 class="font-semibold">Overview</h1> </header> <main class="flex-1 p-4 text-sm text-slate-500">Content goes here.</main> </div> </div></div><script> const frame = document.getElementById("frame"); document.querySelectorAll("[data-width]").forEach((b) => b.addEventListener("click", () => { frame.style.width = b.dataset.width; }) ); const shell = document.getElementById("shell"); const menu = document.getElementById("menu"); menu.addEventListener("click", () => { const open = shell.dataset.open !== "true"; shell.dataset.open = String(open); menu.setAttribute("aria-expanded", String(open)); });</script>

Preview

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 + Tailwind
<div class="@container resize-x overflow-auto border border-dashed border-slate-300 bg-slate-100 p-3" style="width: 100%"> <dl class="grid grid-cols-1 gap-3 @xs:grid-cols-2 @2xl:grid-cols-4"> <div class="rounded-xl border border-slate-200 bg-white p-4"> <dt class="text-xs font-medium text-slate-500">Revenue</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">$12,480</dd> <dd class="mt-1 text-xs font-medium text-emerald-700">+8.2% <span class="font-normal text-slate-500">vs last week</span></dd> </div> <div class="rounded-xl border border-slate-200 bg-white p-4"> <dt class="text-xs font-medium text-slate-500">Orders</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">857</dd> <dd class="mt-1 text-xs font-medium text-emerald-700">+12.5% <span class="font-normal text-slate-500">vs last week</span></dd> </div> <div class="rounded-xl border border-slate-200 bg-white p-4"> <dt class="text-xs font-medium text-slate-500">Average order</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">$14.56</dd> <dd class="mt-1 text-xs font-medium text-red-700">-3.1% <span class="font-normal text-slate-500">vs last week</span></dd> </div> <div class="rounded-xl border border-slate-200 bg-white p-4"> <dt class="text-xs font-medium text-slate-500">Refunds</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">6</dd> <dd class="mt-1 text-xs font-medium text-slate-600">2 fewer <span class="font-normal text-slate-500">vs last week</span></dd> </div> </dl></div>

Preview

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 + Tailwind
<section aria-labelledby="chart-title" class="max-w-md rounded-xl border border-slate-200 bg-white p-4"> <div class="flex items-baseline justify-between"> <h2 id="chart-title" class="font-semibold">Orders this week</h2> <p class="text-xs text-slate-500">857 total</p> </div> <ol aria-label="Orders per day, Monday to Sunday" class="mt-4 flex h-44 items-end gap-2"> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500">84</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500" style="height: 33%"></div><span class="text-xs text-slate-600">Mon</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500">102</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500" style="height: 41%"></div><span class="text-xs text-slate-600">Tue</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500">96</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500" style="height: 38%"></div><span class="text-xs text-slate-600">Wed</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500">131</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500" style="height: 52%"></div><span class="text-xs text-slate-600">Thu</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500">148</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500" style="height: 59%"></div><span class="text-xs text-slate-600">Fri</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs font-semibold tabular-nums text-slate-900">176</span><div class="w-full rounded-t-md bg-indigo-600" style="height: 70%"></div><span class="text-xs font-semibold text-slate-900">Sat</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500">120</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500" style="height: 48%"></div><span class="text-xs text-slate-600">Sun</span></li> </ol></section>

Preview

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 + Tailwind
<div class="@container resize-x overflow-auto border border-dashed border-slate-300" style="width: 100%"> <div class="overflow-x-auto rounded-xl border border-slate-200 bg-white"> <table class="w-full text-left text-sm"> <thead class="border-b border-slate-200 bg-slate-50 text-xs uppercase tracking-wide text-slate-500"> <tr> <th scope="col" class="px-4 py-2 font-medium">Order</th> <th scope="col" class="px-4 py-2 font-medium">Customer</th> <th scope="col" class="hidden px-4 py-2 font-medium @sm:table-cell">Date</th> <th scope="col" class="px-4 py-2 text-right font-medium">Total</th> <th scope="col" class="px-4 py-2 font-medium">Status</th> </tr> </thead> <tbody class="divide-y divide-slate-100"> <tr class="hover:bg-slate-50"><td class="px-4 py-2.5 font-medium">#1048</td><td class="px-4 py-2.5">Maya Chen</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell">Oct 21</td><td class="px-4 py-2.5 text-right tabular-nums">$42.00</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-800 ring-1 ring-emerald-600/20 ring-inset">Paid</span></td></tr> <tr class="hover:bg-slate-50"><td class="px-4 py-2.5 font-medium">#1047</td><td class="px-4 py-2.5">Tom Okafor</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell">Oct 21</td><td class="px-4 py-2.5 text-right tabular-nums">$18.50</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-800 ring-1 ring-amber-600/20 ring-inset">Pending</span></td></tr> <tr class="hover:bg-slate-50"><td class="px-4 py-2.5 font-medium">#1046</td><td class="px-4 py-2.5">Lena Ruiz</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell">Oct 20</td><td class="px-4 py-2.5 text-right tabular-nums">$27.00</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-700 ring-1 ring-slate-500/20 ring-inset">Refunded</span></td></tr> <tr class="hover:bg-slate-50"><td class="px-4 py-2.5 font-medium">#1045</td><td class="px-4 py-2.5">Sam Patel</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell">Oct 20</td><td class="px-4 py-2.5 text-right tabular-nums">$64.25</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-red-50 px-2 py-0.5 text-xs font-medium text-red-800 ring-1 ring-red-600/20 ring-inset">Failed</span></td></tr> </tbody> </table> </div></div>

Preview

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 + Tailwind
<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 + Tailwind
<style type="text/tailwindcss"> @custom-variant dark (&:where(.dark, .dark *));</style><div class="mb-2 flex gap-2 text-xs"> <button data-width="340px" class="rounded border border-slate-300 px-2 py-1">Narrow</button> <button data-width="100%" class="rounded border border-slate-300 px-2 py-1">Wide</button></div><div id="frame" class="@container resize-x overflow-auto border border-dashed border-slate-300" style="width: 100%"> <div id="shell" data-open="false" class="group flex min-h-[44rem] flex-col bg-slate-100 text-slate-900 @lg:flex-row dark:bg-slate-950 dark:text-slate-100"> <nav id="sidebar" aria-label="Main" class="hidden shrink-0 flex-col gap-1 border-b border-slate-200 bg-white p-3 group-data-[open=true]:flex @lg:flex @lg:w-44 @lg:border-r @lg:border-b-0 dark:border-slate-800 dark:bg-slate-900"> <p class="px-2 pb-2 font-bold tracking-tight">Roastery</p> <a href="#" aria-current="page" class="rounded-md bg-slate-900 px-2 py-1.5 text-sm font-medium text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500 dark:bg-white dark:text-slate-900">Overview</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900 focus-visible:outline-2 focus-visible:outline-indigo-500 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white">Orders</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900 focus-visible:outline-2 focus-visible:outline-indigo-500 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white">Products</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900 focus-visible:outline-2 focus-visible:outline-indigo-500 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white">Customers</a> <a href="#" class="rounded-md px-2 py-1.5 text-sm text-slate-600 hover:bg-slate-100 hover:text-slate-900 focus-visible:outline-2 focus-visible:outline-indigo-500 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white">Settings</a> </nav> <div class="flex min-w-0 flex-1 flex-col"> <header class="flex items-center gap-3 border-b border-slate-200 bg-white px-4 py-3 dark:border-slate-800 dark:bg-slate-900"> <button id="menu" aria-expanded="false" aria-controls="sidebar" class="rounded-md border border-slate-300 px-2 py-1 text-sm hover:bg-slate-100 focus-visible:outline-2 focus-visible:outline-indigo-500 @lg:hidden dark:border-slate-700 dark:hover:bg-slate-800">Menu</button> <h1 class="font-semibold">Overview</h1> <button id="theme" aria-pressed="false" class="ml-auto rounded-md border border-slate-300 px-2 py-1 text-sm hover:bg-slate-100 focus-visible:outline-2 focus-visible:outline-indigo-500 dark:border-slate-700 dark:hover:bg-slate-800">Dark mode</button> <span aria-hidden="true" class="grid size-8 shrink-0 place-items-center rounded-full bg-indigo-600 text-xs font-semibold text-white">AK</span> </header> <main class="@container flex flex-1 flex-col gap-4 p-4"> <dl class="grid grid-cols-1 gap-3 @xs:grid-cols-2 @2xl:grid-cols-4"> <div class="rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900"> <dt class="text-xs font-medium text-slate-500 dark:text-slate-400">Revenue</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">$12,480</dd> <dd class="mt-1 text-xs font-medium text-emerald-700 dark:text-emerald-400">+8.2% <span class="font-normal text-slate-500 dark:text-slate-400">vs last week</span></dd> </div> <div class="rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900"> <dt class="text-xs font-medium text-slate-500 dark:text-slate-400">Orders</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">857</dd> <dd class="mt-1 text-xs font-medium text-emerald-700 dark:text-emerald-400">+12.5% <span class="font-normal text-slate-500 dark:text-slate-400">vs last week</span></dd> </div> <div class="rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900"> <dt class="text-xs font-medium text-slate-500 dark:text-slate-400">Average order</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">$14.56</dd> <dd class="mt-1 text-xs font-medium text-red-700 dark:text-red-400">-3.1% <span class="font-normal text-slate-500 dark:text-slate-400">vs last week</span></dd> </div> <div class="rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900"> <dt class="text-xs font-medium text-slate-500 dark:text-slate-400">Refunds</dt> <dd class="mt-1 text-2xl font-semibold tabular-nums">6</dd> <dd class="mt-1 text-xs font-medium text-slate-600 dark:text-slate-300">2 fewer <span class="font-normal text-slate-500 dark:text-slate-400">vs last week</span></dd> </div> </dl> <section aria-labelledby="chart-title" class="rounded-xl border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900"> <div class="flex items-baseline justify-between"> <h2 id="chart-title" class="font-semibold">Orders this week</h2> <p class="text-xs text-slate-500 dark:text-slate-400">857 total</p> </div> <ol aria-label="Orders per day, Monday to Sunday" class="mt-4 flex h-44 items-end gap-2"> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500 dark:text-slate-400">84</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500 dark:bg-indigo-400/40 dark:hover:bg-indigo-400" style="height: 33%"></div><span class="text-xs text-slate-600 dark:text-slate-400">Mon</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500 dark:text-slate-400">102</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500 dark:bg-indigo-400/40 dark:hover:bg-indigo-400" style="height: 41%"></div><span class="text-xs text-slate-600 dark:text-slate-400">Tue</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500 dark:text-slate-400">96</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500 dark:bg-indigo-400/40 dark:hover:bg-indigo-400" style="height: 38%"></div><span class="text-xs text-slate-600 dark:text-slate-400">Wed</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500 dark:text-slate-400">131</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500 dark:bg-indigo-400/40 dark:hover:bg-indigo-400" style="height: 52%"></div><span class="text-xs text-slate-600 dark:text-slate-400">Thu</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500 dark:text-slate-400">148</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500 dark:bg-indigo-400/40 dark:hover:bg-indigo-400" style="height: 59%"></div><span class="text-xs text-slate-600 dark:text-slate-400">Fri</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs font-semibold tabular-nums">176</span><div class="w-full rounded-t-md bg-indigo-600 dark:bg-indigo-400" style="height: 70%"></div><span class="text-xs font-semibold">Sat</span></li> <li class="flex h-full flex-1 flex-col items-center justify-end gap-1"><span class="text-xs tabular-nums text-slate-500 dark:text-slate-400">120</span><div class="w-full rounded-t-md bg-indigo-300 hover:bg-indigo-500 dark:bg-indigo-400/40 dark:hover:bg-indigo-400" style="height: 48%"></div><span class="text-xs text-slate-600 dark:text-slate-400">Sun</span></li> </ol> </section> <section aria-labelledby="orders-title" class="rounded-xl border border-slate-200 bg-white dark:border-slate-800 dark:bg-slate-900"> <div class="flex flex-wrap items-center justify-between gap-2 p-4"> <h2 id="orders-title" class="font-semibold">Recent orders</h2> <div class="w-full @sm:w-56"> <label for="search" class="sr-only">Search orders</label> <input id="search" type="search" placeholder="Search orders" class="w-full rounded-lg border border-slate-300 bg-white 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 dark:border-slate-700 dark:bg-slate-950 dark:placeholder:text-slate-500"> </div> </div> <div id="table-wrap" class="overflow-x-auto"> <table class="w-full text-left text-sm"> <thead class="border-y border-slate-200 bg-slate-50 text-xs uppercase tracking-wide text-slate-500 dark:border-slate-800 dark:bg-slate-950/50 dark:text-slate-400"> <tr> <th scope="col" class="px-4 py-2 font-medium">Order</th> <th scope="col" class="px-4 py-2 font-medium">Customer</th> <th scope="col" class="hidden px-4 py-2 font-medium @sm:table-cell">Date</th> <th scope="col" class="px-4 py-2 text-right font-medium">Total</th> <th scope="col" class="px-4 py-2 font-medium">Status</th> </tr> </thead> <tbody id="rows" class="divide-y divide-slate-100 dark:divide-slate-800"> <tr class="hover:bg-slate-50 dark:hover:bg-slate-800/50"><td class="px-4 py-2.5 font-medium">#1048</td><td class="px-4 py-2.5">Maya Chen</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell dark:text-slate-400">Oct 21</td><td class="px-4 py-2.5 text-right tabular-nums">$42.00</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-800 ring-1 ring-emerald-600/20 ring-inset dark:bg-emerald-400/10 dark:text-emerald-300 dark:ring-emerald-400/30">Paid</span></td></tr> <tr class="hover:bg-slate-50 dark:hover:bg-slate-800/50"><td class="px-4 py-2.5 font-medium">#1047</td><td class="px-4 py-2.5">Tom Okafor</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell dark:text-slate-400">Oct 21</td><td class="px-4 py-2.5 text-right tabular-nums">$18.50</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-amber-50 px-2 py-0.5 text-xs font-medium text-amber-800 ring-1 ring-amber-600/20 ring-inset dark:bg-amber-400/10 dark:text-amber-300 dark:ring-amber-400/30">Pending</span></td></tr> <tr class="hover:bg-slate-50 dark:hover:bg-slate-800/50"><td class="px-4 py-2.5 font-medium">#1046</td><td class="px-4 py-2.5">Lena Ruiz</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell dark:text-slate-400">Oct 20</td><td class="px-4 py-2.5 text-right tabular-nums">$27.00</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-700 ring-1 ring-slate-500/20 ring-inset dark:bg-slate-400/10 dark:text-slate-300 dark:ring-slate-400/30">Refunded</span></td></tr> <tr class="hover:bg-slate-50 dark:hover:bg-slate-800/50"><td class="px-4 py-2.5 font-medium">#1045</td><td class="px-4 py-2.5">Sam Patel</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell dark:text-slate-400">Oct 20</td><td class="px-4 py-2.5 text-right tabular-nums">$64.25</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-red-50 px-2 py-0.5 text-xs font-medium text-red-800 ring-1 ring-red-600/20 ring-inset dark:bg-red-400/10 dark:text-red-300 dark:ring-red-400/30">Failed</span></td></tr> <tr class="hover:bg-slate-50 dark:hover:bg-slate-800/50"><td class="px-4 py-2.5 font-medium">#1044</td><td class="px-4 py-2.5">Ana Lima</td><td class="hidden px-4 py-2.5 text-slate-500 @sm:table-cell dark:text-slate-400">Oct 19</td><td class="px-4 py-2.5 text-right tabular-nums">$31.75</td><td class="px-4 py-2.5"><span class="inline-flex rounded-full bg-emerald-50 px-2 py-0.5 text-xs font-medium text-emerald-800 ring-1 ring-emerald-600/20 ring-inset dark:bg-emerald-400/10 dark:text-emerald-300 dark:ring-emerald-400/30">Paid</span></td></tr> </tbody> </table> </div> <div id="empty" hidden class="m-4 rounded-lg border-2 border-dashed border-slate-200 p-6 text-center dark:border-slate-700"> <p class="font-medium">No orders match <span id="term"></span></p> <p class="mt-1 text-sm text-slate-500 dark:text-slate-400">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 dark:bg-white dark:text-slate-900 dark:hover:bg-slate-200">Clear search</button> </div> </section> </main> </div> </div></div><script> const frame = document.getElementById("frame"); const shell = document.getElementById("shell"); document.querySelectorAll("[data-width]").forEach((b) => b.addEventListener("click", () => { frame.style.width = b.dataset.width; }) ); const menu = document.getElementById("menu"); menu.addEventListener("click", () => { const open = shell.dataset.open !== "true"; shell.dataset.open = String(open); menu.setAttribute("aria-expanded", String(open)); }); const theme = document.getElementById("theme"); theme.addEventListener("click", () => { const isDark = shell.classList.toggle("dark"); theme.setAttribute("aria-pressed", String(isDark)); }); const search = document.getElementById("search"); const rows = [...document.querySelectorAll("#rows tr")]; function filter() { const text = search.value.trim().toLowerCase(); let shown = 0; for (const row of rows) { row.hidden = !row.textContent.toLowerCase().includes(text); if (!row.hidden) shown++; } document.getElementById("table-wrap").hidden = shown === 0; document.getElementById("empty").hidden = shown > 0; document.getElementById("term").textContent = '"' + search.value.trim() + '"'; } search.addEventListener("input", filter); document.getElementById("clear").addEventListener("click", () => { search.value = ""; filter(); search.focus(); });</script>

Preview

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.

  1. 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.