JGuang

QRCode

QRCode · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

QRCode

Components that can convert text into QR codes, and support custom color and logo.

When To Use

Used when the text needs to be converted into a QR Code.

Examples

  • base · base
  • With Icon · icon
  • other status · status
  • custom status render · customStatusRender
  • Custom Render Type · type
  • Custom Size · customSize
  • Custom Color · customColor
  • Download QRCode · download
  • Error Level · errorlevel
  • Advanced Usage · Popover
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

This component is available since antd@5.1.0

PropertyDescriptionTypeDefaultVersionGlobal Config
valuescanned textstring | string[]-string[]: 5.28.0×
typerender typecanvas | svgcanvas5.6.0×
iconinclude image url (only image link are supported)string--×
sizeQRCode sizenumber160-×
iconSizeinclude image sizenumber | { width: number; height: number }405.19.0×
colorQRCode Colorstring#000-×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.06.0.0
bgColorQRCode Background Colorstringtransparent5.5.0×
marginSizeQuiet zone size (in modules). 0 means no marginnumber06.2.0×
borderedWhether has border stylebooleantrue-×
errorLevelError Code Level'L' | 'M' | 'Q' | 'H'M-×
boostLevelIf enabled, the Error Correction Level of the result may be higher than the specified Error Correction Levelbooleantrue5.28.0×
statusQRCode statusactive | expired | loading | scannedactivescanned: 5.13.0×
statusRendercustom status render(info: StatusRenderInfo) => React.ReactNode-5.20.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.06.0.0

StatusRenderInfo

type StatusRenderInfo = {
  status: QRStatus;
  locale: Locale['QRCode'];
  onRefresh?: () => void;
};

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element, set flex layout, padding, background color, border, border radius and relative positioning styles—
coverCover element, set absolute positioning, z-index, background color and loading state overlay styles—

Semantic description source: vendor/components/qr-code/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

Native ComponentToken declares no directly extractable own fields. Shared tokens and inheritance are defined by the declarations below.

Declaration source: vendor/components/qr-code/style/index.ts

import type { CSSObject } from '@ant-design/cssinjs';

import { unit } from '@ant-design/cssinjs';

import { FastColor } from '@ant-design/fast-color';

import { resetComponent } from '../../style';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

// biome-ignore lint/suspicious/noEmptyInterface: ComponentToken need to be empty by default
export interface ComponentToken {}

/**
 * @desc QRCode 组件的 Token
 * @descEN Token for QRCode component
 */
interface QRCodeToken extends FullToken<'QRCode'> {
  /**
   * @desc QRCode 文字颜色
   * @descEN Text color of QRCode
   */
  QRCodeTextColor: string;
  /**
   * @desc QRCode 遮罩背景颜色
   * @descEN Cover background color of QRCode
   */
  QRCodeCoverBackgroundColor: string;
}

FAQ

About QRCode ErrorLevel

The ErrorLevel means that the QR code can be scanned normally after being blocked, and the maximum area that can be blocked is the error correction rate.

Generally, the QR code is divided into 4 error correction levels: Level L can correct about 7% errors, Level M can correct about 15% errors, Level Q can correct about 25% errors, and Level H can correct about 30% errors. When the content encoding of the QR code carries less information, in other words, when the value link is short, set different error correction levels, and the generated image will not change.

For more information, see the: https://www.qrcode.com/en/about/error_correction

⚠️⚠️⚠️ Cannot scan the QR code?

If the QR code cannot be scanned for identification, it may be because the link address is too long, which leads to too dense pixels.

You can configure the QR code to be larger through size, or shorten the link through short link services.

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/qr-code/QrcodeStatus.tsx
  • vendor/components/qr-code/index.tsx
  • vendor/components/qr-code/interface.ts
  • vendor/components/qr-code/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.