Most small business owners have no idea what a website costs. They've heard "$500" from a nephew and "$15,000" from an agency, and they don't know which one applies to them. A simple cost calculator on your site answers that question before the first call, filters out people who can't afford you, and gives the ones who can a reason to get in touch.
This post builds one in vanilla JavaScript: no framework, no build step, about 90 lines split into pricing logic and UI. The interesting part isn't the code, it's the pricing model behind it.
Short answer: keep the pricing rules in a small, pure function that takes the options (pages, features, copywriting, care plan) and returns line items plus a low and high range. Keep the UI separate: read a form with FormData, call the function on every input event, format money with Intl.NumberFormat, and render the result into an <output> element. Show a range, not a single number, and say the final quote follows a call.
Start with the pricing model
Before writing code, decide what actually changes your price. For most small business sites it's a short list:
- A base price for design, setup, the homepage and the contact page.
- A price per extra page.
- Feature add-ons like booking, a small shop or a second language.
- Copywriting, if you write the text.
- A monthly care plan, shown separately from the one-off price.
The numbers below are placeholders. Use your own hours and rates, not someone else's price list.
The pricing logic
Pure function, no DOM, easy to test:
// pricing.js: the pricing logic, kept separate from the UI so it is easy to test. export const PRICES = { base: 1200, // design, setup, homepage and contact page perPage: 150, // each extra page beyond the homepage and contact page features: { booking: { label: 'Online booking', price: 400 }, shop: { label: 'Small online shop', price: 1500 }, blog: { label: 'Blog setup', price: 300 }, multilingual: { label: 'Second language', price: 600 }, }, copywriting: 100, // per page, if you write the text carePlanMonthly: 60, // optional monthly care plan }; export function estimate({ pages = 5, features = [], copywriting = false, carePlan = false }, p = PRICES) { const extraPages = Math.max(0, pages - 2); const lines = [ { label: 'Design, setup, homepage and contact page', amount: p.base }, ]; if (extraPages) lines.push({ label: `${extraPages} extra pages`, amount: extraPages * p.perPage }); for (const f of features) { if (!(f in p.features)) throw new Error(`Unknown feature: ${f}`); lines.push({ label: p.features[f].label, amount: p.features[f].price }); } if (copywriting) lines.push({ label: `Copywriting for ${pages} pages`, amount: pages * p.copywriting }); const total = lines.reduce((sum, l) => sum + l.amount, 0); // Show a range, not a single number: scope always moves a little. const low = Math.round((total * 0.9) / 50) * 50; const high = Math.round((total * 1.15) / 50) * 50; return { lines, total, low, high, monthly: carePlan ? p.carePlanMonthly : 0 }; } Two choices worth copying:
- A range instead of one number. Scope always moves a little, and a range sets that expectation from the start.
- Unknown features throw. If the form and the price list drift apart, you find out immediately instead of quoting $0 for a feature.
The form
Plain HTML. Every input has a name, so FormData can read it without any wiring:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Website cost calculator</title> </head> <body> <form id="calc"> <label>Number of pages <input type="number" name="pages" min="1" max="40" value="5"> </label> <fieldset> <legend>Features</legend> <label><input type="checkbox" name="features" value="booking"> Online booking</label> <label><input type="checkbox" name="features" value="shop"> Small online shop</label> <label><input type="checkbox" name="features" value="blog"> Blog</label> <label><input type="checkbox" name="features" value="multilingual"> Second language</label> </fieldset> <label><input type="checkbox" name="copywriting"> I need the text written</label> <label><input type="checkbox" name="carePlan"> Add a monthly care plan</label> </form> <output id="result" for="calc" aria-live="polite"></output> <script type="module" src="app.js"></script> </body> </html> The <output> element with aria-live="polite" means screen readers announce the new estimate when it changes.
The UI code
// app.js: read the form, call estimate(), render the result. import { estimate } from './pricing.js'; const form = document.querySelector('#calc'); const out = document.querySelector('#result'); const money = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }); function render() { const data = new FormData(form); const result = estimate({ pages: Number(data.get('pages')) || 1, features: data.getAll('features'), copywriting: data.has('copywriting'), carePlan: data.has('carePlan'), }); const items = result.lines .map((l) => `<li>${l.label}: ${money.format(l.amount)}</li>`) .join(''); const care = result.monthly ? `<p>Care plan: ${money.format(result.monthly)} per month</p>` : ''; out.innerHTML = ` <p><strong>Estimated range: ${money.format(result.low)} to ${money.format(result.high)}</strong></p> <ul>${items}</ul> ${care} <p>This is an estimate. The final quote follows a short call about your project.</p>`; } form.addEventListener('input', render); render(); Formatting uses the built-in internationalization API:
"The Intl.NumberFormat object enables language-sensitive number formatting."
MDN Web Docs, Intl.NumberFormat
Change 'en-US' and 'USD' to match your market, and the separators and currency symbol follow.
Testing the pricing function
Because the logic is pure, a few assertions with Node's built-in test helpers are enough:
import { estimate } from './pricing.js'; import assert from 'node:assert/strict'; assert.equal(estimate({ pages: 5 }).total, 1200 + 3 * 150); assert.equal(estimate({ pages: 1 }).total, 1200); assert.throws(() => estimate({ features: ['rocket'] })); With 8 pages, booking, a blog, copywriting and a care plan, the placeholder prices give a total of $3,600, shown to the visitor as a range of $3,250 to $4,150 plus $60 a month.
Making it useful for sales
A calculator on its own just shows a number. A few small additions turn it into a lead source:
- Add a "Send me this estimate" button that opens your contact form with the selected options filled in.
- Explain each line in one sentence, so owners learn what they're paying for.
- Show what's included in the base price, so the cheapest option doesn't look empty.
- Track which options people pick. It tells you what to put in your packages.
The calculator helps with people who find you. For reaching businesses that haven't, many freelancers keep a list of local businesses with outdated sites. A lead tool like LeadReef can find local businesses whose websites are outdated, broken on mobile or missing, by city and trade, and the first search is free.
Quick reference
- Keep pricing in a pure function; keep the DOM code separate.
- Read the form with
FormDataand re-render on everyinputevent. - Format money with
Intl.NumberFormat. - Show a range and a monthly line separately, and say the final quote follows a call.
- Test the pricing function with
node:assert.
Sources (checked November 2026): MDN Web Docs, "Intl.NumberFormat"; MDN Web Docs, "FormData" and ": The Output element".


