<cs-qr-code>
StableMediaSince 0.1

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 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.

Image

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.

Generating from a Value

Bind an input to the value property to build a live generator that updates the code as the user types.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/qr-code/qr-code.js';
import './cornerstone/components/qr-code/qr-code.js';
import CsQrCode from '@cruglobal/cornerstone-components/react/qr-code/index.js';

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
backgroundbackgroundThe background color. This can be any valid CSS color or transparent. It cannot be a CSS custom property.string''
errorCorrectionerror-correctionThe level of error correction to use. Learn more'L' | 'M' | 'Q' | 'H''H'
fillfillThe fill color. This can be any valid CSS color, but not a CSS custom property.string''
labellabelThe label for assistive devices to announce. If unspecified, the value will be used instead.string''
radiusradiusThe edge radius of each module. Must be between 0 and 0.5.number0
sizesizeThe size of the QR code, in pixels.number128
valuevalueThe QR code's value.string''

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
qr-codeThe component's outer wrapper.::part(qr-code)