Here's a cozy and inviting calorie tracking website – all in one HTML file with embedded CSS and JavaScript. The design features a warm, minimal look, nice fonts, and smooth interactions to make the user feel welcome and comfortable while entering their meals.
You can save the entire code as an .html file and open it in your browser.
✅ Features:
- Add meals with name and calories
- See a list of meals
- Automatically update total calories
- Option to delete a meal
🍎 Cozy Calorie Tracker – Single File Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cozy Calorie Tracker</title>
<style>
/* Reset and Fonts */
* {
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
}
body {
background: #fffbe6;
color: #333;
padding: 40px 20px;
display: flex;
justify-content: center;
align-items: flex-start;
min-height: 100vh;
}
.container {
background: #ffffff;
padding: 30px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
width: 100%;
max-width: 500px;
}
h1 {
text-align: center;
margin-bottom: 24px;
color: #d6863a;
}
.form-group {
margin-bottom: 16px;
}
label {
display: block;
margin-bottom: 6px;
font-weight: 600;
}
input[type="text"],
input[type="number"] {
width: 100%;
padding: 10px;
border: 2px solid #f0d9b5;
border-radius: 8px;
font-size: 16px;
background: #fffdf6;
}
button {
background-color: #ffb347;
color: #fff;
font-weight: bold;
padding: 10px 16px;
border: none;
border-radius: 8px;
cursor: pointer;
width: 100%;
font-size: 16px;
transition: background 0.3s ease;
}
button:hover {
background-color: #ffa033;
}
.meal-list {
margin-top: 30px;
}
.meal-item {
background-color: #fff7e6;
padding: 12px 16px;
border-radius: 8px;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.meal-name {
font-weight: 500;
}
.meal-calories {
font-weight: bold;
color: #e67e22;
}
.delete-btn {
background: none;
border: none;
font-size: 16px;
color: #e74c3c;
cursor: pointer;
margin-left: 10px;
}
.total {
margin-top: 20px;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #2d3436;
}
</style>
</head>
<body>
<div class="container">
<h1>🍽️ Cozy Calorie Tracker</h1>
<div class="form-group">
<label for="meal">Meal Name</label>
<input type="text" id="meal" placeholder="e.g. Chicken Salad">
</div>
<div class="form-group">
<label for="calories">Calories</label>
<input type="number" id="calories" placeholder="e.g. 350">
</div>
<button onclick="addMeal()">Add Meal</button>
<div class="meal-list" id="mealList"></div>
<div class="total" id="totalCalories">Total Calories: 0</div>
</div>
<script>
let meals = [];
function addMeal() {
const mealInput = document.getElementById("meal");
const caloriesInput = document.getElementById("calories");
const mealName = mealInput.value.trim();
const calories = parseInt(caloriesInput.value);
if (!mealName || isNaN(calories) || calories <= 0) {
alert("Please enter a valid meal and calorie number.");
return;
}
const meal = {
id: Date.now(),
name: mealName,
calories: calories
};
meals.push(meal);
mealInput.value = "";
caloriesInput.value = "";
renderMeals();
}
function deleteMeal(id) {
meals = meals.filter(meal => meal.id !== id);
renderMeals();
}
function renderMeals() {
const mealList = document.getElementById("mealList");
mealList.innerHTML = "";
let totalCalories = 0;
meals.forEach(meal => {
const mealItem = document.createElement("div");
mealItem.className = "meal-item";
mealItem.innerHTML = `
<div>
<div class="meal-name">${meal.name}</div>
<div class="meal-calories">${meal.calories} Cal</div>
</div>
<button class="delete-btn" onclick="deleteMeal(${meal.id})">✖</button>
`;
totalCalories += meal.calories;
mealList.appendChild(mealItem);
});
document.getElementById("totalCalories").textContent = `Total Calories: ${totalCalories}`;
}
</script>
</body>
</html>
🧡 Optional Ideas for Expansion:
- Save data to localStorage
- Add meal time or category (breakfast, lunch, etc.)
- Display calories with a daily goal/progress bar
- Dark mode toggle
Let me know if you'd like to expand it!