📝 HTML Notes App Tutorial for Beginners (Full Project)
In this tutorial, you will learn how to build a fully functional Notes App using HTML, CSS, and JavaScript. This app works on all devices and saves notes even after refreshing the page!
✨ Features of This Notes App
- Add new notes
- Edit notes
- Delete notes
- Dark Mode
- Search notes
- Auto-save using LocalStorage
- No backend needed
📌 Step 1 — HTML Structure
<div class="container">
<h1>Notes App</h1>
<button id="toggleDark">🌙 Dark Mode</button>
<input type="text" id="searchBox" placeholder="Search notes...">
<textarea id="noteInput" placeholder="Write your note here..."></textarea>
<button id="addNote">Add Note</button>
<div id="notesList"></div>
</div>
📌 Step 2 — CSS Styling
<style>
body {
font-family: Arial;
background: #f4f4f4;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 10px;
}
textarea {
width: 100%;
height: 120px;
margin-top: 10px;
padding: 10px;
}
.note {
background: #fff8cc;
padding: 10px;
border-radius: 10px;
margin-top: 10px;
}
.note button {
margin-right: 5px;
}
.dark {
background: #222 !important;
color: white !important;
}
.dark textarea,
.dark input {
background: #444;
color: #fff;
}
.dark .note {
background: #333;
color: #fff;
}
</style>
📌 Step 3 — JavaScript (Add, Edit, Delete, Search, Dark Mode)
<script>
let notes = JSON.parse(localStorage.getItem("notes") || "[]");
function saveNotes() {
localStorage.setItem("notes", JSON.stringify(notes));
}
function displayNotes() {
const list = document.getElementById("notesList");
list.innerHTML = "";
let search = document.getElementById("searchBox").value.toLowerCase();
notes.forEach((note, index) => {
if (note.toLowerCase().includes(search)) {
list.innerHTML += `
<div class='note'>
<p>${note}</p>
<button onclick="editNote(${index})">Edit</button>
<button onclick="deleteNote(${index})">Delete</button>
</div>
`;
}
});
}
function addNote() {
let noteText = document.getElementById("noteInput").value.trim();
if (noteText === "") return alert("Write something first!");
notes.push(noteText);
saveNotes();
displayNotes();
document.getElementById("noteInput").value = "";
}
function deleteNote(i) {
notes.splice(i, 1);
saveNotes();
displayNotes();
}
function editNote(i) {
let newNote = prompt("Edit your note:", notes[i]);
if (newNote !== null) {
notes[i] = newNote;
saveNotes();
displayNotes();
}
}
document.getElementById("addNote").onclick = addNote;
document.getElementById("searchBox").oninput = displayNotes;
document.getElementById("toggleDark").onclick = () => {
document.body.classList.toggle("dark");
};
displayNotes();
</script>
🎉 FULL NOTES APP (All Code Together)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Notes App</title>
<style>
body {
font-family: Arial;
background: #f4f4f4;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 10px;
}
textarea {
width: 100%;
height: 120px;
margin-top: 10px;
padding: 10px;
}
.note {
background: #fff8cc;
padding: 10px;
border-radius: 10px;
margin-top: 10px;
}
.note button {
margin-right: 5px;
}
.dark {
background: #222 !important;
color: white !important;
}
.dark textarea,
.dark input {
background: #444;
color: #fff;
}
.dark .note {
background: #333;
color: #fff;
}
</style>
</head>
<body>
<div class="container">
<h1>Notes App</h1>
<button id="toggleDark">🌙 Dark Mode</button>
<input type="text" id="searchBox" placeholder="Search notes...">
<textarea id="noteInput" placeholder="Write your note here..."></textarea>
<button id="addNote">Add Note</button>
<div id="notesList"></div>
</div>
<script>
let notes = JSON.parse(localStorage.getItem("notes") || "[]");
function saveNotes() {
localStorage.setItem("notes", JSON.stringify(notes));
}
function displayNotes() {
const list = document.getElementById("notesList");
list.innerHTML = "";
let search = document.getElementById("searchBox").value.toLowerCase();
notes.forEach((note, index) => {
if (note.toLowerCase().includes(search)) {
list.innerHTML += `
<div class='note'>
<p>${note}</p>
<button onclick="editNote(${index})">Edit</button>
<button onclick="deleteNote(${index})">Delete</button>
</div>
`;
}
});
}
function addNote() {
let noteText = document.getElementById("noteInput").value.trim();
if (noteText === "") return alert("Write something!");
notes.push(noteText);
saveNotes();
displayNotes();
document.getElementById("noteInput").value = "";
}
function deleteNote(i) {
notes.splice(i, 1);
saveNotes();
displayNotes();
}
function editNote(i) {
let newNote = prompt("Edit your note:", notes[i]);
if (newNote !== null) {
notes[i] = newNote;
saveNotes();
displayNotes();
}
}
document.getElementById("addNote").onclick = addNote;
document.getElementById("searchBox").oninput = displayNotes;
document.getElementById("toggleDark").onclick = () => {
document.body.classList.toggle("dark");
};
displayNotes();
</script>
</body>
</html>

Comments
Post a Comment