---
title: "QR Code · UI SDK — StyleX Blocks"
description: "Scannable code frames with a centered logo overlay, sized from 2xs to 2xl."
url: "https://stylexblocks.com/components/ui-sdk/qr-code/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# QR Code

Scannable code frames with a centered logo overlay, sized from 2xs to 2xl.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/qr-code.md), [Base UI](https://stylexblocks.com/components/base-ui/qr-code.md)
- Category: Display
- Sizes: 2xs, xs, sm, md, lg, xl, 2xl
- HTML page: https://stylexblocks.com/components/ui-sdk/qr-code/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add qr-code
```

Equivalent: `npx shadcn add @stylexblocks/qr-code`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/qr-code.json

## Usage

```tsx
import { QrCode } from "#components/ui/ui-sdk/qr-code.tsx";

export function Example() {
  return (
    // UI SDK ships no QR primitive — Frame is an <svg> (viewBox 0 0 29 29)
    // whose children are the module paths: feed it server-generated QR
    // markup to make it scannable (a decorative grid works for mockups);
    // modules fill with currentColor and every part composes via `render`
    <QrCode.Root size="md">
      <QrCode.Frame aria-label="QR code">
        <path fillRule="evenodd" d="M0 0h7v7H0V0Zm1 1v5h5V1H1Z" />
        <path d="M2 2h3v3H2z" />
        {/* …finder squares and data modules… */}
      </QrCode.Frame>
      <QrCode.Overlay>
        <Logo />
      </QrCode.Overlay>
    </QrCode.Root>
  );
}
```

## Source

`components/ui/ui-sdk/qr-code.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import {
  mergeProps,
  renderElement,
  type PartProps,
  type RenderProp,
} from "@ui-sdk/react/primitive";
import type { StyleOverrideProps } from "#lib/recipe-props.ts";
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'

const qrCodeRoot = stylex.create({
  base: {
    position: 'relative',
    width: 'fit-content',
    '--qr-code-overlay-size': 'calc(var(--qr-code-size) / 3)',
  },
})

const qrCodeRootSizes = stylex.create({
  '2xs': {
    '--qr-code-size': '40px',
  },
  xs: {
    '--qr-code-size': '64px',
  },
  sm: {
    '--qr-code-size': '80px',
  },
  md: {
    '--qr-code-size': '120px',
  },
  lg: {
    '--qr-code-size': '160px',
  },
  xl: {
    '--qr-code-size': '200px',
  },
  '2xl': {
    '--qr-code-size': '240px',
  },
  full: {
    '--qr-code-size': '100%',
  },
})

const qrCodeFrame = stylex.create({
  base: {
    width: 'var(--qr-code-size)',
    height: 'var(--qr-code-size)',
    fill: 'currentColor',
  },
})

const qrCodeOverlay = stylex.create({
  base: {
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    width: 'var(--qr-code-overlay-size)',
    height: 'var(--qr-code-overlay-size)',
    padding: spacing._1,
    backgroundColor: semanticColors.bg,
    borderRadius: semanticRadii.indicatorSm,
  },
})

export type QrCodeSize = keyof typeof qrCodeRootSizes

// The machine-less variant positions the overlay itself (Ark's machine does
// this inline); the recipe supplies the box, background, and radius.
const qrCodeLocal = stylex.create({
  overlay: {
    position: "absolute",
    top: "50%",
    left: "50%",
    translate: "-50% -50%",
  },
});

/**
 * QrCode — UI SDK ships no QR primitive, so the recipe is composed through
 * UI SDK's render helpers (`renderElement` + `mergeProps`). Frame renders an
 * `<svg>` whose children are the module `<path>`s — feed it
 * server-generated QR markup to make it scannable (a decorative placeholder
 * grid works for mockups); modules fill with `currentColor`. Only the root
 * consumes the size axis, so `size` is a plain prop on Root. Every part
 * composes via `render`.
 */
// recipe maps hold stylex.props-compatible values by construction; one cast
// bridges StyleX's variadic generics
function sx(
  styles: ReadonlyArray<unknown>,
  palette: StyleOverrideProps["palette"],
  style: StyleOverrideProps["style"],
) {
  return stylex.props(
    ...([palette, ...styles, style] as unknown as ReadonlyArray<never>),
  );
}

export type QrCodeRootProps = Omit<PartProps<"div">, "style"> &
  StyleOverrideProps & {
    size?: QrCodeSize;
  };

function Root(allProps: QrCodeRootProps) {
  const { size = "md", render, palette, style, ...rest } =
    allProps as QrCodeRootProps & Record<string, unknown>;
  return renderElement(
    "div",
    mergeProps(
      {
        ...sx([qrCodeRoot.base, qrCodeRootSizes[size]], palette as never, style as never),
      },
      rest,
    ),
    render as RenderProp<{ size: QrCodeSize }> | undefined,
    { size },
  );
}
Root.displayName = "QrCodeRoot";

function Frame(allProps: Omit<PartProps<"svg">, "style"> & StyleOverrideProps) {
  const { render, palette, style, ...rest } = allProps as Record<string, unknown>;
  return renderElement(
    "svg",
    mergeProps(
      {
        viewBox: "0 0 29 29",
        role: "img",
        ...sx([qrCodeFrame.base], palette as never, style as never),
      },
      rest,
    ),
    render as RenderProp | undefined,
  );
}
Frame.displayName = "QrCodeFrame";

function Overlay(allProps: Omit<PartProps<"div">, "style"> & StyleOverrideProps) {
  const { render, palette, style, ...rest } = allProps as Record<string, unknown>;
  return renderElement(
    "div",
    mergeProps(
      {
        ...sx(
          [qrCodeOverlay.base, qrCodeLocal.overlay],
          palette as never,
          style as never,
        ),
      },
      rest,
    ),
    render as RenderProp | undefined,
  );
}
Overlay.displayName = "QrCodeOverlay";

export const QrCode = {
  Root,
  Frame,
  Overlay,
};
```
