A look at the math, the user interface decisions, and how everything is implemented.
Every percentage calculation reduces to one of four formulas:
| Mode | Question | Formula |
|---|---|---|
| 1 | What is P% of X? | Y = X × P ÷ 100 |
| 2 | Y is what % of X? | P = Y ÷ X × 100 |
| 3 | Y is P% of what? | X = Y × 100 ÷ P |
| 4 | X changed by P% | Y = X × (1 ± P ÷ 100) |
Every input has an input event listener. When you type, the active mode’s formula runs, and the result is rewritten into the DOM along with the formula and the substituted equation.
Each mode generates an ordered list showing the math step by step:
The numbers in the steps update reactively as you type.
The CSS uses CSS custom properties (variables) for every color. A data-theme="dark" attribute on the <html> element swaps the variable values. The user’s choice is saved to localStorage so it persists across visits.
The current calculation mode and input values are serialized into URL query parameters. Loading a shared link parses the parameters, populates the fields, switches to the right mode, and runs the calculation. No server involved.
This is why the calculator works offline after the first load, and why your inputs never leave your device.
The whole site is plain HTML, CSS, and JavaScript — no React, no Vue, no build step. About 400 lines of JS total. Pages typically load in under a second on a fast connection.