Here's a simple web app that provides a CRUD interface (Create, Read, Update, Delete) using browser storage, specifically localStorage, which is persistent across sessions.
This example includes:
- A basic HTML UI
- JavaScript to handle CRUD operations
- Styling with minimal CSS
✅ Features
- Add new records (with name and email)
- View all saved records
- Edit existing records
- Delete records
- Data stored in
localStorage
📁 Project Structure
You can create this as a single index.html file or split into separate files (style.css, script.js) if preferred.
🌐 Full Code: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>LocalStorage CRUD App</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 30px;
background-color: #f4f4f4;
}
h2 {
color: #333;
}
form {
margin-bottom: 20px;
}
input[type="text"],
input[type="email"] {
padding: 6px;
margin-right: 10px;
width: 150px;
}
button {
padding: 6px 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
text-align: left;
padding: 8px;
border-bottom: 1px solid #ccc;
}
.actions button {
margin-right: 5px;
}
</style>
</head>
<body>
<h2>LocalStorage CRUD App</h2>
<form id="user-form">
<input type="text" id="name" placeholder="Name" required />
<input type="email" id="email" placeholder="Email" required />
<button type="submit">Add User</button>
</form>
<table id="users-table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th class="actions">Actions</th>
</tr>
</thead>
<tbody>
<!-- Users will be listed here -->
</tbody>
</table>
<script>
const form = document.getElementById('user-form');
const nameInput = document.getElementById('name');
const emailInput = document.getElementById('email');
const tableBody = document.querySelector('#users-table tbody');
let users = [];
// Load data from localStorage
function loadUsers() {
const stored = localStorage.getItem('users');
users = stored ? JSON.parse(stored) : [];
renderTable();
}
// Save data to localStorage
function saveUsers() {
localStorage.setItem('users', JSON.stringify(users));
}
// Render table rows
function renderTable() {
tableBody.innerHTML = '';
users.forEach((user, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${user.name}</td>
<td>${user.email}</td>
<td class="actions">
<button onclick="editUser(${index})">Edit</button>
<button onclick="deleteUser(${index})">Delete</button>
</td>
`;
tableBody.appendChild(row);
});
}
// Handle form submit
form.addEventListener('submit', function(e) {
e.preventDefault();
const newUser = {
name: nameInput.value,
email: emailInput.value
};
users.push(newUser);
saveUsers();
renderTable();
form.reset();
});
// Edit user
window.editUser = function(index) {
const user = users[index];
nameInput.value = user.name;
emailInput.value = user.email;
// Remove original entry
users.splice(index, 1);
saveUsers();
renderTable();
};
// Delete user
window.deleteUser = function(index) {
if (confirm("Are you sure you want to delete this user?")) {
users.splice(index, 1);
saveUsers();
renderTable();
}
};
// Initialize
loadUsers();
</script>
</body>
</html>
🧪 How to Use
- Save the above code in a file named
index.html.
- Open it in your browser.
- Add users via the form.
- Edit or delete entries from the table.
💾 Storage Info
All data is stored under the key "users" in localStorage.
To view or clear it manually:
- Open Developer Tools → Application tab → Local Storage
- You'll see the key-value pair there.
🚀 Optional Enhancements
- Add unique IDs for each record
- Validate email format
- Add search/filter functionality
- Sort by name/email
- Add pagination
Would you like me to turn this into a downloadable project or package it as a React/Vue app?