1. Reference
  2. Media

<qr-scanner>

A live camera viewfinder that reads QR codes and runs on-scan with the code it found.

Media Uses camera

This tag has more than one name. Every spelling is the same tag, so write whichever feels natural. Pick one and every example on this page uses it.

This tag needs a camera, so try it on your phone.

qr-scanner.ham
<column style="gap-12">
    <qr-scanner id="scan"
                style="h-320 rounded-lg"
                on-scan="$code = $event.value"/>
    <text style="muted">Point the camera at a ticket's QR code.</text>
</column>
The snippet drawn by Hype Apps on a phone, in light mode The snippet drawn by Hype Apps on a phone, in dark mode
This snippet as Hype Apps draws it on a phone. It follows this page's light or dark theme.

Attributes

NameWhat it doesDefault
cooldown Seconds before the same code can fire again. Unset: each code fires once while the scanner is on screen.
number
facing Which camera.
back, front
back
frame Draw the corner brackets showing where to hold the code.
boolean
true
torch Start with the torch on.
boolean
false

Commands

NameWhat it does
pause Stop reading codes (the preview stays); \$id.scanning goes false.
reset Forget the codes already read, so each can fire again.
resume Read codes again.
torch Toggle the torch, or set it; \$id.torch follows.

Events

NameWhat it does
on-scan Statements to run when a code is read (same as @on.scan / action-scan): on-scan="auth:pair:\$event.query.code".

Readings

NameWhat it does
scanning Whether codes are being read.
torch Whether the torch is on.
value The last code read.

Any tag also takes gestures: @on.tap, @on.longpress, @on.doubletap and @on.swipeleft (and right, up and down). @click runs on a tap too.

This page is also Markdown, and all of HAM is in llms.txt.