DEV Community

Cover image for Building a 19-page admin dashboard with Tailwind CSS v4 and no JavaScript framework
Brightkit Templates
Brightkit Templates

Posted on

Building a 19-page admin dashboard with Tailwind CSS v4 and no JavaScript framework

When people build an admin dashboard today, the first step is usually "pick a framework". I wanted to try the opposite: Tailwind CSS v4, plain HTML and one small vanilla JavaScript file. The result is Velora, a 19-page dashboard template. Here are the patterns that made it work.

👉 Live demo

1. Dark mode without a flash

Tailwind v4 lets you redefine the dark variant directly in CSS:

@import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));
Enter fullscreen mode Exit fullscreen mode

Now dark:bg-gray-900 applies whenever an ancestor has the dark class. To avoid the classic "white flash" on page load, a tiny script in the <head> applies the saved theme before anything is painted:

<script>
  try {
    var t = localStorage.getItem("velora-theme");
    if (t === "dark" || (!t && matchMedia("(prefers-color-scheme: dark)").matches))
      document.documentElement.classList.add("dark");
  } catch (e) {}
</script>
Enter fullscreen mode Exit fullscreen mode

The try/catch matters: localStorage can throw in private windows or sandboxed iframes, and the page must still render.

2. Components with @apply, utilities everywhere else

I keep repeated UI pieces as small component classes so the HTML stays readable:

@layer components {
  .card { @apply rounded-2xl border border-gray-200 bg-white shadow-xs dark:border-gray-800 dark:bg-gray-900; }
  .btn-primary { @apply bg-primary-600 text-white hover:bg-primary-700; }
}
Enter fullscreen mode Exit fullscreen mode

One v4 gotcha: you can't @apply an arbitrary value containing spaces (like a bg-[url(...)] with an inline SVG), and you can't @apply peer. Plain CSS properties next to @apply solve both.

3. Data attributes instead of a framework

Every interactive piece is declared in HTML:

<button data-modal-open="newOrder">New order</button>
<dialog id="newOrder" class="modal">…<button data-modal-close>Cancel</button></dialog>
Enter fullscreen mode Exit fullscreen mode

A single click listener on document handles dropdowns, modals, toasts and the theme toggle through event delegation:

document.addEventListener("click", (e) => {
  const open = e.target.closest("[data-modal-open]");
  if (open) document.getElementById(open.dataset.modalOpen).showModal();
  if (e.target.closest("[data-modal-close]")) e.target.closest("dialog").close();
});
Enter fullscreen mode Exit fullscreen mode

Using the native <dialog> element gives focus trapping, Esc to close and a ::backdrop for free.

4. A data table in ~120 lines

The orders, customers and invoices pages share one table script: search, status filter, sortable columns, pagination and bulk selection. The key ideas:

  • Keep all rows in an array and only toggle hidden, so sorting is just re-appending rows in a new order.
  • Sort on a data-value attribute when the visible text isn't sortable (dates, prices).
  • Expose the sort state with aria-sort so it's accessible, and style the arrow with th[aria-sort="ascending"]::after.

5. Charts that follow the theme

Chart.js doesn't know about Tailwind's dark mode, so all colors come from one helper:

Velora.chartColors = () => {
  const dark = document.documentElement.classList.contains("dark");
  return { text: dark ? "#9ca3af" : "#6b7280", grid: dark ? "rgba(255,255,255,.06)" : "rgba(17,24,39,.06)" };
};
Enter fullscreen mode Exit fullscreen mode

Each page script destroys and rebuilds its charts when the theme changes. It's simpler than patching every option.

6. No images to license

Avatars are initials with a color derived from the name, and product visuals are gradients plus icons. Besides avoiding licensing issues, it keeps the template light and makes dark mode trivial.

Wrapping up

Without a framework you write a bit more HTML, but you get pages that load instantly, work by double-clicking the file, and are easy for anyone to customize.

If you want to explore the full result, here's the live demo. The complete template, with sources and documentation, is available on Codester.

What would you build differently? I'd love to hear your approach in the comments.

Top comments (0)