Skip to Content
Documentation
Getting startedComponentsChartsTheming
Get Pro
Overview
Concepts

QR Code

Used to generate a QR code based on the provided data

Recipe

Anatomy

import { QrCode } from '@chakra-ui/react'
<QrCode.Root value="...">
  <QrCode.Frame>
    <QrCode.Pattern />
  </QrCode.Frame>
  <QrCode.Overlay />
  <QrCode.DownloadTrigger fileName="..." mimeType="image/png" />
</QrCode.Root>

Examples

Sizes

Use the size prop to set the size of the QR code.

Logo Overlay

Pass the children prop to the QrCode.Overlay component to add a logo or overlay to the QR code.

Fill

Set the fill style on the QrCode.Frame component to change the color of the QR code pattern.

Download

Use the QrCode.DownloadTrigger to download the QR code.

The fileName and the mimeType props are required.

Error Correction

In cases where the link is too long or the logo overlay covers a significant area, the error correction level can be increased.

Use the encoding.ecc or encoding.boostEcc property to set the error correction level:

  • L: Allows recovery of up to 7% data loss (default)
  • M: Allows recovery of up to 15% data loss
  • Q: Allows recovery of up to 25% data loss
  • H: Allows recovery of up to 30% data loss

Input

Here's an example of how to use the QrCode component with an Input component.

Props

Root

PropDefaultType
colorPalette 'gray'
'base' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'sidebar' | 'sidebar.accent' | 'interaction' | 'accent' | 'presence' | 'status' | 'slate'

The color palette of the component

size 'md'
'2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full'

The size of the component

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
defaultValue
string

The initial value to encode when rendered. Use when you don't need to control the value of the qr code.

encoding
QrCodeGenerateOptions

The qr code encoding options.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string; frame: string }>

The element ids.

onValueChange
(details: ValueChangeDetails) => void

Callback fired when the value changes.

pixelSize
number

The pixel size of the qr code.

value
string

The controlled value to encode.

DownloadTrigger

PropDefaultType
fileName *
string

The name of the file.

mimeType *
DataUrlType

The mime type of the image.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
quality
number

The quality of the image.