<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Expense Tracker</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 0; background-color: #f0f0f0; } header { background-color: #333; color: #fff; padding: 1em; text-align: center; } #expenses { width: 60%; margin: 2em auto; background-color: #fff; padding: 1em; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } table { width: 100%; border-collapse: collapse; margin-top: 1em; } th, td { border: 1px solid #ddd; padding: 12px; text-align: left; } th { background-color: #333; color: #fff; } form { width: 50%; margin: 2em auto; background-color: #fff; padding: 1em; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } label, input, button { display: block; margin-bottom: 1em; } button { background-color: #333; color: #fff; padding: 0.8em; cursor: pointer; border: none; border-radius: 4px; } #totalExpense { margin-top: 1em; font-size: 18px; } </style> </head> <body> <header> <h1>Expense Tracker</h1> </header> <form id="expenseForm"> <label for="expenseName">Expense Name:</label> <input type="text" id="expenseName" required> <label for="expenseAmount">Expense Amount:</label> <input type="number" id="expenseAmount" required> <button type="button" onclick="addExpense()">Add Expense</button> </form> <div id="expenses"> <h2>Expense List</h2> <table> <thead> <tr> <th>Name</th> <th>Amount</th> </tr> </thead> <tbody id="expenseList"></tbody> </table> <div id="totalExpense">Total Expense: $0</div> </div> <script> let totalExpense = 0; function addExpense() { const name = document.getElementById("expenseName").value; const amount = parseFloat(document.getElementById("expenseAmount").value); if (name && !isNaN(amount) && amount > 0) { const expenseList = document.getElementById("expenseList"); const newRow = document.createElement("tr"); newRow.innerHTML = `<td>${name}</td><td>$${amount.toFixed(2)}</td>`; expenseList.appendChild(newRow); totalExpense += amount; updateTotalExpense(); // Additional logic to save data to backend or local storage } else { alert("Please enter valid values."); } } function updateTotalExpense() { const totalExpenseElement = document.getElementById("totalExpense"); totalExpenseElement.textContent = `Total Expense: $${totalExpense.toFixed(2)}`; } </script> </<!-- Existing HTML remains unchanged --> <div id="expenses"> <h2>Expense List</h2> <table> <!-- Existing table structure remains unchanged --> <tfoot> <tr> <td> <button id="downloadBtn" onclick="downloadExpenseSheet()">Download Expense Sheet</button> </td> </tr> </tfoot> </table> <div id="totalExpense">Total Expense: $0</div> </div> <!-- Existing JavaScript remains unchanged --> <script> function downloadExpenseSheet() { const data = generateExpenseData(); const blob = new Blob([data], { type: 'text/plain' }); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'expense_sheet.txt'; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); } function generateExpenseData() { const rows = Array.from(document.getElementById("expenseList").getElementsByTagName("tr")); const data = rows.map(row => Array.from(row.children).map(cell => cell.textContent).join('\t')).join('\n'); return `Name\tAmount\n${data}`; } </script> <!-- Existing HTML remains unchanged --> <body> </html>
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>