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
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| value | scanned text | string | string[] | - | string[]: 5.28.0 | × |
| type | render type | canvas | svg | canvas | 5.6.0 | × |
| icon | include image url (only image link are supported) | string | - | - | × |
| size | QRCode size | number | 160 | - | × |
| iconSize | include image size | number | { width: number; height: number } | 40 | 5.19.0 | × |
| color | QRCode Color | string | #000 | - | × |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 6.0.0 | 6.0.0 |
| bgColor | QRCode Background Color | string | transparent | 5.5.0 | × |
| marginSize | Quiet zone size (in modules). 0 means no margin | number | 0 | 6.2.0 | × |
| bordered | Whether has border style | boolean | true | - | × |
| errorLevel | Error Code Level | 'L' | 'M' | 'Q' | 'H' | M | - | × |
| boostLevel | If enabled, the Error Correction Level of the result may be higher than the specified Error Correction Level | boolean | true | 5.28.0 | × |
| status | QRCode status | active | expired | loading | scanned | active | scanned: 5.13.0 | × |
| statusRender | custom status render | (info: StatusRenderInfo) => React.ReactNode | - | 5.20.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 6.0.0 | 6.0.0 |
StatusRenderInfo
type StatusRenderInfo = {
status: QRStatus;
locale: Locale['QRCode'];
onRefresh?: () => void;
};
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element, set flex layout, padding, background color, border, border radius and relative positioning styles | — |
cover | Cover 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.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
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.tsxvendor/components/qr-code/index.tsxvendor/components/qr-code/interface.tsvendor/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.