Skip to content
Nana UI

Data Display & Media

QR Code

Renders a QR code as crisp, scalable SVG. Encodes any text (byte mode, UTF-8) with a self-contained generator — no runtime dependencies. Choose a module style with variant, theme it with CSS custom properties, and drop a logo into the center via the default slot.

View .md Download
N

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add qr-code --framework web-components
npx @nana-tec/ui add qr-code --framework svelte

Lands in src/lib/components/ui/qr-code/ as NanaQrCode.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and each component downloads only the first time a page uses it:

import "@nana-tec/ui-components/autoloader";
import "@nana-tec/ui-components/theme";

The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.

Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:

import "@nana-tec/ui-components/qr-code";

Copied in with npx @nana-tec/ui add qr-code? Import your project's own @/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.

<script lang="ts">
import { NanaQrCode } from '$lib/components/ui/qr-code';
</script>
<NanaQrCode value="https://pay.example.com/unit-4b" size={180} variant="rounded" label="Pay rent for Unit 4B" />

The code is drawn as SVG by a generator with no dependencies, so it stays crisp at any size. The modules take the text colour. Put a logo in the middle with logo (a monogram) or children (an image), and raise errorCorrection to Q or H so the code still scans.

<nana-qr-code value="https://design.nanatec.co.ke"></nana-qr-code>

The variant attribute changes how modules are drawn — square (default), rounded, or dots. (The demos below set explicit colors so they stay crisp in both light and dark; by default the module color follows your theme.)

Override the colour tokens to brand the code. Keep strong contrast between foreground and background so it stays scannable.

Higher levels (Q, H) tolerate more damage or occlusion — required if you overlay a center logo.

For a simple text monogram, set the logo attribute — the badge is styled for you (defaults to the module color, white text, rounded), tunable via CSS variables. For a custom image, slot an <img> instead. Always pair either with error-correction="H" so the code stays scannable behind the overlay.

<nana-qr-code value="https://nanatec.co.ke" logo="N" error-correction="H"></nana-qr-code>
<nana-qr-code value="https://nanatec.co.ke" error-correction="H">
<img src="/logo.svg" alt="Nanatec" />
</nana-qr-code>

Properties

PropertyAttributeTypeDefaultDescription
errorCorrectionerror-correctionQrCodeErrorCorrection'M'Error-correction level (higher tolerates more damage / occlusion)
labellabelstring''Accessible label (defaults to the encoded value)
logologostring''Short monogram (e.g. "N") rendered as a styled center badge automatically. Prefer this over the slot for simple text logos.
marginmarginnumber4Quiet-zone width, in modules
sizesizenumber160Rendered size in pixels (width and height)
valuevaluestring''The data to encode
variantvariantQrCodeVariant'square'Module shape style

Slots

SlotDescription
(default)Optional center logo / overlay (e.g. an <img>). Use a high error-correction level so the code stays scannable. For a simple monogram, use the logo attribute instead — the badge is styled for you.

CSS parts

PartDescription
::part(frame)The bordered background frame
::part(svg)The SVG element
::part(modules)The <path> of dark modules
::part(logo)The center logo/monogram container; carries has-logo, logo--mono
::part(placeholder)The placeholder
::part(logo-mono)The logo mono

CSS custom properties

PropertyDescription
--nana-qr-foregroundModule colour
--nana-qr-backgroundBackground / quiet-zone colour
--nana-qr-radiusFrame corner radius
--nana-qr-logo-sizeLogo width / monogram tile size (default 22% / 2.25rem)
--nana-qr-logo-bgMonogram tile background (default: the module colour)
--nana-qr-logo-colorMonogram text colour (default #fff)
--nana-qr-logo-radiusMonogram tile corner radius (default 0.5rem)
--nana-qr-logo-font-sizeText size of the centre monogram
--nana-qr-logo-padPadding around the centre monogram

NanaQrCode

PropTypeDefault
valuerequiredstring
sizenumber160
variantQrVariant'square'
errorCorrectionQrEcc'M'
marginnumber4
labelstring
logostring
childrenSnippet

Also accepts Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children'>.