In this project you will build a responsive admin dashboard for a school class, the kind of page a teacher might open each morning. It brings together many skills from this series: CSS Grid for the layout, auto-fitting cards, a bar chart drawn with pure CSS, :has(), a container query, transforms, and an automatic dark mode. No JavaScript and no frameworks are needed.
In this project you will practise
- A sidebar-and-content layout with CSS Grid
- Responsive stat cards with
repeat(auto-fit, minmax()) - A CSS bar chart using
attr()and pseudo-elements :has(), a container query and hover transforms- Theming with variables and
prefers-color-scheme
This project uses CSS Grid, container queries, :has() and dark mode.
The Complete Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>School Dashboard</title>
<style>
:root {
color-scheme: light dark;
--bg: #f4f6fb; --panel: #ffffff; --text: #1f2933; --muted: #6b7280; --accent: #2563eb; --line: #e5e7eb;
}
@media (prefers-color-scheme: dark) {
:root { --bg: #0b1220; --panel: #111a2e; --text: #e5e7eb; --muted: #9ca3af; --accent: #60a5fa; --line: #1f2a44; }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.app { display: grid; grid-template-columns: 180px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 14px; }
.side h2 { font-size: 16px; margin: 0 0 12px; }
.side a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text); text-decoration: none; }
.side a:hover, .side a[aria-current] { background: var(--bg); color: var(--accent); }
main { padding: 16px; display: grid; gap: 14px; align-content: start; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
transition: transform 0.2s; }
.stat:hover { transform: translateY(-3px); }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); }
.panels { display: grid; gap: 14px; grid-template-columns: 2fr 1fr; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
container-type: inline-size; }
.panel h3 { margin: 0 0 8px; font-size: 15px; }
.bars { display: flex; align-items: end; gap: 8px; height: 110px; margin-bottom: 20px; }
.bars div { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; position: relative; }
.bars div::after { content: attr(data-day); position: absolute; bottom: -18px; left: 0; right: 0;
text-align: center; font-size: 11px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li:has(.late) { color: #dc2626; }
@container (max-width: 220px) { .list li { flex-direction: column; } }
@media (max-width: 700px) {
.app { grid-template-columns: 1fr; }
.side { border-right: 0; border-bottom: 1px solid var(--line); }
.side nav { display: flex; gap: 4px; overflow-x: auto; }
.panels { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="app">
<aside class="side">
<h2>Class 9 – A</h2>
<nav>
<a href="#" aria-current="page">Overview</a>
<a href="#">Students</a>
<a href="#">Attendance</a>
<a href="#">Results</a>
</nav>
</aside>
<main>
<section class="stats" aria-label="Summary">
<div class="stat"><b>42</b><span>Students</span></div>
<div class="stat"><b>39</b><span>Present today</span></div>
<div class="stat"><b>93%</b><span>Attendance</span></div>
<div class="stat"><b>4.21</b><span>Average GPA</span></div>
</section>
<section class="panels">
<div class="panel">
<h3>Attendance this week</h3>
<div class="bars" role="img" aria-label="Attendance: Sun 95%, Mon 90%, Tue 93%, Wed 88%, Thu 97%">
<div data-day="Sun" style="height:95%"></div>
<div data-day="Mon" style="height:90%"></div>
<div data-day="Tue" style="height:93%"></div>
<div data-day="Wed" style="height:88%"></div>
<div data-day="Thu" style="height:97%"></div>
</div>
</div>
<div class="panel">
<h3>Homework</h3>
<ul class="list">
<li><span>Maths: Ex 4.2</span><span>Done</span></li>
<li><span>Biology: Cell diagram</span><span class="late">Late</span></li>
<li><span>English: Essay</span><span>Due Sun</span></li>
</ul>
</div>
</section>
</main>
</div>
</body>
</html>
Result
Save the code as dashboard.html and open it in a browser. Make the window narrow to see the mobile layout, and switch your device to dark mode to see the dark theme.
Step 1: The Layout
.appis a grid with two columns: a fixed 180px sidebar and a flexible1frmain area.min-height: 100vhmakes it fill the screen.- The sidebar uses an
<aside>and a<nav>, so assistive technology recognises it as navigation.aria-current="page"marks the active link, and the same attribute is used in CSS to highlight it. mainis also a grid, withgapfor spacing andalign-content: startso its sections stay at the top.
Step 2: Stat Cards
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr))fits as many 140px-or-wider cards as the space allows: four in a row on a laptop, two on a phone, with no media query.- Each card shows a big number in
<b>withdisplay: blockand a muted label. The attendance figure is 39 of 42 students, about 93%. transform: translateY(-3px)on hover lifts the card slightly, with a transition for smoothness.
Step 3: A CSS Bar Chart
.barsis a flex row with a fixed height of 110px andalign-items: end, so the bars grow upwards from the bottom.- Each bar’s inline
style="height:95%"sets its value. In a real app, the server or JavaScript would write these numbers. ::afterwithcontent: attr(data-day)prints each bar’s label below it, read straight from the HTML attribute. The bottom margin on.barsleaves room for these labels.- A chart made of plain boxes means nothing to a screen reader, so the container has
role="img"and anaria-labellisting all the values.
Step 4: Modern CSS Touches
.list li:has(.late)turns a homework row red when it contains a “Late” tag. Change another row’s status to<span class="late">and it turns red too.- Each
.panelis a query container. If a panel becomes narrower than 220px,@container (max-width: 220px)stacks each homework row’s text vertically. - The media query at 700px changes the page itself: one column, the sidebar on top, and its links in a horizontal scrolling row.
- All colours come from variables, and a single
prefers-color-scheme: darkblock swaps them for the dark theme.
Ideas to Extend the Project
- Add a manual dark-mode toggle, using the method from the previous lesson.
- Add a “Students” table with a sticky header, using what you learned about tables and
position: sticky. - Show the attendance percentage when a bar is hovered, using
::beforeand adata-valueattribute. - Run a Lighthouse audit and fix any accessibility or performance warnings.
Common Mistakes
- Using fixed widths for cards, which leaves gaps or overflow on other screens.
- Forgetting text alternatives for the chart, so screen reader users miss the data.
- Hard-coding colours inside components, which breaks the dark theme.
- Relying on colour alone for “Late”. The word itself is still shown, which keeps it clear for colour-blind users.
Practice Exercises
Exercise 1. Add a fifth stat card showing “3 Absent”. What else do you need to change in the CSS?
Show answer
Only the HTML: <div class="stat"><b>3</b><span>Absent</span></div>. The auto-fit grid makes room automatically.
Exercise 2. Make the chart bars change colour to orange on hover.
Show answer
.bars div { transition: background 0.2s; }
.bars div:hover { background: #f97316; }
Frequently Asked Questions
Should a real dashboard use a chart library?
For simple bar charts, CSS is light and fast. For line graphs, tooltips, zooming or large data sets, a JavaScript chart library or an SVG chart is a better choice.
Where would the data come from in a real app?
From a server and database. JavaScript would fetch the numbers, usually as JSON, and fill in the cards, bars and list. You will learn how in the JavaScript lessons.
Summary
- CSS Grid builds the sidebar layout;
auto-fitandminmax()make the cards responsive. - Flexbox,
attr()and::aftercreate a labelled CSS bar chart. :has(), container queries and media queries each handle a different kind of change.- Variables and
prefers-color-schemegive the whole dashboard a dark theme.
Next: CSS Logical Properties.
