Loading your tools...
Loading your tools...
Learn to build a concrete calculator in 10 detailed steps! We break it down into simple parts so anyone can understand the magic behind the code.
Hey there! 👋
Building your own web tool feels like a superpower. Instead of just using the internet, you can create it.
Today, we’re going to build a Concrete Calculator. This tool helps builders know exactly how many bags of cement they need for a project.
Think of it like a recipe:
Let's start cooking!
First, we need a reliable container for our tool. We'll call it calculator-box. This is where all our inputs and buttons will live.
<div id="calculator-box">
<h2>🚧 Concrete Wizard</h2>
<!-- We will put inputs here -->
</div>
We need to ask the user: "How long is the slab?".
We use an <input> box that only accepts numbers.
<label>Length (feet):</label>
<input type="number" id="len" placeholder="e.g. 10">
Next ingredient: "How wide is it?".
<label>Width (feet):</label>
<input type="number" id="wid" placeholder="e.g. 10">
Usually, people measure thickness in inches, not feet. So we'll specify that here. (Don't worry, we'll fix the math later!)
<label>Thickness (inches):</label>
<input type="number" id="thk" placeholder="e.g. 4">
We need a button to start the calculation. We'll tell it to run a function called doTheMath when clicked.
<button onclick="doTheMath()">Calculate Bags Needed</button>
Where do we show the answer? We'll create a hidden area that pops up with the result.
<div id="result-area">
<p>You need: <b id="bag-count">0</b> Bags (80lb)</p>
<p class="small text">Total Volume: <span id="vol-count">0</span> Cubic Yards</p>
</div>
Now for the brain. The formula for concrete is:
Volume = Length x Width x Thickness.
But wait! Length and Width are in feet, but Thickness is in inches. So we must divide thickness by 12.
Volume (Cubic Feet) = Length * Width * (Thickness / 12)
And finally, concrete is sold in Cubic Yards. There are 27 cubic feet in 1 cubic yard.
Cubic Yards = Cubic Feet / 27
<script>
function doTheMath() {
// 1. Get numbers
var l = parseFloat(document.getElementById('len').value);
var w = parseFloat(document.getElementById('wid').value);
var t = parseFloat(document.getElementById('thk').value);
// 2. The Formula
var cubicFeet = l * w * (t / 12);
var cubicYards = cubicFeet / 27;
}
</script>
Builders always order a little extra in case they spill some. This is called a Safety Margin. We usually add 10%.
And then, we calculate how many bags needed. A standard 80lb bag covers about 0.022 cubic yards. (Or simply: 1 Cubic Yard needs roughly 45 bags).
// ... inside the function
// Add 10% extra
var totalYards = cubicYards * 1.10;
// Calculate 80lb bags (45 bags make a yard)
var bags = Math.ceil(totalYards * 45);
// Show results
document.getElementById('bag-count').innerText = bags;
document.getElementById('vol-count').innerText = totalYards.toFixed(2);
Let's make it look like a construction tool! We'll use Safety Orange and Blueprint Blue colors.
<style>
#calculator-box {
background-color: #f0f9ff;
border: 3px solid #0284c7;
padding: 25px;
border-radius: 15px;
max-width: 350px;
font-family: os-bold, sans-serif;
margin: 20px auto;
}
label { font-weight: bold; color: #333; display: block; margin-top: 10px; }
input {
width: 100%;
padding: 10px;
border: 2px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
background-color: #f97316; /* Safety Orange */
color: white;
width: 100%;
padding: 15px;
margin-top: 20px;
border: none;
border-radius: 8px;
font-size: 18px;
font-weight: bold;
cursor: pointer;
}
button:hover { background-color: #ea580c; }
#result-area {
margin-top: 20px;
padding: 15px;
background: white;
border-radius: 8px;
border-left: 5px solid #0284c7;
}
</style>
Here is the finished code. Copy it, save it as concrete.html, and start building!
<!DOCTYPE html>
<html>
<head>
<title>Concrete Calculator</title>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #fffbe6; display: flex; justify-content: center; min-height: 100vh; align-items: center; margin: 0; }
.card {
background: white;
padding: 2rem;
border-radius: 1rem;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
width: 340px;
border-top: 6px solid #f59e0b; /* Amber/Orange Top */
}
h2 { text-align: center; color: #451a03; margin-top: 0; }
label { display: block; font-weight: 600; color: #78350f; margin-bottom: 0.5rem; margin-top: 1rem; }
input {
width: 100%;
padding: 0.75rem;
border: 2px solid #fde68a;
border-radius: 0.5rem;
font-size: 1rem;
box-sizing: border-box;
outline: none;
}
input:focus { border-color: #f59e0b; }
button {
width: 100%;
margin-top: 1.5rem;
padding: 1rem;
background: #f59e0b;
color: white;
border: none;
border-radius: 0.5rem;
font-weight: 800;
font-size: 1.1rem;
cursor: pointer;
text-transform: uppercase;
letter-spacing: 1px;
transition: 0.2s;
}
button:hover { background: #d97706; transform: translateY(-2px); }
.result-box {
background: #ffffff;
margin-top: 1.5rem;
padding: 1rem;
border: 2px dashed #d97706;
border-radius: 0.5rem;
text-align: center;
}
.big-number { font-size: 2.5rem; font-weight: 900; color: #d97706; display: block; line-height: 1; margin-bottom: 5px; }
.sub-text { color: #92400e; font-size: 0.9rem; }
</style>
</head>
<body>
<div class="card">
<h2>🚧 Concrete Wizard</h2>
<label>Length (feet)</label>
<input type="number" id="len" placeholder="e.g. 12">
<label>Width (feet)</label>
<input type="number" id="wid" placeholder="e.g. 10">
<label>Thickness (inches)</label>
<input type="number" id="thk" placeholder="e.g. 4">
<button onclick="calc()">Calculate Bags</button>
<div class="result-box">
<span class="big-number" id="bags">0</span>
<span class="sub-text">Bags of Premix (80lb)</span>
<hr style="border:0; border-top:1px dashed #fbbf24; margin: 10px 0;">
<span class="sub-text">Volume: <span id="yards">0</span> cu. yards</span>
</div>
</div>
<script>
function calc() {
// 1. Get Inputs
let l = parseFloat(document.getElementById('len').value) || 0;
let w = parseFloat(document.getElementById('wid').value) || 0;
let t = parseFloat(document.getElementById('thk').value) || 0;
if(l==0 || w==0 || t==0) { alert("Please fill all fields!"); return; }
// 2. Math
// Volume in Cubic Feet = L * W * (T/12)
let volFeet = l * w * (t / 12);
// Volume in Cubic Yards = Feet / 27
let volYards = volFeet / 27;
// Add 10% Waste Margin
let totalYards = volYards * 1.10;
// Bags (Approx 45 bags per yard)
let bags = Math.ceil(totalYards * 45);
// 3. Display
document.getElementById('bags').innerText = bags;
document.getElementById('yards').innerText = totalYards.toFixed(2);
}
</script>
</body>
</html>
Solid work! 🧱
You just built a tool that saves real people real money. No more guessing how much concrete to buy.
Try the Pro Concrete Calculator »Developer Tools & Resource Experts
FastTools is dedicated to curating high-quality content and resources that empower developers. With nearly 5 years of hands-on development experience, our team rigorously evaluates every tool and API we recommend, ensuring you get only the most reliable and effective solutions for your projects.