Admin Dashboard UI with HTML, CSS & JavaScript
40 DAYS 40 PROJECT CHALLENGE
Day #01
Project Overview
The Admin Dashboard UI is a beginner-friendly project built with HTML, CSS, and JavaScript. It provides a dashboard interface where administrators can log in, manage users, view user statistics, and search through user records. The dashboard of this project consists of a login page, sidebar, user statistics cards, add/edit user form, and user table. JavaScript manages the login process, user creation, editing, deletion, and search functionality. Additionally, the project uses localStorage to save user records and sessionStorage to maintain the login status during the browser session.
This project is designed for frontend learning and demonstration purposes. The login uses fixed credentials, so it does not provide secure, production-level authentication. However, it gives beginners valuable experience with DOM manipulation, browser storage, form validation, responsive layouts, and dynamic table rendering
Key Features
- Admin Login System: It includes a login screen where users must enter the predefined username and password. JavaScript checks the credentials and displays error message if details are incorrect.
- Session-Based Login Status: After successful login, the application stores
"isLoggedIn"insessionStorage. When the page loads, JavaScript checks this value and displays the dashboard if the session is still active. - Dashboard Layout: The dashboard contains a sidebar, top navigation bar, statistics cards, user form, search field, and user table. Which creates a structure similar to a basic admin management interface.
- Sidebar Navigation: It displays the Admin Panel title along with Dashboard, Users, and Logout options. On smaller screens, JavaScript uses a toggle function to open and close the sidebar.
- User Statistics: Dashboard contains two cards i.e Total Users and Active Users. The Total Users card shows how many people have signed up for the application, while the Active Users shows how many are online.
- Add Users: Administrators can enter a name and email address through the form and click Save. JavaScript validates the fields before adding a new user to the users array.
- Edit Users: Each user row contains an Edit button that loads the selected user’s name and email into the form. The application then updates the existing record instead of creating a duplicate user.
- Delete Users: Delete button removes the selected user from the users array. After deletion, the application updates
localStorageand refreshes the table. - LocalStorage Data Management: User records are stored in
localStorageusingJSON.stringify(). Therefore, the data remains available even after the page is refreshed. - Search Functionality: Users can search the table by typing a name into the search field. The
searchUser()function checks each row and hides the rows that do not match the entered text. - Dynamic User Table: JavaScript creates table rows from the stored user data. Each row displays the user ID, name, email, and Edit and Delete action buttons.
- Form Validation: The
saveUser()function checks whether the name and email fields contain values. If either field is empty, the application displays an error message and stops the save operation. - Responsive Design: The dashboard uses CSS media queries to respond to different screen sizes. At smaller sizes than 768px, the cards turn into a vertical layout, and the form takes the full width of the screen. Moreover, the sidebar turns into a hamburger menu.
- Logout Functionality: Logout option removes the login status from
sessionStorage. It then hides the dashboard and displays the login page again. - Clean Admin Interface: This project uses cards, a table, a sidebar, and a form to organize dashboard information. This structure makes the interface easier to understand and extend.
What You'll Learn
- How to create a basic admin dashboard layout.
- How to build a simple login interface using HTML and JavaScript.
- How to validate fixed login credentials.
- How to use
sessionStorageto manage login status. - How to use
localStorageto store user records. - How to convert arrays into JSON using
JSON.stringify(). - How to retrieve stored data using
JSON.parse(). - How to add, edit, and delete objects from an array.
- How to use
map(),find(), andfilter()for user management. - How to generate dynamic table rows using template literals.
- How to update dashboard statistics dynamically.
- How to implement search functionality using
querySelectorAll(). - How to show and hide elements with JavaScript.
- How to create a responsive sidebar using CSS media queries.
HTML Code
HTML creates both the login page and the main dashboard structure. The .login-page contains the username and password fields, Login button, login error message. Also, the button calls login() when clicked, allowing JavaScript to validate the entered credentials.
The .dashboard contains the sidebar and main content area. The sidebar includes navigation options and a Logout action, while the main section contains the topbar, statistics cards, user form, search field, and user table.
This project uses form #name, #email, and the hidden #editId field to manage user information. Meanwhile, #userTable provides the location where JavaScript inserts user rows dynamically. Finally, the HTML loads script.js to activate the dashboard functionality.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Admin Dashboard</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- LOGIN PAGE -->
<div class="login-page" id="loginPage">
<div class="login-box">
<h2>Admin Login</h2>
<input type="text" id="username" placeholder="Username">
<input type="password" id="password" placeholder="Password">
<button onclick="login()">Login</button>
<p class="error" id="loginError"></p>
</div>
</div>
<!-- DASHBOARD -->
<div class="dashboard" id="dashboard">
<div class="sidebar" id="sidebar">
<span class="close-btn" onclick="toggleSidebar()">✕</span>
<h2>Admin Panel</h2>
<ul>
<li>Dashboard</li>
<li>Users</li>
<li onclick="logout()">Logout</li>
</ul>
</div>
<div class="main">
<div class="topbar">
<button onclick="toggleSidebar()">☰</button>
<h3>Admin Dashboard</h3>
</div>
<!-- Cards -->
<div class="cards">
<div class="card">
<h4>Total Users</h4>
<p id="totalUsers">0</p>
</div>
<div class="card">
<h4>Active Users</h4>
<p id="activeUsers">0</p>
</div>
</div>
<!-- Add/Edit User -->
<div class="form-box">
<h3>Add / Edit User</h3>
<input type="hidden" id="editId">
<input type="text" id="name" placeholder="Name">
<input type="email" id="email" placeholder="Email">
<button onclick="saveUser()">Save</button>
<p class="error" id="formError"></p>
</div>
<!-- Search -->
<input type="text" id="search" placeholder="Search..." onkeyup="searchUser()">
<!-- Table -->
<div class="table-box">
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody id="userTable"></tbody>
</table>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html> CSS Code
CSS controls the appearance of the login page and dashboard. The universal selector resets the margin and padding, sets box-sizing: border-box, and applies the Segoe UI font, body uses a dark blue background for the overall page.
The .login-page uses Flexbox to center the login box vertically and horizontally, .login-box creates a white card with padding, rounded corners, and a shadow. Similarly, the dashboard’s .sidebar uses a fixed position, dark background, and full viewport height, while .main adds left spacing to accommodate the sidebar.
The .cards section uses Flexbox and wrapping to display statistics cards and this .form-box and .table-box create separate white sections for user management and table content. Finally, the mobile media query changes the layout for smaller screens by stacking cards, expanding inputs, hiding the sidebar off-screen, and allowing users to open it with the toggle button.
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family:Segoe UI, sans-serif;
}
body{
background:#042354;
}
/* LOGIN */
.login-page{
height:100vh;
display:flex;
justify-content:center;
align-items:center;
}
.login-box{
background:#fff;
padding:30px;
width:320px;
border-radius:8px;
box-shadow:0 5px 20px rgba(0,0,0,0.1);
}
.login-box h2{
text-align:center;
margin-bottom:20px;
}
.login-box input{
width:100%;
padding:10px;
margin:8px 0;
}
.login-box button{
width:100%;
padding:10px;
background:#2c3e50;
color:#fff;
border:none;
cursor:pointer;
}
.error{
color:red;
font-size:14px;
margin-top:5px;
}
/* DASHBOARD */
.dashboard{
display:none;
}
.sidebar{
width:230px;
height:100vh;
background:#2c3e50;
color:#fff;
position:fixed;
padding:20px;
transition:0.3s;
left:0;
}
.sidebar h2{
margin-bottom:20px;
}
.sidebar ul li{
list-style:none;
margin:15px 0;
cursor:pointer;
}
.main{
margin-left:230px;
padding:20px;
transition:0.3s;
}
.topbar{
display:flex;
justify-content:space-between;
align-items:center;
margin-bottom:20px;
}
.topbar button{
padding:5px 10px;
cursor:pointer;
}
/* CARDS */
.cards{
display:flex;
gap:15px;
flex-wrap:wrap;
margin-bottom:20px;
}
.card{
flex:1 1 200px;
background:#fff;
padding:20px;
border-radius:8px;
box-shadow:0 2px 10px rgba(0,0,0,0.05);
}
/* FORM */
.form-box{
background:#fff;
padding:20px;
border-radius:8px;
margin-bottom:20px;
}
.form-box input{
padding:8px;
margin-right:10px;
margin-top:10px;
}
.form-box button{
padding:8px 12px;
}
/* TABLE */
.table-box{
background:#fff;
padding:20px;
border-radius:8px;
overflow-x:auto;
width:100%;
}
table{
width:100%;
border-collapse:collapse;
}
th, td{
padding:10px;
border:1px solid #ddd;
}
button.edit{
background:orange;
border:none;
padding:5px 10px;
color:#fff;
}
button.delete{
background:red;
border:none;
padding:5px 10px;
color:#fff;
}
/* SEARCH */
#search{
padding:8px;
margin-bottom:10px;
width:250px;
}
.close-btn{
position:absolute;
top:15px;
right:20px;
font-size:22px;
cursor:pointer;
display:none;
}
/* MOBILE RESPONSIVE */
@media (max-width:768px){
/* Topbar */
.topbar h3{
font-size:18px;
}
/* Cards */
.cards{
flex-direction:column;
}
.card{
width:100%;
}
/* Form */
.form-box input{
width:100%;
margin:8px 0;
}
.form-box button{
width:100%;
margin-top:10px;
}
/* Search */
#search{
width:100%;
}
/* Table */
table{
font-size:14px;
}
th,td{
padding:8px;
}
/* Sidebar */
.sidebar{
left:-230px;
z-index:1000;
}
.sidebar.active{
left:0;
}
.main{
margin-left:0;
}
/* Topbar button */
.topbar button{
font-size:20px;
}
.close-btn{
display:block;
color:white;
}
} Javascript Code
JavaScript manages login, user data, dashboard updates, and search functionality. First, the code retrieves the user records from localStorage using JSON.parse() or creates an empty array when no data exists. It also calculates the next user ID using the last stored user’s ID.
This window.onload function checks whether "isLoggedIn" exists in sessionStorage. If the value is "true", it hides the login page, displays the dashboard, and calls renderUsers(). Then, the login() function checks whether the username is "admin" and the password is "1234". When the credentials match, it stores the login status and opens the dashboard, logout() function removes this status and returns the user to the login page.
This saveUser() function validates the name and email fields. If editId contains a value, it uses map() to update the matching user. Otherwise, it adds a new user with push(). The code then saves the updated array in localStorage and calls renderUsers().
This renderUsers() function clears the table and creates a row for each user using forEach(). It also updates the Total Users and Active Users values. The editUser() function loads a selected user’s information into the form, while deleteUser() removes the user with filter(). Finally, searchUser() checks each table row’s name and hides rows that do not contain the entered search value.
let users = JSON.parse(localStorage.getItem("users")) || [];
let userId = users.length ? users[users.length-1]?.id + 1 : 1;
/* CHECK LOGIN STATUS ON LOAD */
window.onload = function() {
if(sessionStorage.getItem("isLoggedIn") === "true"){
document.getElementById("loginPage").style.display="none";
document.getElementById("dashboard").style.display="block";
renderUsers();
}
}
/* LOGIN */
function login(){
const user = document.getElementById("username").value;
const pass = document.getElementById("password").value;
if(user === "admin" && pass === "1234"){
sessionStorage.setItem("isLoggedIn","true");
document.getElementById("loginPage").style.display="none";
document.getElementById("dashboard").style.display="block";
renderUsers();
}else{
document.getElementById("loginError").textContent="Invalid Credentials!";
}
}
/* LOGOUT */
function logout(){
sessionStorage.removeItem("isLoggedIn");
document.getElementById("dashboard").style.display="none";
document.getElementById("loginPage").style.display="flex";
}
/* SIDEBAR */
function toggleSidebar(){
document.getElementById("sidebar").classList.toggle("active");
}
/* SAVE USER */
function saveUser(){
const name=document.getElementById("name").value.trim();
const email=document.getElementById("email").value.trim();
const editId=document.getElementById("editId").value;
if(!name || !email){
document.getElementById("formError").textContent="All fields required!";
return;
}
if(editId){
users=users.map(u=>u.id==editId?{...u,name,email}:u);
document.getElementById("editId").value="";
}else{
users.push({id:userId++,name,email});
}
localStorage.setItem("users",JSON.stringify(users));
document.getElementById("name").value="";
document.getElementById("email").value="";
document.getElementById("formError").textContent="";
renderUsers();
}
/* RENDER USERS */
function renderUsers(){
const table=document.getElementById("userTable");
table.innerHTML="";
users.forEach(user=>{
table.innerHTML+=`
<tr>
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.email}</td>
<td>
<button class="edit" onclick="editUser(${user.id})">Edit</button>
<button class="delete" onclick="deleteUser(${user.id})">Delete</button>
</td>
</tr>
`;
});
document.getElementById("totalUsers").textContent=users.length;
document.getElementById("activeUsers").textContent=users.length;
}
/* EDIT */
function editUser(id){
const user=users.find(u=>u.id==id);
document.getElementById("name").value=user.name;
document.getElementById("email").value=user.email;
document.getElementById("editId").value=id;
}
/* DELETE */
function deleteUser(id){
users=users.filter(u=>u.id!=id);
localStorage.setItem("users",JSON.stringify(users));
renderUsers();
}
/* SEARCH */
function searchUser(){
const value=document.getElementById("search").value.toLowerCase();
const rows=document.querySelectorAll("#userTable tr");
rows.forEach(row=>{
const name=row.cells[1].innerText.toLowerCase();
row.style.display=name.includes(value)?"":"none";
});
} Related Projects
Day 3 : E-commerce Product Page
Generates an OTP via alert and verifies it through a popup-based input UI.
Concepts: DOM manipulation, modal UI, random OTP generation, input handling.
Day 4 : Invoice Generator
Creates invoices dynamically with item details and real-time total calculation.
Concepts: DOM manipulation, form handling, calculations, data rendering.
Day 5 : Chat UI (Frontend Only)
A simple chat interface with message sending and display functionality.
Concepts: DOM manipulation, event handling, dynamic UI updates.