Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

Building a zero-dependency California car sales tax calculator from the CDTFA rate table

I sell used cars in Irvine, California, and the question I hear most after "does it have a clean title?" is "how much will the tax be?". The honest answer is "it depends on where you will register the car", and that is s

I sell used cars in Irvine, California, and the question I hear most after "does it have a clean title?" is "how much will the tax be?". The honest answer is "it depends on where you will register the car", and that is surprisingly hard for buyers to look up. So I built a small calculator. This post is about how it works under the hood: one HTML file, no framework, no tracking, no network requests after the page loads.

The rule the code has to follow

In California the sales or use tax on a car is based on the buyer's address, where the car will be registered, not on where the seller is. A dealer collects sales tax at the sale; on a private-party purchase the buyer pays use tax to the DMV at registration. Either way, the number you need is the combined rate (state + local + district taxes) for one specific city or unincorporated county area.

The California Department of Tax and Fee Administration (CDTFA) publishes that table: California City & County Sales & Use Tax Rates. The release I used is effective October 1, 2026 and has 541 places, from the 7.25% statewide base up to 11.75%.

Step 1: turn the table into a tiny array

The source is a spreadsheet with a lot of columns I don't need. A short build script keeps three fields per row - place name, rate, county - and writes them as a JavaScript array literal straight into the page:

window.__RATES = [
  ["Irvine", 7.75, "Orange"],
  ["Santa Ana", 9.25, "Orange"],
  ["Long Beach", 11.0, "Los Angeles"],
  // ... 541 rows in total
];

As a compact array of arrays, 541 rows is small enough to inline. Inlining means the calculator works offline, can be saved with Ctrl+S, and can be embedded in an iframe on any site without CORS or a CDN.

Step 2: lookup by name, not by ZIP

My first idea was ZIP codes, but ZIP codes don't line up with city limits or tax districts, so a ZIP-based lookup would quietly give wrong answers near borders. The tool asks for the city (or "X County" for unincorporated areas) through a <datalist>, so people get autocomplete with plain HTML, and the code builds a lowercase index once:

var R = window.__RATES || [], by = {};
R.forEach(function (x) { by[x[0].toLowerCase()] = x; });

For an exact street address the final word is still CDTFA's own address lookup, and the page says so.

Step 3: the math, in cents

function calc() {
  var loc = by[String($('c-loc').value).trim().toLowerCase()];
  var rate = loc ? loc[1] : null;
  var taxable = num('c-price') + num('c-dealer');      // price + taxable dealer fees
  var tax = rate === null ? 0 : Math.round(taxable * rate) / 100;
  $('o-rate').textContent  = rate === null ? '—' : rate + '%';
  $('o-tax').textContent   = rate === null ? '—' : money(tax);
  $('o-total').textContent = rate === null ? '—' : money(taxable + tax + num('c-dmv'));
}

A few decisions hidden in those lines:

  • Math.round(taxable * rate) / 100. The rate is a percent (7.75), so taxable * rate is already the tax in cents. Rounding there avoids the classic 0.1 + 0.2 float noise in the displayed dollars.
  • No trade-in field. In California a trade-in does not reduce the taxable amount, and a field for it would invite people to subtract it.
  • DMV fees are an input, not a formula. Registration fees have several parts that depend on the vehicle, so the tool doesn't guess them; the user can paste the number from the DMV fee calculator and get an out-the-door total.
  • num() strips everything except digits and the dot, so "$24,500" pasted from a listing still works.

Step 4: shareable state through the URL

Every input listens to input and change, and on load the page reads ?city= and ?price= from the query string:

var q = new URLSearchParams(location.search);
if (q.get('city') && by[q.get('city').toLowerCase()]) $('c-loc').value = by[q.get('city').toLowerCase()][0];
if (q.get('price')) $('c-price').value = q.get('price');
calc();

That gives prefilled links like ?city=Irvine&price=18500 for free, with no state library. One gotcha I hit on another tool: some hosts that embed pages in iframes append their own query parameters (for example a cache-busting ?v=<timestamp>), so only read parameter names you own and validate the values.

Step 5: keeping it honest

The calculator is only as good as the table, and CDTFA rates change (usually on January 1, April 1, July 1 and October 1). So the page states the effective date of the rates at the top and an "Updated" date in the footer, and the build script is rerun when a new table comes out. It also states plainly that it is an estimate, not tax advice.

Try it or reuse it

The live version with all 541 places is here: California car sales tax calculator. The single-file version is MIT licensed, so feel free to copy the approach for your own state's rate table.

If you've built something similar for another state, I'd like to hear how you handled district taxes and boundary cases.

I wrote the calculator and this post with help from an AI assistant and checked the code and the tax rules against the CDTFA and DMV sources myself.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.