HTML guide
Any CMS · static sites · hand-written pages
A quantity calculator in any HTML page
If your site takes HTML, it takes the calculator: an iframe tag, a credit paragraph, and an optional script that fits the frame's height. Joomla, Drupal, Ghost, a static site generator or a hand-written page all work the same way.
- <iframe>Element
- OptionalFitting script
- LazyLoading
- NoneKey or account
Before you start
- A place in your page's HTML or your CMS's HTML field where the calculator should appear.
- If your site sends a
Content-Security-Policyheader withframe-srcorchild-src, the right to change it. - If that policy forbids inline scripts, a way to load the fitting script as a file, or a fixed height instead.
Step by step
Paste the frame and the credit
Put the first two lines of the code below where the calculator belongs. The
loading="lazy"attribute makes the browser load the frame only as it nears the screen.Keep the script, or set a height
The third line, the fitting script, listens for the frame's
sizemessage and sets its height. It is needed once per page, however many calculators the page holds. Without it, theheightattribute decides.Allow the frame in your policy
If your site has a frame policy, add this site to
frame-src(second block below). A page with no Content-Security-Policy needs nothing.Check it
Load the page, type a measurement and watch the result update. In the browser's console, a refused frame names the directive that blocked it.
Your code
<iframe src="https://craftquantities.com/embed/?calc=gravel-calculator&ev=1&fmt=compact" width="100%" height="460" loading="lazy" style="border:1px solid #e4e4e7;border-radius:12px;max-width:100%" title="Gravel Calculator — Craft Quantities"></iframe>
<p style="margin:4px 0 0;font:12px/1.4 system-ui,sans-serif">Calculator by <a href="https://craftquantities.com/calculators/landscaping-outdoor/gravel-calculator/">Craft Quantities</a></p>
<script>(function(){if(window.cqEmbedFit)return;window.cqEmbedFit=1;window.addEventListener("message",function(e){var d=e.data;if(!d||d.source!=="craft-quantities"||d.type!=="size"||typeof d.height!=="number"||!isFinite(d.height))return;var f=document.getElementsByTagName("iframe");for(var i=0;i<f.length;i++){if(f[i].contentWindow!==e.source)continue;var a=document.createElement("a");a.href=f[i].src;if(a.protocol+"//"+a.host!==e.origin)return;f[i].style.height=Math.min(6000,Math.max(200,Math.ceil(d.height)))+"px";return}})})();</script>Paste as is. The title attribute names the frame for screen readers; the credit paragraph is ordinary HTML on your page and must stay visible.
Content-Security-Policy: frame-src https://craftquantities.comAdd the address to your existing frame-src (or child-src) list rather than replacing it.
Every other option is in the full builder.
What visitors see
Calculator by Craft Quantities
Several calculators, and reading the result
Each calculator is its own frame and credit line. Put the fitting script on the page once; it matches each size message to the frame that sent it.
Your page can also read each answer: the frame posts a result message on every change. The message reference shows a listener that checks the sender first.
For your own interface rather than a frame, the same calculators are on the static JSON API and the MCP server.
Troubleshooting
- The frame says the page refused to connect
- Your site's Content-Security-Policy does not list this site in
frame-src. Add it, as in the second block. - The height never changes
- The fitting script did not run: your policy blocks inline scripts, or the CMS stripped the tag. Load it as a file, or set the
heightattribute. - The frame stays blank until scrolled to
- That is
loading="lazy"working: the frame loads as it nears the screen. Remove the attribute to load it at once. - The CMS removes the iframe
- Some editors strip iframes for users without the right permission or in their visual mode. Use the CMS's HTML or source mode, or ask an administrator.
Why it helps
- Any page becomes a tool page: a materials list, a project write-up or a supplier's product sheet answers "how much?" in place.
- The frame isolates the calculator from your styles and scripts, so it cannot break your page and your page cannot break it.
- Every result is in both unit systems, with sources on the calculator's own page, which the credit links to.
Sources
Checked against these help pages on 26 November 2026.