Finance & Investing

Free Crypto Converter Widget

Convert crypto to fiat with rates you supply yourself.

A simple crypto-to-fiat converter with an amount input and two dropdowns. You supply the exchange rates as a small JSON snapshot (or point the widget at your own endpoint), so it works fully offline with no API keys or third-party calls. Paste one script tag where you want it to appear.

Live demo

Embed this widget

Paste either snippet into your page — a Custom HTML block on WordPress, Shopify, or Squarespace works too. Both snippets update live as you customize, so what you copy is exactly what you configured.

Hosted (recommended)html
<script src="https://hayneslab.dev/widgets/crypto-converter.js" data-hl-config='{"BTC":{"USD":67000,"EUR":62000},"ETH":{"USD":3500,"EUR":3250},"SOL":{"USD":160,"EUR":148}}' data-hl-default-from="BTC" data-hl-default-to="USD" data-hl-amount="0.5" async></script>
<!-- Free Crypto Converter widget by haynes lab — https://hayneslab.dev/tools/widgets/crypto-converter -->
Inline (self-contained)html
<!-- Free Crypto Converter widget by haynes lab — https://hayneslab.dev/tools/widgets/crypto-converter -->
<script data-hl-config='{"BTC":{"USD":67000,"EUR":62000},"ETH":{"USD":3500,"EUR":3250},"SOL":{"USD":160,"EUR":148}}' data-hl-default-from="BTC" data-hl-default-to="USD" data-hl-amount="0.5">
/*!
 * haynes lab — Crypto Converter widget (free)
 * Docs & embed code: https://hayneslab.dev/tools/widgets/crypto-converter
 */
(function () {
  'use strict';

  var PREFIX = 'hlw-crypto-converter';
  var STYLE_ID = 'hlw-crypto-converter-styles';

  function findScript() {
    return document.currentScript ||
      document.querySelector('script[src*="widgets/crypto-converter.js"]');
  }

  function injectStyles() {
    if (document.getElementById(STYLE_ID)) return;
    var css =
      '.' + PREFIX + ', .' + PREFIX + ' * { box-sizing: border-box; }' +
      '.' + PREFIX + ' { position: relative; max-width: 420px; margin: 0 auto; padding: 24px 24px 32px;' +
      ' font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;' +
      ' font-size: 16px; line-height: 1.5; color: #1f2937; background: #ffffff;' +
      ' border: 1px solid #e5e7eb; border-radius: 12px; }' +
      '.' + PREFIX + '__title { margin: 0 0 16px; font-size: 18px; font-weight: 600; color: #111827; }' +
      '.' + PREFIX + '__label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase;' +
      ' letter-spacing: 0.04em; color: #6b7280; margin: 0 0 6px; }' +
      '.' + PREFIX + '__field { margin-bottom: 14px; }' +
      '.' + PREFIX + '__input, .' + PREFIX + '__select { width: 100%; padding: 10px 12px; font: inherit;' +
      ' color: #1f2937; background: #ffffff; border: 1px solid #d1d5db; border-radius: 8px; }' +
      '.' + PREFIX + '__input:focus, .' + PREFIX + '__select:focus { outline: 2px solid var(--hlw-accent);' +
      ' outline-offset: 0; border-color: var(--hlw-accent); }' +
      '.' + PREFIX + '__pair { display: flex; gap: 10px; }' +
      '.' + PREFIX + '__pair .' + PREFIX + '__field { flex: 1; min-width: 0; margin-bottom: 0; }' +
      '.' + PREFIX + '__result { margin-top: 18px; padding: 14px 16px; background: #f9fafb;' +
      ' border: 1px solid #e5e7eb; border-radius: 8px; }' +
      '.' + PREFIX + '__result-value { font-size: 22px; font-weight: 700; color: var(--hlw-accent);' +
      ' word-break: break-all; }' +
      '.' + PREFIX + '__result-rate { font-size: 13px; color: #6b7280; margin-top: 2px; }' +
      '.' + PREFIX + '__note { margin: 12px 0 0; font-size: 11px; color: #9ca3af; }' +
      '.' + PREFIX + '__credit { position: absolute; right: 10px; bottom: 6px; font-size: 11px;' +
      ' display: inline-flex; align-items: center; gap: 4px; color: #9ca3af; text-decoration: none; }' +
      '.' + PREFIX + '__credit svg { display: block; }' +
      '.' + PREFIX + '__credit:hover { color: #6b7280; text-decoration: underline; }' +
      '@media (max-width: 420px) { .' + PREFIX + '__pair { flex-direction: column; } }';
    var style = document.createElement('style');
    style.id = STYLE_ID;
    style.textContent = css;
    document.head.appendChild(style);
  }

  function el(tag, className, text) {
    var node = document.createElement(tag);
    if (className) node.className = className;
    if (text != null) node.textContent = text;
    return node;
  }

  function logoSvg() {
    var svgNS = 'http://www.w3.org/2000/svg';
    var svg = document.createElementNS(svgNS, 'svg');
    svg.setAttribute('viewBox', '0 0 32 32');
    svg.setAttribute('width', '13');
    svg.setAttribute('height', '13');
    svg.setAttribute('aria-hidden', 'true');
    svg.setAttribute('focusable', 'false');
    function circle(cx, cy, r, attrs) {
      var c = document.createElementNS(svgNS, 'circle');
      c.setAttribute('cx', cx);
      c.setAttribute('cy', cy);
      c.setAttribute('r', r);
      for (var key in attrs) c.setAttribute(key, attrs[key]);
      svg.appendChild(c);
    }
    circle(16, 16, 16, { fill: '#0f0a0a' });
    circle(16, 16, 12, { fill: 'none', stroke: '#fff5f5', 'stroke-width': 1, opacity: 0.3 });
    circle(16, 16, 9, { fill: 'none', stroke: '#fff5f5', 'stroke-width': 1, opacity: 0.5 });
    circle(16, 16, 6, { fill: 'none', stroke: '#fff5f5', 'stroke-width': 1.2, opacity: 0.9 });
    circle(16, 16, 3, { fill: '#06b6d4' });
    circle(24.5, 7.5, 2, { fill: '#f97316' });
    circle(7, 16, 1.8, { fill: '#f97316' });
    circle(20, 20, 1.5, { fill: '#f97316' });
    return svg;
  }

  function validRates(data) {
    if (!data || typeof data !== 'object' || Array.isArray(data)) return null;
    var clean = {};
    Object.keys(data).forEach(function (crypto) {
      var row = data[crypto];
      if (!row || typeof row !== 'object' || Array.isArray(row)) return;
      var out = {};
      Object.keys(row).forEach(function (fiat) {
        var n = Number(row[fiat]);
        if (isFinite(n) && n > 0) out[fiat] = n;
      });
      if (Object.keys(out).length) clean[crypto] = out;
    });
    return Object.keys(clean).length ? clean : null;
  }

  function loadRates(script, done) {
    var raw = script.getAttribute('data-hl-config');
    if (raw) {
      try {
        var rates = validRates(JSON.parse(raw));
        if (rates) return done(rates);
        console.warn('[haynes lab crypto-converter] data-hl-config has no usable rates ({CRYPTO:{FIAT:number}}).');
      } catch (e) {
        console.warn('[haynes lab crypto-converter] data-hl-config is not valid JSON.', e);
      }
    }
    var endpoint = script.getAttribute('data-hl-endpoint');
    if (!endpoint) {
      if (!raw) console.warn('[haynes lab crypto-converter] Provide data-hl-config (rates JSON) or data-hl-endpoint. Nothing rendered.');
      return done(null);
    }
    fetch(endpoint)
      .then(function (res) {
        if (!res.ok) throw new Error('HTTP ' + res.status);
        return res.json();
      })
      .then(function (data) {
        var rates = validRates(data);
        if (!rates) console.warn('[haynes lab crypto-converter] Endpoint returned no usable rates ({CRYPTO:{FIAT:number}}).');
        done(rates);
      })
      .catch(function (e) {
        console.warn('[haynes lab crypto-converter] Failed to load rates from data-hl-endpoint.', e);
        done(null);
      });
  }

  function formatMoney(n, fiat) {
    var decimals = n >= 1 ? 2 : 6;
    try {
      return new Intl.NumberFormat(undefined, {
        style: 'currency', currency: fiat,
        minimumFractionDigits: 2, maximumFractionDigits: decimals
      }).format(n);
    } catch (e) {
      return n.toLocaleString(undefined, { maximumFractionDigits: decimals }) + ' ' + fiat;
    }
  }

  function build(script, rates) {
    var cryptos = Object.keys(rates);
    var fiats = [];
    cryptos.forEach(function (c) {
      Object.keys(rates[c]).forEach(function (f) {
        if (fiats.indexOf(f) === -1) fiats.push(f);
      });
    });

    var title = script.getAttribute('data-hl-title') || 'Crypto Converter';
    var accent = script.getAttribute('data-hl-accent') || '#f97316';
    var defaultFrom = (script.getAttribute('data-hl-default-from') || '').toUpperCase();
    var defaultTo = (script.getAttribute('data-hl-default-to') || '').toUpperCase();
    var amount0 = parseFloat(script.getAttribute('data-hl-amount'));
    if (!isFinite(amount0) || amount0 < 0) amount0 = 1;
    if (cryptos.indexOf(defaultFrom) === -1) defaultFrom = cryptos[0];
    if (fiats.indexOf(defaultTo) === -1) defaultTo = fiats[0];

    injectStyles();

    var root = el('div', PREFIX);
    root.style.setProperty('--hlw-accent', accent);
    root.appendChild(el('h3', PREFIX + '__title', title));

    var amountField = el('div', PREFIX + '__field');
    var amountLabel = el('label', PREFIX + '__label', 'Amount');
    var amount = el('input', PREFIX + '__input');
    amount.type = 'number';
    amount.min = '0';
    amount.step = 'any';
    amount.value = String(amount0);
    amount.id = PREFIX + '-amount-' + Math.random().toString(36).slice(2, 8);
    amountLabel.setAttribute('for', amount.id);
    amountField.appendChild(amountLabel);
    amountField.appendChild(amount);
    root.appendChild(amountField);

    function makeSelect(id, labelText, options, selected) {
      var field = el('div', PREFIX + '__field');
      var label = el('label', PREFIX + '__label', labelText);
      var select = el('select', PREFIX + '__select');
      select.id = id;
      label.setAttribute('for', id);
      options.forEach(function (code) {
        var opt = el('option', null, code);
        opt.value = code;
        if (code === selected) opt.selected = true;
        select.appendChild(opt);
      });
      field.appendChild(label);
      field.appendChild(select);
      return { field: field, select: select };
    }

    var uid = amount.id.replace(PREFIX + '-amount-', '');
    var from = makeSelect(PREFIX + '-from-' + uid, 'From', cryptos, defaultFrom);
    var to = makeSelect(PREFIX + '-to-' + uid, 'To', fiats, defaultTo);
    var pair = el('div', PREFIX + '__pair');
    pair.appendChild(from.field);
    pair.appendChild(to.field);
    root.appendChild(pair);

    var result = el('div', PREFIX + '__result');
    result.setAttribute('aria-live', 'polite');
    var valueEl = el('div', PREFIX + '__result-value');
    var rateEl = el('div', PREFIX + '__result-rate');
    result.appendChild(valueEl);
    result.appendChild(rateEl);
    root.appendChild(result);

    function update() {
      var n = parseFloat(amount.value);
      var crypto = from.select.value;
      var fiat = to.select.value;
      var rate = rates[crypto] && rates[crypto][fiat];
      if (!rate) {
        valueEl.textContent = '—';
        rateEl.textContent = 'No ' + crypto + '/' + fiat + ' rate in the supplied data.';
        return;
      }
      if (!isFinite(n) || n < 0) n = 0;
      valueEl.textContent = formatMoney(n * rate, fiat);
      rateEl.textContent = '1 ' + crypto + ' = ' + formatMoney(rate, fiat);
    }

    amount.addEventListener('input', update);
    from.select.addEventListener('change', update);
    to.select.addEventListener('change', update);
    update();

    root.appendChild(el('p', PREFIX + '__note',
      'Rates are a snapshot supplied by this site\u2019s owner and may differ from live market prices.'));

    var credit = el('a', PREFIX + '__credit');
    credit.appendChild(logoSvg());
    credit.appendChild(document.createTextNode('Powered by haynes lab'));
    credit.href = 'https://hayneslab.dev/tools/widgets/crypto-converter';
    credit.target = '_blank';
    credit.rel = 'noopener';
    root.appendChild(credit);

    if (script.parentNode && script.parentNode.nodeName !== 'HEAD') {
      script.insertAdjacentElement('afterend', root);
    } else {
      document.body.appendChild(root);
    }
  }

  function init() {
    var script = findScript();
    if (!script) {
      console.warn('[haynes lab crypto-converter] Could not locate its own script tag. Nothing rendered.');
      return;
    }
    loadRates(script, function (rates) {
      if (rates) build(script, rates);
    });
  }

  if (document.body) {
    init();
  } else {
    document.addEventListener('DOMContentLoaded', init);
  }
})();

</script>

Configuration

Every option is an attribute on the script tag — the same attributes the customizer above exposes. All attributes are optional unless marked required — defaults apply when omitted.

AttributeDefaultDescription
data-hl-config(none)Rates snapshot as JSON: {"BTC":{"USD":67000,"EUR":62000},"ETH":{"USD":3500}}. Required unless data-hl-endpoint is set. These are owner-supplied snapshots, not live market data.
data-hl-endpoint(none)Optional URL that returns the same rates JSON. Used when data-hl-config is absent, and fetched live on each page load.
data-hl-default-from(first in rates)Crypto code preselected in the "From" dropdown, e.g. "BTC". Falls back to the first crypto in the rates data.
data-hl-default-to(first in rates)Fiat code preselected in the "To" dropdown, e.g. "USD". Falls back to the first fiat in the rates data.
data-hl-amount"1"Number pre-filled in the amount input.
data-hl-title"Crypto Converter"Heading shown at the top of the widget.
data-hl-accent"#f97316"Any CSS color used for the converted result and focus highlights.

Frequently asked questions

How do I install the crypto converter?

Copy the embed snippet and paste it where you want the converter to appear — it renders inline at that spot. Put your rates in the data-hl-config attribute as JSON (e.g. {"BTC":{"USD":67000}}) and the widget builds the crypto and fiat dropdowns from it automatically.

Where do the exchange rates come from?

You supply them. Rates are owner-provided snapshots passed via data-hl-config, or fetched from your own URL via data-hl-endpoint — the widget shows a note to visitors that rates are a snapshot and may differ from live market prices. Update the JSON whenever you want fresher numbers; there are no API keys or third-party services involved.

Does it work on WordPress, Shopify, or Squarespace?

Yes. It is a single dependency-free vanilla JS file — paste the script tag into a Custom HTML block (WordPress, Shopify, Squarespace, Webflow) or directly in your HTML and it just works.

More free widgets

Need a custom widget?

We build custom widgets, integrations, and whole products. Tell us what your site needs and we'll scope it.

Get in Touch