Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

Project: An Admin Dashboard

Build a responsive admin dashboard with Tailwind CSS: sidebar and top bar layout, stat cards, a data table, progress bars, status badges and a dark mode switch.

Dashboards are where Tailwind shines: lots of small, repeated building blocks (cards, badges, rows) that must line up on every screen size. In this project you build a dashboard for a fictional shop, Harbor. You will practice app-style layouts with a fixed sidebar, grid and flex combinations, data rendered from an array, and dark mode with the class strategy.

The layout shell

An app shell has three regions: a sidebar, a top bar and a scrolling content area. On phones the sidebar becomes a slide-in drawer; from lg up it is always visible.

flowchart LR
  subgraph Desktop["lg and up"]
    S1["Sidebar<br/>w-64"] --- M1["Top bar<br/>Content"]
  end
  subgraph Phone["below lg"]
    T2["Top bar + menu button"] --> C2["Content"]
    D2["Drawer<br/>slides over content"] -.-> C2
  end

One markup, two layouts: the sidebar is translated out of view on phones.

The key idea for the drawer is that the sidebar is always in the page, fixed to the left. On phones it is pushed off screen with -translate-x-full, and a class toggles it back to translate-x-0. On lg it is forced visible with lg:translate-x-0, and the content gets lg:pl-64 so it is not hidden behind it.

Step 1: sidebar, top bar and a drawer

The class -translate-x-full and lg:translate-x-0 are an example of the mobile-first rule: the base class hides the drawer, and the lg: class cancels it. Toggling -translate-x-full with JavaScript shows or hides it on small screens; on large screens lg:translate-x-0 wins regardless.

A production drawer also needs a backdrop that closes it on click, Escape key handling and focus management. The patterns are the same as for any modal; the focus of this project is the layout and styling.

Stat cards

Four key numbers sit in a responsive grid: one column on phones, two on sm, four on xl. Each card has a label, a value and a trend badge colored by direction.

A reusable function builds the card from data, following the pattern from Reusing Styles with Components. The trend color uses a lookup table with complete class names.

Data table, badges and progress

Tables on narrow screens are tricky. The robust approach is a wrapper with overflow-x-auto, so the table scrolls sideways instead of breaking the page. Row backgrounds use odd:/even: or a hover highlight; the status uses a small pill badge.

Step 2: the complete dashboard

Some choices in this code are worth studying.

  • Complete class names in lookup tables (trend, status) so a production build can see them.
  • Dynamic values in style: the bar width is data, so it goes into a style attribute rather than a generated class (see Arbitrary Values and Resolving Conflicts).
  • tabular-nums keeps digits the same width so totals line up in a column.
  • min-w-[28rem] on the table inside overflow-x-auto gives horizontal scrolling on phones instead of squashed columns.
  • divide-y adds borders between rows without a class on each <tr>.
  • ring-1 instead of border on cards adds an outline that does not change the card's size.

Accessibility notes

Dashboards are information-dense, so structure matters:

  • Give each section an aria-label or a heading, so screen reader users can jump between regions.
  • Do not rely on color alone for status. The badges contain the words "Paid", "Pending" and "Refunded"; the trend badges contain a sign.
  • Provide role="progressbar" and the aria-value* attributes for bars, as above.
  • Mark the current navigation item with aria-current="page" and style it with aria-[current=page]:bg-slate-800 if you prefer attribute-driven styling.

Extensions to try

  1. Add a "Filter by status" <select> and re-render the rows.
  2. Make the sidebar collapsible on large screens with a data-collapsed attribute and data-[collapsed=true]:w-16.
  3. Replace the progress bars with an inline SVG sparkline.
  4. Give the table sticky headers: sticky top-0 on <th> inside a scroll container with max-h-80.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does the sidebar stay visible on large screens but hide on phones?

    The base utility pushes it off screen; the lg: variant resets it, so the drawer toggle only matters on small screens.
  2. 2. Why wrap a table in overflow-x-auto?

    A scrolling wrapper contains the overflow, so the rest of the page keeps its width.
  3. 3. Why put the bar width in a style attribute?

    A style value (or a CSS variable) carries dynamic numbers; utilities stay as complete static names.
  4. 4. What does divide-y do?

    divide-y puts a top border on every child except the first, so rows are separated without extra classes.

Summary

  • An app shell is a fixed sidebar plus offset content (lg:pl-64); on phones the sidebar slides in with a translate toggle.
  • Use grids with breakpoint column counts for stat cards, overflow-x-auto for tables and divide-y for row borders.
  • Render repeated UI from data with functions and lookup tables of complete class names; use style or CSS variables for dynamic numbers.
  • Do not rely on color alone, label regions and use progressbar roles.

Next: Project: Signup Form and Pricing