Skip to main content

Build a Simple Expense Tracker App Using HTML, CSS, and JavaScript

Managing finances can be tricky, but with the right tools, it becomes much easier. In this project, I’ll walk you through building a basic Expense Tracker App using HTML, CSS, and JavaScript. This app will allow users to track their expenses, categorize them, and view the total expense amount in real-time.




What You'll Learn:

  • Structuring a web page using HTML.
  • Styling your app using CSS for a clean and responsive layout.
  • Implementing interactivity using JavaScript to add, remove, and calculate expenses dynamically.
  • Storing and retrieving expense data using the browser's local storage.


Features of the Expense Tracker App

  1. Add Expenses: Users can input expenses and assign categories like Food, Travel, Shopping, etc.
  2. Delete Expenses: Users can remove unwanted or incorrect expenses.
  3. Real-Time Calculation: The total expenses update instantly as users add or delete entries.
  4. Local Storage: Expenses persist even after refreshing the page, thanks to local storage.


Tech Stack Used

  • HTML: For structuring the app's user interface.
  • CSS: To make the app visually appealing and responsive.
  • JavaScript: To handle the logic for adding expenses, calculating totals, and managing local storage.

 

Html Code


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Expense Tracker App</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <div class="container">
      <h1>Expense Tracker</h1>
      <div class="new-expense">
        <input type="text" id="expense-description" placeholder="Enter expense">
        <input type="number" id="expense-amount" placeholder="Amount">
        <button onclick="addExpense()">Add Expense</button>
      </div>
      <ul id="expense-list"></ul>
      <h2>Total: $<span id="total-amount">0</span></h2>
    </div>
    <script src="app.js"></script>
  </body>
</html>

CSS Code


<style>
  body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
  }
  .container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    background-color: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  }
  h1 {
    text-align: center;
  }
  .new-expense input {
    margin-right: 10px;
  }
  #expense-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #ccc;
  }
</style>

JS Code


<script>
  let totalAmount = 0;
  function addExpense() {
    const description = document.getElementById('expense-description').value;
    const amount = parseFloat(document.getElementById('expense-amount').value);
    
    if (description && amount) {
      const expenseList = document.getElementById('expense-list');
      const li = document.createElement('li');
      li.textContent = `${description} - $${amount}`;
      expenseList.appendChild(li);
      
      totalAmount += amount;
      document.getElementById('total-amount').textContent = totalAmount.toFixed(2);
      
      document.getElementById('expense-description').value = '';
      document.getElementById('expense-amount').value = '';
    } else {
      alert('Please enter both description and amount.');
    }
  }
</script>



4. Exploring More Features (Optional):

You can further enhance the app by adding features such as:

  • Expense Categories: Allow users to categorize their expenses (e.g., Food, Travel, Shopping).
  • Edit Expenses: Enable users to edit their existing expenses.
  • Chart Visualization: Visualize expense data using libraries like Chart.js.




Live Demo and Source Code:

Check out the live demo  Feel free to clone and modify it for your own projects!



Conclusion:

Building an Expense Tracker App with HTML, CSS, and JavaScript is a fantastic way to sharpen your front-end development skills. This project covers key concepts like DOM manipulation, local storage, and responsive design. By completing this app, you’ll be better equipped to build more complex applications in the future. 

Comments

Blog Post Ad Unit

Popular posts from this blog

Master Real-Time Chat Apps: Build with Laravel, Livewire, Tailwind CSS, and Alpine.js

Dive into the world of real-time chat applications and learn how to leverage Laravel, Livewire, Tailwind CSS, and Alpine.js to create seamless, interactive experiences. Unlock the power of modern web development by mastering real-time chat applications with Laravel, Livewire, Tailwind CSS, and Alpine.js. Whether you're a beginner eager to learn or an experienced developer looking to enhance your skills, this course will take you on a transformative journey through the TALL-Stack, providing you with the tools and knowledge to build dynamic and interactive chat systems. Why Choose This Course? In today’s fast-paced digital world, real-time communication is crucial. This course is designed to empower you with the skills needed to create robust, efficient, and engaging chat applications using Laravel and Livewire. Laravel, a leading PHP framework, offers a strong foundation, while Livewire simplifies and enhances interactivity. Together, they form a powerful duo that will revolutionize...

Master ASCII and Unicode Char Detection: Fun Project Using HTML, CSS, & JS

ASCII and Unicode Char Detector: Fun Project with HTML, CSS & JS Master the ASCII & Unicode Char Detector: Building Fun with HTML, CSS, and JS Ever wondered how computers translate those everyday characters like '@' or '#' into something they understand? It's all magic—or maybe just ASCII and Unicode . 😏 In this post, we’ll walk you through an amazing project where you can build your very own ASCII and Unicode Character Detector using HTML , CSS , and JavaScript . Trust me, this is one project you’ll want to show off to your friends! 🚀 Why Should You Care? Characters are everywhere! From passwords to text messages, ASCII and Unicode are behind the scenes, helping computers understand what we type. Creating a detector helps you understand how these character sets work—and you get to look like a coding genius while doing it. 😉 What's Inside the Project? Learn the difference between AS...