WebAwesome Laminar LogoWebAwesome Laminar

QR Code

Generates a QR code and renders it using the Canvas API.

QR codes are useful for providing small pieces of information to users who can quickly scan them with a smartphone. Most smartphones have built-in QR code scanners, so simply pointing the camera at a QR code will decode it and allow the user to visit a website, dial a phone number, read a message, etc.

val qrValue = Var("https://shoelace.style/")div(  maxWidth.px(256),  QrCode(    _.value <-- qrValue.signal,    _.label := "Scan this code to visit Web Awesome on the web!"  )(),  br(),  Input(    _.maxlength := 255.0,    _.withClear := true,    _.label     := "Value",    _.value <-- qrValue.signal,    _.slots.start(Icon(_.name := "link")())  )(    onInput.mapToValue --> qrValue.writer  ))

Examples

Center Images

Use image to place an image in the center of a QR code. imageCoverage, imagePadding, and imageBackground control its size and surrounding space. Keep the image small and test the result with a QR scanner.

QrCode(  _.value := "https://webawesome.com/",  _.label := "Visit Web Awesome",  _.errorCorrection.h,  _.image := "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Ccircle cx='16' cy='16' r='14' fill='%232563eb'/%3E%3C/svg%3E",  _.imageCoverage := "0.15",  _.imagePadding := "4",  _.imageBackground := "white")()

Colors

Use the fill and background attributes to modify the QR code's colors. You should always ensure good contrast for optimal compatibility with QR code scanners.

QrCode(  _.value      := "https://shoelace.style/",  _.fill       := "deeppink",  _.background := "white")()

Size

Use the size attribute to change the size of the QR code.

QrCode(  _.value := "https://shoelace.style/",  _.size  := 64.0)()

Radius

Create a rounded effect with the radius attribute.

QrCode(  _.value  := "https://shoelace.style/",  _.radius := 0.5)()

Error Correction

QR codes can be rendered with various levels of error correction that can be set using the error-correction attribute. This example generates four codes with the same value using different error correction levels.

QrCode(  _.value           := "https://shoelace.style/",  _.errorCorrection := "L")()QrCode(  _.value           := "https://shoelace.style/",  _.errorCorrection := "M")()QrCode(  _.value           := "https://shoelace.style/",  _.errorCorrection := "Q")()QrCode(  _.value           := "https://shoelace.style/",  _.errorCorrection := "H")()

On this page