QRCode
Generate and display QR codes
Source
LLM docs
Docs
Package
Usage
QRCode encodes a string into a QR code and renders it as an SVG. The encoder is
bundled with the component: no additional dependencies or network requests are
required, and the component works with server-side rendering:
Size
Set size prop to control the width and height of the code. Numbers are
converted to rem, strings are used as is:
Colors
Use color prop to change the color of the dark modules and
bg style prop to change the background color.
Keep a high contrast between the two colors so that the code stays scannable:
Error correction level
errorCorrectionLevel prop controls how much of the code can be damaged or
covered while remaining readable. Higher levels produce a denser code:
L– recovers up to ~7% of dataM– recovers up to ~15% of data (default)Q– recovers up to ~25% of dataH– recovers up to ~30% of data
Low (~7%)
Medium (~15%)
Quartile (~25%)
High (~30%)
Capacity
The amount of data a QR code can hold depends on the error correction level. The limits below are for text encoded as UTF-8 bytes, non-ASCII characters take 2–4 bytes each:
L– about 2953 bytesM– about 2331 bytesQ– about 1663 bytesH– about 1273 bytes
When the value is longer than the capacity, QRCode renders an empty code.
encodeQR throws a RangeError in this case, use it to validate user input:
Logo
Pass any React node to the logo prop to display it in the center of the code.
The logo covers part of the code, set errorCorrectionLevel="H" to make
sure the code can still be scanned:
Custom rendering with encodeQR
To fully control the appearance (rounded dots, gradients, canvas export, etc.), use
encodeQR function to get the module matrix and render it yourself:
Finder patterns (the three large squares in the corners) and alignment patterns must stay solid squares so that scanners can locate the code. Other modules can have any shape:
Accessibility
By default, aria-label of the code is the encoded value. Set aria-label
or aria-labelledby prop to provide a more descriptive name:
To hide a decorative code that is duplicated by nearby text, use attributes prop
of the Styles API: