For developers · html5-qrcode

Try the scanner.
Build it into your app.

Test QR and barcode scanning with your camera or an image, then use the same library in your own website.

01 / LIVE DEMO

Scan a code

v2.3.0

Allow camera access when prompted, or switch to an image file. Codes are decoded in this browser.

Loading the scanner…

Download sample image

02 / OUTPUT

Decoded results

Your results appear here

Scan a code to inspect its text and format. This demo never opens a decoded link automatically.

    The latest 10 results stay in this tab until you clear them or leave.

    Images and decoded contents are not uploaded. ScanApp analytics records demo actions and outcomes without the image, filename or decoded text.

    03 / QUICK START

    From demo to your website

    Full getting-started guide ↗

    Serve this example over HTTPS, or on localhost while developing. It uses the same pinned library version as the live demo above.

    index.html
    <!doctype html>
    <html lang="en">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>QR and barcode scanner</title>
    <div id="reader" style="width: 100%; max-width: 600px"></div>
    <pre id="result"></pre>
    <script src="https://unpkg.com/html5-qrcode@2.3.0/html5-qrcode.min.js"></script>
    <script>
      function onScanSuccess(decodedText, decodedResult) {
        // Use textContent to display a result safely.
        document.getElementById("result").textContent = decodedText;
      }
    
      const scanner = new Html5QrcodeScanner("reader", {
        fps: 10,
        qrbox: (width, height) => {
          const size = Math.floor(Math.min(width, height) * 0.75);
          return { width: size, height: size };
        }
      });
      scanner.render(onScanSuccess);
    </script>
    </html>

    Using npm? Install html5-qrcode@2.3.0 and import Html5QrcodeScanner in your JavaScript. This page pins v2.3.0 to preserve the original demo; it is not a claim that this is the latest release.

    Stop scanning after a result

    Clear the scanner when the user is finished. The promise resolves after the camera and scanner UI have been cleaned up.

    let finished = false;
    function onScanSuccess(text, result) {
      if (finished) return;
      finished = true;
      document.getElementById("result").textContent = text;
      scanner.clear().catch(console.error);
    }

    Pass this callback to scanner.render(onScanSuccess) instead of the callback in the example above.

    Adjust the configuration

    fps
    Controls how frequently frames are checked. Higher values use more CPU.
    qrbox
    Sets the scan region. A function keeps it responsive to the camera view.
    formatsToSupport
    Limits decoding to the formats your app needs.
    showTorchButtonIfSupported
    Shows a torch control when the camera and browser support it.
    Explore the API reference ↗

    If a code doesn’t scan

    Check camera access

    Use HTTPS or localhost, allow camera permission and close other apps using the camera. Permissions on the old demo site do not carry over to this domain.

    Try an image

    Use a clear photo or screenshot with the entire code visible. Switch away from the camera before selecting an image.

    Ignore normal frame misses

    A frame without a readable code is expected. Show success in the callback; avoid treating every scan-failure callback as a user-facing error.

    JUST NEED TO SCAN?

    Use ScanApp’s ready-to-use scanner.

    Read a code without adding a library to your own website.

    Open QR scanner ↗

    Adapted from the original developer demo. Apache 2.0 license · Notices.