QR Code
QR codes encode a URL or other short text into a scannable image, rendered client-side using the Canvas API. Use them to share links, contact info, or Wi-Fi credentials that visitors can scan with a phone.
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.
Examples
Size
Use the size attribute to change the size of the QR code.
Colors
The QR code's fill color is determined by the current text color. To change it, set the CSS color property on the host element or an ancestor element.
The canvas is always transparent, so use the background or background-color CSS property on the host element to set a background color.
A quiet zone is the blank space around a QR code that helps scanners detect it more reliably. Use the padding CSS property on the host element to add one.
Corner Color
You can change the color of the corners to be different from the main element with the --corner-color custom property.
Radius
Create a rounded effect with the radius attribute.
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.
Images
Use the image attribute to add a logo or image to the center of the QR code. When using an image, the error correction level will automatically be set to H to ensure the code remains scannable.
Image Coverage
Use the image-coverage attribute to control how much of the QR code the image is allowed to cover, from 0 to 1. The default is 0.5.
The higher the image-coverage value, the harder it will be for QR readers to scan. For example, 1.0 usually makes the QR code unreadable.
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/qr-code/qr-code.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/qr-code/qr-code.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/qr-code/qr-code.js';
To import this component for React 18 or below, use the following code:
import WaQrCode from '@awesome.me/webawesome/dist/react/qr-code/index.js';
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
backgroundbackground |
The background color. This can be any valid CSS color or
transparent. It cannot be a CSS custom property.
Type
string
Default
''
|
||
errorCorrectionerror-correction |
The level of error correction to use. Learn more
Type
'L' | 'M' | 'Q' | 'H'
Default
'H'
|
||
fillfill |
The fill color. This can be any valid CSS color, but not a CSS custom property.
Type
string
Default
''
|
||
labellabel |
The label for assistive devices to announce. If unspecified, the value will be used instead.
Type
string
Default
''
|
||
radiusradius |
The edge radius of each module. Must be between 0 and 0.5.
Type
number
Default
0
|
||
sizesize |
The size of the QR code, in pixels.
Type
number
Default
128
|
||
valuevalue |
The QR code's value.
Type
string
Default
''
|
CSS parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The component's base wrapper. |
::part(base)
|