Percentage calculator for your website
Four percentage questions in one small widget, each answered in a sentence as well as a number. Free on any site, one snippet, no account.
Accent colour
The real widget, running here with your settings.
What it does
"Percentage calculator" means four different sums depending on who is asking, so the widget has a tab for each. What is 20% of 250. 50 is what percent of 250. From 200 to 250 is what change. And 50 is 20% of what number, which is the one people reach for when working backwards from a sale price.
Each answer comes with the sentence that goes with it, so 20% of 250 shows 50 and then reads "20% of 250 is 50." That sounds like a small thing. It is the difference between a reader trusting the number and quietly wondering which way round it went.
Percentage change handles a negative starting value using its size rather than its sign, and says increase or decrease in words. Each tab keeps its own pair of numbers, so switching between them does not wipe what was typed.
The full version is the percentage calculator on this site.
How to install it
Copy the code above and paste it into your page where you want the calculator to show. It is ordinary HTML, so it goes wherever HTML goes.
WordPress
In the block editor, add a Custom HTML block and paste the code into it. In the classic editor, switch from Visual to Text first. For a sidebar, use a Custom HTML widget under Appearance, then Widgets. Some managed hosts strip script tags from posts written by non-administrator accounts, in which case paste it while signed in as an administrator.
Wix, Squarespace and Shopify
Wix: add an Embed HTML element and paste the code into the code panel. Squarespace: add a Code block and turn off Display Source. Shopify: paste it into a section or page written in the code editor rather than the rich text field, which removes scripts.
Plain HTML
Paste both lines into the body of the page. The script tag can sit next to the div or at the end of the document, and it only needs to appear once even if the page holds several calculators.
Settings you can change
Every option is a data attribute on the div, so the script itself never needs editing.
| Attribute | What it does | Example |
|---|---|---|
data-theme | Light or dark surface | dark |
data-accent | Colour of the answer and link | #7c3aed |
data-title | Heading text, or empty for none | Work out a percentage |
data-mode | Which question it opens on | change |
The widget renders inside a shadow root with its own stylesheet, so your site's CSS cannot reach in and break it, and your own rules are equally safe from ours. It caps itself at 400px wide and shrinks to fit anything narrower. To control where it sits, wrap the div in a container of your own.
Terms of use
By using this code you agree:
- The materials are provided as is, without warranty of any kind.
- Not to alter the calculation logic in the script.
- Not to remove the "powered by Calculator Castle" credit link.
- That copyright in the code belongs to calculatorcastle.com.
- Not to remove these terms from the standalone version.
Results are estimates for planning and carry no warranty. Neither you nor your visitors should treat the output as professional advice.
Common questions
Questions about the widget
Is the widget free?
Yes, on any site, including commercial ones. No fee, no account and no usage limit. The one condition is that the "powered by Calculator Castle" link stays visible.
Which four calculations does it do?
Percent of a number, one number as a percent of another, percentage change between two numbers, and working back to a total from a part and its percentage. The tabs switch between them and each keeps its own numbers.
Can it open on a particular tab?
Yes, with the data-mode attribute. A retail page might open on percentage change, a tax page on percent of a number. Visitors can still switch.
How does it handle a decrease?
Percentage change says increase or decrease in words rather than leaving a reader to work out what a minus sign means. Going from 250 to 200 reads as a decrease of 20%.
What happens with zero?
It explains rather than showing an error code. A percentage of zero and a change starting from zero are both undefined, and the widget says so in a sentence.
How big is it?
10 KB, around 3.6 KB compressed over the wire, loaded with the async attribute so it never blocks your page. No libraries, no fonts, no images and no network requests once loaded.
Will it clash with my site styles?
No. It renders inside a shadow root with its own stylesheet, so your CSS cannot reach into it and its CSS cannot leak out. We test that against a page that sets width, colour and font on every input and button with !important.
Does it track my visitors?
No. It sets no cookies, stores nothing and sends nothing back to us. Everything is worked out in the browser of the person using it, so it needs no cookie banner of its own.