QR Code
<wa-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.
<div class="qr-overview"> <wa-qr-code value="https://shoelace.style/" label="Scan this code to visit Web Awesome on the web!"></wa-qr-code> <br /> <wa-input maxlength="255" with-clear label="Value"> <wa-icon slot="start" name="link"></wa-icon> </wa-input> </div> <script> const container = document.querySelector('.qr-overview'); const qrCode = container.querySelector('wa-qr-code'); const input = container.querySelector('wa-input'); customElements.whenDefined('wa-qr-code').then(() => { input.value = qrCode.value; input.addEventListener('input', () => (qrCode.value = input.value)); }); </script> <style> .qr-overview { max-width: 256px; } .qr-overview wa-input { margin-top: 1rem; } </style>
Examples
Jump to heading
Size
Jump to heading
Use the size attribute to change the size of the QR code.
<wa-qr-code value="https://shoelace.style/" size="64"></wa-qr-code>
Colors
Jump to heading
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.
<wa-qr-code value="https://shoelace.style/" style=" color: var(--wa-color-indigo-20); background-color: var(--wa-color-indigo-90); border-radius: var(--wa-border-radius-m); padding: 1rem; " ></wa-qr-code>
Radius
Jump to heading
Create a rounded effect with the radius attribute.
<wa-qr-code value="https://shoelace.style/" radius="0.5"></wa-qr-code>
Error Correction
Jump to heading
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.
<div class="qr-error-correction"> <wa-qr-code value="https://shoelace.style/" error-correction="L"></wa-qr-code> <wa-qr-code value="https://shoelace.style/" error-correction="M"></wa-qr-code> <wa-qr-code value="https://shoelace.style/" error-correction="Q"></wa-qr-code> <wa-qr-code value="https://shoelace.style/" error-correction="H"></wa-qr-code> </div> <style> .qr-error-correction { display: flex; flex-wrap: wrap; gap: 1rem; } </style>
Importing
Jump to heading
Autoloading components via projects is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
Let your project code do the work! Sign up for free to use a project with your very own CDN — it's the fastest and easiest way to use Web Awesome.
To manually import this component from NPM, use the following code.
import '@awesome.me/webawesome/dist/components/qr-code/qr-code.js';
To manually import this component from React, use the following code.
import WaQrCode from '@awesome.me/webawesome/dist/react/qr-code';
Attributes & Properties
Jump to heading
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
stringDefault
'' |
||
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
stringDefault
'' |
||
labellabel |
The label for assistive devices to announce. If unspecified, the value will be used instead.
Type
stringDefault
'' |
||
radiusradius |
The edge radius of each module. Must be between 0 and 0.5.
Type
numberDefault
0 |
||
sizesize |
The size of the QR code, in pixels.
Type
numberDefault
128 |
||
valuevalue |
The QR code's value.
Type
stringDefault
'' |
CSS parts
Jump to heading
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The component's base wrapper. |
::part(base)
|