# A quantity calculator in any HTML page

> Two lines of HTML and an optional script put a free quantity calculator on any page or CMS. Content-Security-Policy, lazy loading and fixes.

Page: https://craftquantities.com/embeds/html/ (embed guide). This is the page's Markdown copy; the HTML page is the canonical version.

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
- Optional Fitting script
- Lazy Loading
- None Key or account

**On this page Before you start**

## 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-Policy` header with `frame-src` or `child-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

1. 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.
2. Keep the script, or set a height

   The third line, the fitting script, listens for the frame's `size` message and sets its height. It is needed once per page, however many calculators the page holds. Without it, the `height` attribute decides.
3. 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.
4. 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

_The frame, the credit and the fitting script_

```
<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, if you send one_

```
Content-Security-Policy: frame-src https://craftquantities.com
```

Add the address to your existing `frame-src` (or `child-src`) list rather than replacing it.

Every other option is in the [full builder](https://craftquantities.com/embeds/#calculator=gravel-calculator).

## What visitors see

Your page · Driveway project · Materials

Calculator by [Craft Quantities](https://craftquantities.com/calculators/landscaping-outdoor/gravel-calculator/)

## 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](https://craftquantities.com/embeds/#messages) 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](https://craftquantities.com/api/) and the [MCP server](https://craftquantities.com/developers/mcp/).

## 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 `height` attribute.

**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.

1. [MDN Web Docs: <iframe>: The Inline Frame element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe)
2. [MDN Web Docs: CSP frame-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-src)
3. [MDN Web Docs: Window.postMessage()](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)

On this page

At a glance

**Element**

<iframe>

**Fitting script**

Optional

**Loading**

Lazy

**Key or account**

None

Official links

- [The plugin on WordPress.org](https://wordpress.org/plugins/craft-quantities-calculators/)
- [Developer hub](https://craftquantities.com/developers/)
- [Static JSON API](https://craftquantities.com/api/)
- [Remote MCP server](https://craftquantities.com/developers/mcp/)
- [npm package](https://craftquantities.com/developers/npm/)

The one rule

Keep the visible credit line under the frame: it is the one condition of the free embed.

**Open:** the engine’s answers (its JSON API, MCP server and npm package), the data files under /api/v1/ and the formula library (/formulas/) are published under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/): reuse them, commercially too, crediting “Craft Quantities” with a link. **Reserved:** the page text, the design and the software, the engine’s code included. [The terms of use](https://craftquantities.com/terms/)

[The terms, in full](https://craftquantities.com/embeds/#terms)

[Home](https://craftquantities.com/)

Embed & integrations

Pages

- [Overview and builder](https://craftquantities.com/embeds/)
- [WordPress plugin](https://craftquantities.com/embeds/wordpress/)
- [Shopify](https://craftquantities.com/embeds/shopify/)
- [Wix](https://craftquantities.com/embeds/wix/)
- [Squarespace](https://craftquantities.com/embeds/squarespace/)
- [Webflow](https://craftquantities.com/embeds/webflow/)
- [Google Sites](https://craftquantities.com/embeds/google-sites/)
- [Blogger](https://craftquantities.com/embeds/blogger/)
- [Any HTML page](https://craftquantities.com/embeds/html/)

Developers & integrations

- [Overview and live call](https://craftquantities.com/developers/)
- [API reference](https://craftquantities.com/developers/api-reference/)
- [Static JSON API](https://craftquantities.com/api/)
- [Remote MCP server](https://craftquantities.com/developers/mcp/)
- [npm package](https://craftquantities.com/developers/npm/)
- [Command line](https://craftquantities.com/developers/cli/)
- [WebMCP in the browser](https://craftquantities.com/developers/webmcp/)
- [Claude and ChatGPT](https://craftquantities.com/ai/)
- [Embeds and WordPress](https://craftquantities.com/embeds/)
- [Browser extension](https://craftquantities.com/tools/browser-extension/)
- [Changelog](https://craftquantities.com/developers/changelog/)
- [Service status](https://craftquantities.com/status/)

On this page

- Before you start
- Step by step
- Your code
- What visitors see
- Several calculators, and reading the result
- Troubleshooting
- Why it helps
- Sources

---
Source: https://craftquantities.com/embeds/html/
Craft Quantities: free to read, cite and link to; the pages are not licensed for republication. Quantities only: no prices, no design and no certification.
