While developing the Financial data analyzer series, a dashboard became necessary for presenting the analyzed data intuitively and visually appealingly. Although I'm not a UI/UX designer, I appreciate well-designed interfaces with modern visual cues. This article details my process of creating such a dashboard from scratch with TailwindCSS v4 without using external frameworks.

This article assumes you're familiar with HTML5, CSS3, and JavaScript (ES syntax). Familiarity with TailwindCSS is also helpful.

I'll present two ways to set up your development environment for working with TailwindCSS from scratch, without external frameworks.

To get started with Tailwind CSS v4 for your dashboard project using Node.js, follow these steps:

  1. Create your project directory (e.g., finance-dashboard) and navigate into it:

    sh
  2. Install Tailwind CSS, the Tailwind CSS CLI, and the @tailwindcss/forms plugin as development dependencies:

    sh
  3. Create an input CSS file (e.g., assets/css/input.css) and add the following:

    assets/css/input.css
    css

    This CSS file imports Tailwind CSS, registers the @tailwindcss/forms plugin and sets up a custom dark variant for enabling dark mode via CSS classes. It also includes basic styling for smooth scrolling, font family, and form elements.

    Note: TailwindCSS v4

    We are using strictly TailwindCSS v4 here hence we ditched tailwind.config.[j|t]s file. You can read more in my v3 to v4 migration guide with plugins.

  4. Create your main HTML file (e.g., index.html) with the following structure:

    index.html
    html

    This is a basic HTML structure that includes Google Fonts, ApexCharts (for placeholder charts), and links to your compiled CSS and JavaScript files. The body includes classes for light and dark modes.

  5. Generate the compiled CSS file, assets/css/style.css:

    sh

For those who prefer not to use Node.js, you can use TailwindCSS's Standalone CLI. Follow the guide to install it based on your operating system. Then, complete steps 1, 3, and 4 from the Node.js setup, skipping steps 2 and 5. To compile your CSS, run:

sh

This setup provides a foundation for building the dashboard with Tailwind CSS v4, utilizing vanilla JavaScript for interactivity and ApexCharts for data visualization.

Sirneij
Sirneij/finance-dashboard
00

An aesthetic personal finance dashboard built with vanilla JS, tailwindcss v4 and HTML5

html5javascriptcss3

First off, we will build out the header and sidebar of the dashboard. Let's add this to the body of the page:

html

The entire page is meant to take the height of the screen (h-screen). This ensures the page remains in view. The sidebar inherits this property. It contains both icons and labels. We'll use both so that when the sidebar is fully open, both are visible, but when it's collapsed, only the icons are displayed.

Next, we will add the main content markup:

html

At the top, we have the header with the "Dashboard" inscription. It also houses the icons that toggle light/dark modes. The main page takes the remaining height available on the page (h-[calc(100vh-4rem)]) and allows vertical scrolling in case of overflow (overflow-y-auto).

The remaining markups are easy to follow, so we won't paste them here. You can always visit the project's repo to copy them. They look like this for now:

Dark themed dashboard Light themed dashboard

We'll proceed to write the theme-switching logic and responsive triggers.

Make your assets/js/app.js look like this:

assets/js/app.js
js

This JavaScript code sets up the responsive sidebar and theme-switching logic for the dashboard. SidebarController handles the sidebar's behavior on different screen sizes, including toggling the sidebar and highlighting the current page in the navigation. The ThemeController manages the theme (light/dark) based on user preference or system settings, persisting the choice in local storage. The code uses classes and event listeners for efficient state management and dynamic UI updates.

I opted for classes due to state management issues, especially isSidebarOpen and isMobile. Binding them up here makes it very easy to elegantly manage.

The collapsed versions should look like these:

Dark themed dashboard (collapsed) Light themed dashboard (collapsed)

For a little taste of the awesome and relatively lightweight charting library (the reason it was preferred compared to Chart.js):

assets/js/index.chart.js
js

This code configures and initializes ApexCharts for the dashboard. initializeMonthlyChart and initializeFinancialChart functions define the options for two different area charts, including series data, chart type, colors, and grid settings. The code also includes a MutationObserver to handle theme changes and a debounce function to optimize resize event handling, ensuring the charts are responsive and adapt to the selected theme.

There are other pages implemented and the repo has them. You can also preview its live version.

Enjoyed this article? I'm a Software Engineer, Technical Writer, and Technical Support Engineer actively seeking new opportunities, particularly in areas related to web security, finance, healthcare, and education. If you think my expertise aligns with your team's needs, let's chat! You can find me on LinkedIn and X. I am also an email away.

If you found this article valuable, consider sharing it with your network to help spread the knowledge!