---
title: "QR Code · Ark UI — StyleX Blocks"
description: "Scannable code frames with a centered logo overlay, sized from 2xs to 2xl."
url: "https://stylexblocks.com/components/ark-ui/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: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/qr-code.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/qr-code.md)
- Category: Display
- Sizes: 2xs, xs, sm, md, lg, xl, 2xl
- HTML page: https://stylexblocks.com/components/ark-ui/qr-code/

## Install

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

```sh
npx stylexblocks init
```

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/ark-ui/qr-code.json

## Usage

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

export function Example() {
  return (
    // the real Ark QrCode machine wearing the recipe styles — it encodes
    // the value into a scannable matrix and positions the logo overlay;
    // modules fill with currentColor
    <QrCode.Root defaultValue="https://stylexblocks.com" size="md">
      <QrCode.Frame>
        <QrCode.Pattern />
      </QrCode.Frame>
      <QrCode.Overlay>
        <Logo />
      </QrCode.Overlay>
    </QrCode.Root>
  );
}
```

## Source

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

```tsx
import * as stylex from "@stylexjs/stylex";
import { QrCode as ArkQrCode } from "@ark-ui/react/qr-code";
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

/**
 * QrCode — the real Ark UI QrCode machine wearing the recipe styles: the
 * machine encodes `defaultValue`/`value` into a scannable matrix
 * (`<QrCode.Frame><QrCode.Pattern /></QrCode.Frame>`) and positions the
 * logo `Overlay` itself. Only the root consumes the size axis
 * (`--qr-code-size`), so `size` is a plain prop on Root.
 */
function mergeClassName(base: string | undefined, extra: unknown) {
  return typeof extra === "string" && extra.length > 0
    ? [base, extra].filter(Boolean).join(" ")
    : base;
}

// 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<React.ComponentProps<typeof ArkQrCode.Root>, "style"> &
  StyleOverrideProps & {
    size?: QrCodeSize;
  };

function Root(allProps: QrCodeRootProps) {
  const { size = "md", palette, style, className, ...rest } =
    allProps as QrCodeRootProps & Record<string, unknown>;
  const p = sx([qrCodeRoot.base, qrCodeRootSizes[size]], palette, style as never);
  return (
    <ArkQrCode.Root
      data-size={size}
      {...rest}
      className={mergeClassName(p.className, className)}
      style={p.style}
    />
  );
}
Root.displayName = "QrCodeRoot";

/** Wraps a machine part with its slot's recipe styles. */
function withPart<P extends { className?: string; style?: React.CSSProperties }>(
  Part: React.ComponentType<P>,
  styles: ReadonlyArray<unknown>,
  displayName: string,
) {
  function StyledPart(allProps: Omit<P, "style"> & StyleOverrideProps) {
    const { palette, style, className, ...rest } = allProps as P &
      StyleOverrideProps &
      Record<string, unknown>;
    const p = sx(styles, palette, style as never);
    return (
      <Part
        {...(rest as unknown as P)}
        className={mergeClassName(p.className, className)}
        style={p.style}
      />
    );
  }
  StyledPart.displayName = displayName;
  return StyledPart;
}

export const QrCode = {
  Root,
  Frame: withPart(ArkQrCode.Frame, [qrCodeFrame.base], "QrCodeFrame"),
  Pattern: ArkQrCode.Pattern,
  Overlay: withPart(ArkQrCode.Overlay, [qrCodeOverlay.base], "QrCodeOverlay"),
};
```
