Nov 4, 20243 min read

Build Dashboard with HTML Tailwind CSS and JavaScript

Build a modern dashboard with Tailwind CSS and JavaScript. Create dark-themed interfaces with Chart.js visualizations and responsive sidebar.

Build Dashboard with HTML Tailwind CSS and JavaScript

In this tutorial, we’ll will Build Dashboard with HTML Tailwind CSS and JavaScript. This dashboard features a sleek, dark-themed interface with stunning visualizations and interactive components, such as charts and a responsive sidebar. Designed with user experience in mind, it incorporates Tailwind CSS for responsive styling and Chart.js for dynamic data visualizations, making it ideal for those looking to create an eye-catching and functional dashboard.

Introduction to Build Dashboard with HTML Tailwind CSS and JavaScript

Dashboards have become indispensable tools in digital product interfaces, enabling users to view analytics, track progress, and make data-driven decisions quickly. By building a dashboard with HTML and Tailwind CSS, you can create a modular, scalable, and aesthetically pleasing interface without sacrificing performance

In this tutorial, we’re focusing on a few essentials:

  • HTML for structure

  • Tailwind CSS for styling

  • JavaScript for interactivity and data visualization (using Chart.js)

With this approach, you’ll be able to customize your dashboard’s look and feel, add dynamic elements, and create responsive layouts that work seamlessly across all devices.

Setting Up the Project Structure For this dashboard, you’ll need a basic project structure. You’ll create separate files for your HTML, CSS (compiled by Tailwind), and JavaScript.

  • HTML: This will define the dashboard’s structure, layout, and accessibility.

  • Tailwind CSS: Use Tailwind’s utility-first classes for fast and responsive design without writing custom CSS.

  • JavaScript (Chart.js): Chart.js will handle the visual representation of data, helping you generate dynamic charts for data visualization.

Subscribe to my YouTube channel HTML Structure and Layout Let’s dive into the HTML structure for a simple yet functional dashboard. We’ll start with a header, sidebar, and main content area that includes interactive widgets and data charts.

Adding Styles with Tailwind CSS With Tailwind, styling becomes much more efficient. You’ll add classes directly to HTML elements to define their appearance, layout, and responsiveness. Below, we’ll cover how Tailwind is used for each section:

  • Header: This contains the app name, search bar, and profile information.

  • Sidebar: Acts as the navigation menu for different dashboard sections.

  • Main Content Area: Holds dynamic widgets for revenue flow, income, expenses, and available balance.

Creating Interactivity with JavaScript

JavaScript adds functionality to your dashboard. For instance, you can create interactive charts with Chart.js to display data trends.

Source code

If you like this design, then feel free to use it. Copy the code by clicking on Copy button provided below. First, you have to create two files. One of them is HTML and the other is JS after creating these files, paste the code provided below.

Build Dashboard with HTML Tailwind CSS and JavaScript
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <!-- Code by: www.codeinfoweb.com -->
5 <meta charset="UTF-8" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 <link href="./output.css" rel="stylesheet" />
8 <!-- Tailwind CSS CDN -->
9 <script src="https://cdn.tailwindcss.com"></script>
10 <link
11 href="https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css"
12 rel="stylesheet"
13 />
14 <title>Finavise Dashboard</title>
15 <style>
16 @import url("https://fonts.googleapis.com/css2?family=Itim&display=swap");
17 body {
18 font-family: "Itim", cursive;
19 }
20 </style>
21 </head>
22 <body class="bg-gray-900 text-gray-100 overflow-x-clip">
23 <!-- Header Section -->
24 <header class="p-4 flex justify-between items-center">
25 <div class="flex items-center gap-2">
26 <button
27 id="menuButton"
28 class="text-gray-100 text-3xl lg:hidden hover:text-gray-400"
29 aria-label="Open Menu"
30 >
31 <i class="bx bx-menu"></i>
32 </button>
33 <div class="flex items-center gap-2 text-teal-400 cursor-pointer">
34 <i class="bx bx-infinite text-3xl"></i>
35 <span class="text-xl font-semibold">Finavise</span>
36 </div>
37 </div>
38
39 <div class="flex items-center">
40 <div class="relative hidden lg:flex w-[500px]">
41 <input
42 type="text"
43 placeholder="Search..."
44 class="w-full py-2 pl-10 pr-4 bg-gray-800 border border-gray-600 rounded-md text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-teal-500"
45 />
46 <i
47 class="bx bx-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"
48 ></i>
49 </div>
50 </div>
51 <div class="flex items-center gap-2">
52 <span class="text-gray-300 font-medium">John Doe</span>
53 <img
54 src="../src/user.png"
55 alt="User Avatar"
56 class="w-10 h-10 rounded-full border border-gray-600"
57 />
58 </div>
59 </header>
60
61 <div class="flex p-3 gap-4">
62 <!-- Sidebar Section -->
63 <aside
64 id="sidebar"
65 class="w-42 hidden lg:block rounded-lg bg-gray-800 p-2 py-5 fixed lg:relative lg:translate-x-0 transform -translate-x-full transition-transform duration-200 ease-in-out"
66 >
67 <nav class="space-y-4">
68 <a
69 href="#"
70 class="flex items-center space-x-3 text-gray-300 hover:bg-gray-700 p-3 rounded-md"
71 >
72 <i class="bx bx-home-alt text-teal-400"></i>
73 <span>Dashboard</span>
74 </a>
75 <a
76 href="#"
77 class="flex items-center space-x-3 text-gray-300 hover:bg-gray-700 p-3 rounded-md"
78 >
79 <i class="bx bx-line-chart text-teal-400"></i>
80 <span>Analytics</span>
81 </a>
82 <a
83 href="#"
84 class="flex items-center space-x-3 text-gray-300 hover:bg-gray-700 p-3 rounded-md"
85 >
86 <i class="bx bx-wallet text-teal-400"></i>
87 <span>Transactions</span>
88 </a>
89 <a
90 href="#"
91 class="flex items-center space-x-3 text-gray-300 hover:bg-gray-700 p-3 rounded-md"
92 >
93 <i class="bx bx-user text-teal-400"></i>
94 <span>Account</span>
95 </a>
96 <a
97 href="#"
98 class="flex items-center space-x-3 text-gray-300 hover:bg-gray-700 p-3 rounded-md"
99 >
100 <i class="bx bx-cog text-teal-400"></i>
101 <span>Settings</span>
102 </a>
103 </nav>
104 </aside>
105
106 <!-- Main Section -->
107 <main
108 class="flex-1 bg-gray-900 flex gap-4 flex-col lg:flex-row ml-0 lg:ml-42"
109 >
110 <section
111 class="w-full lg:flex-1 p-4 space-y-6 bg-gray-800 flex flex-col rounded-lg"
112 >
113 <!-- Revenue Flow Card (full width) -->
114 <div class="bg-gray-700 p-5 rounded-md">
115 <div class="flex items-center justify-between mb-4">
116 <div class="flex items-center space-x-3">
117 <i class="bx bx-trending-up text-teal-400 text-2xl"></i>
118 <h2 class="text-lg font-semibold text-gray-100">
119 Revenue Flow
120 </h2>
121 </div>
122 <span class="text-xl font-bold text-gray-100">$24,300</span>
123 </div>
124 <canvas id="revenueFlowChart" class="w-full"></canvas>
125 </div>
126
127 <div class="flex gap-4 flex-col md:flex-row">
128 <!-- Income Card with Growth -->
129 <div
130 class="bg-gray-700 p-5 flex-1 rounded-md flex items-center justify-between"
131 >
132 <div
133 class="flex md:items-center gap-2 flex-col lg:flex-row items-start"
134 >
135 <i class="bx bx-dollar-circle text-teal-400 text-2xl"></i>
136 <h2 class="text-sm md:text-lg font-semibold text-gray-100">
137 Income
138 </h2>
139 </div>
140 <div
141 class="text-xl font-bold text-gray-100 flex flex-col items-end lg:flex-row lg:items-center gap-2"
142 >
143 <span class="text-sm lg:text-lg">$15,200</span>
144 <span class="text-green-400 text-sm">+8%</span>
145 </div>
146 </div>
147
148 <!-- Expense Card with Growth -->
149 <div
150 class="bg-gray-700 p-4 md:p-5 flex-1 rounded-md flex items-center justify-between"
151 >
152 <div
153 class="flex md:items-center gap-2 flex-col lg:flex-row items-start"
154 >
155 <i class="bx bx-cart text-teal-400 text-2xl"></i>
156 <h2 class="text-sm md:text-lg font-semibold text-gray-100">
157 Expenses
158 </h2>
159 </div>
160 <div
161 class="text-xl font-bold text-gray-100 flex flex-col items-end lg:flex-row lg:items-center gap-2"
162 >
163 <span class="text-sm lg:text-lg">$6,700</span>
164 <span class="text-red-400 text-sm">-5%</span>
165 </div>
166 </div>
167 </div>
168 </section>
169
170 <!-- Right Side Content -->
171 <section
172 class="w-full lg:w-[300px] p-4 flex flex-col justify-between gap-4 bg-gray-800 rounded-lg"
173 >
174 <!-- Credit Card -->
175 <div
176 class="bg-gradient-to-r from-teal-500 to-blue-600 p-5 rounded-lg text-white"
177 >
178 <h3 class="text-xl font-semibold mb-2">Credit Card</h3>
179 <p class="text-sm mb-4">Valid Thru: 12/25</p>
180 <div class="mb-6">
181 <span class="block text-lg font-bold tracking-wide"
182 >•••• •••• •••• 1234</span
183 >
184 </div>
185 <div class="flex justify-between">
186 <div>
187 <span class="text-xs uppercase text-gray-200">Card Holder</span>
188 <p class="text-lg font-medium">John Doe</p>
189 </div>
190 <div>
191 <span class="text-xs uppercase text-gray-200">Balance</span>
192 <p class="text-lg font-medium">$5,300</p>
193 </div>
194 </div>
195 </div>
196
197 <!-- Available Balance with Pie Chart -->
198 <div class="bg-gray-700 p-5 rounded-md overflow-hidden">
199 <div class="flex items-center justify-between mb-4">
200 <i class="bx bx-wallet text-teal-400 text-2xl"></i>
201 <h2 class="text-lg font-semibold text-gray-100">Available</h2>
202 </div>
203 <div class="flex justify-center px-10 overflow-hidden">
204 <canvas
205 id="availableBalanceChart"
206 class="w-20 md:w-32 lg:w-40"
207 ></canvas>
208 </div>
209 </div>
210 </section>
211 </main>
212 </div>
213
214 <!-- Include Chart.js from CDN -->
215 <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
216 <script src="script.js"></script>
217 </body>
218</html>

Best Practices for Building Dashboards Responsive Design: Ensure your dashboard adjusts to different screen sizes using Tailwind’s responsive classes (lg:hidden, md:flex, etc.). Accessible Colors: Make sure the color contrast is high enough for readability, particularly in dark mode. Minimize JavaScript and CSS: Tailwind CSS and Chart.js are both lightweight, but try to reduce any extra styles and scripts that could slow down performance. Interactive and Informative Charts: Use Chart.js to build intuitive visualizations; avoid overcrowding charts with too much information.

Conclusion

Creating a dashboard with HTML, Tailwind CSS, and JavaScript is a powerful way to deliver a user-friendly interface. Tailwind’s utility classes make styling efficient, while JavaScript enables you to add dynamic elements that improve user engagement. Following best practices for responsive design, accessibility, and code modularity will help you build dashboards that are both visually appealing and highly functional.