logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
YouMindTRACTIANLobeHubCodeRabbit
6.4.5
  • Components Overview
  • Changelog
    v6.4.5
  • General
    • Button
    • FloatButton
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
      DEPRECATED
    • Popover
    • QRCode
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • App
    • BorderBeam
      6.4.0
    • ConfigProvider
    • Util
When To Use
Examples
Basic Usage
Progressive Loading
Fault tolerant
Multiple image preview
Preview from one image
Custom preview image
Controlled Preview
Custom toolbar render
Custom preview render
preview mask
Custom semantic dom styling
nested
API
Image
PlaceholderType
ImageProgressConfig
PreviewType
PreviewGroup
PreviewGroupType
Interface
TransformType
TransformAction
ToolbarRenderInfoType
ImgInfo
CoverConfig
Semantic DOM
Design Token

Image

Preview-able image.
Importimport { Image } from 'antd';
GitHub
components/imageIssueOpen issues
Docs
Edit this pageLLMs.md
EmptyList

Resources

Ant Design X
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
X
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
For Agents
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
WeaveFox logoWeaveFox-AI Development with WeaveFox 🦊
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

  • When you need to display pictures.
  • Display when loading a large image or fault tolerant handling when loading fail.

Examples

API

Common props ref:Common props

Image

PropertyDescriptionTypeDefaultVersionGlobal Config
altImage descriptionstring-×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
fallbackFallback URL when load failsstring-5.28.0
heightImage heightstring | number-×
placeholderLoading placeholder, supports ReactNode or config objectPlaceholderType-×
previewPreview configuration; set to false to disableboolean | PreviewTypetruepreview.closeIcon: 5.14.0, preview.mask: 6.0.0, preview.mask.closable: 6.4.0
srcImage URLstring-×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
widthImage widthstring | number-×
onErrorCallback when loading error occurs(event: Event) => void-×

Other Property ref <img>

PlaceholderType

PropertyDescriptionTypeDefaultVersion
progressProgress config, set to true to show gradient animation, set { percent: number } to show progress, render for custom renderingboolean | ImageProgressConfig-

ImageProgressConfig

PropertyDescriptionTypeDefaultVersion
percentProgress valuenumber-
renderCustom rendering, receives default progress UI and percentage(progress: React.ReactNode, percent: number) => React.ReactNode-

PreviewType

PropertyDescriptionTypeDefaultVersion
actionsRenderCustom toolbar render(originalNode: React.ReactElement, info: ToolbarRenderInfoType) => React.ReactNode-
closeIconCustom close iconReact.ReactNode-
coverCustom preview maskReact.ReactNode | CoverConfig-CoverConfig support after v6.0
focusTrapWhether to trap focus within the preview when openbooleantrue6.4.0
destroyOnCloseDestroy child elements on preview close (removed, no longer supported)booleanfalse
forceRenderForce render preview image (removed, no longer supported)boolean-
getContainerSpecify container for preview mounting; still full screen; false mounts at current locationstring | HTMLElement | (() => HTMLElement) | false-
imageRenderCustom preview content(originalNode: React.ReactElement, info: { transform: TransformType, image: ImgInfo }) => React.ReactNode-
maskpreview mask effectboolean | { enabled?: boolean, blur?: boolean, closable?: boolean }truemask.closable: 6.4.0
maskClassNameThumbnail mask class name; please use 'classNames.cover' insteadstring-
maxScaleMaximum zoom scalenumber50
minScaleMinimum zoom scalenumber1
movableWhether the preview image can be dragged when it is larger than the viewportbooleantrue
openWhether to display previewboolean-
rootClassNameRoot DOM class name for preview; applies to both image and preview wrapperstring-
scaleStepEach step's zoom multiplier is 1 + scaleStepnumber0.5
srcCustom preview srcstring-
stylesCustom semantic structure stylesRecord<SemanticDOM, CSSProperties>-
toolbarRenderCustom toolbar; please use 'actionsRender' instead(originalNode: React.ReactElement, info: Omit<ToolbarRenderInfoType, 'current' | 'total'>) => React.ReactNode-
visibleWhether to show; please use 'open' insteadboolean-
onOpenChangeCallback when preview open state changes(visible: boolean) => void-
onTransformCallback for preview transform changes{ transform: TransformType, action: TransformAction }-
onVisibleChangeCallback when 'visible' changes; please use 'onOpenChange' instead(visible: boolean, prevVisible: boolean) => void-

PreviewGroup

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
fallbackFallback URL for load errorstring-
itemsArray of preview itemsstring[] | { src: string, crossOrigin: string, ... }[]-
previewPreview configuration; disable by setting to falseboolean | PreviewGroupTypetrue

PreviewGroupType

PropertyDescriptionTypeDefaultVersion
actionsRenderCustom toolbar render(originalNode: React.ReactElement, info: ToolbarRenderInfoType) => React.ReactNode-
closeIconCustom close iconReact.ReactNode-
countRenderCustom preview count render(current: number, total: number) => React.ReactNode-
focusTrapWhether to trap focus within the preview when openbooleantrue6.4.0
currentIndex of the current preview imagenumber-
forceRenderForce render preview image (removed, no longer supported)boolean-
getContainerSpecify container for preview mounting; still full screen; false mounts at current locationstring | HTMLElement | (() => HTMLElement) | false-
imageRenderCustom preview content(originalNode: React.ReactElement, info: { transform: TransformType, image: ImgInfo, current: number }) => React.ReactNode-
maskpreview mask effectboolean | { enabled?: boolean, blur?: boolean, closable?: boolean }truemask.closable: 6.4.0
maskClassNameThumbnail mask class name; please use 'classNames.cover' insteadstring-
minScaleMinimum zoom scalenumber1
maxScaleMaximum zoom scalenumber50
movableWhether the preview image can be dragged when it is larger than the viewportbooleantrue
openWhether to display previewboolean-
rootClassNameRoot DOM class name for preview; applies to both image and preview wrapper. Use 'classNames.root' insteadstring-
stylesCustom semantic structure stylesRecord<SemanticDOM, CSSProperties>-
scaleStepEach step's zoom multiplier is 1 + scaleStepnumber0.5
toolbarRenderCustom toolbar; please use 'actionsRender' instead(originalNode: React.ReactElement, info: ToolbarRenderInfoType) => React.ReactNode-
visibleWhether to show; please use 'open' insteadboolean-
onOpenChangeCallback when preview open state changes, includes current preview index(visible: boolean, info: { current: number }) => void-
onChangeCallback when changing preview image(current: number, prevCurrent: number) => void-
onTransformCallback for preview transform changes{ transform: TransformType, action: TransformAction }-
onVisibleChangeCallback when 'visible' changes; please use 'onOpenChange' instead(visible: boolean, prevVisible: boolean, current: number) => void-

Interface

TransformType

typescript
{
x: number;
y: number;
rotate: number;
scale: number;
flipX: boolean;
flipY: boolean;
}

TransformAction

typescript
type TransformAction =
| 'flipY'
| 'flipX'
| 'rotateLeft'
| 'rotateRight'
| 'zoomIn'
| 'zoomOut'
| 'close'
| 'prev'
| 'next'
| 'wheel'
| 'doubleClick'
| 'move'
| 'dragRebound';

ToolbarRenderInfoType

typescript
{
icons: {
flipYIcon: React.ReactNode;
flipXIcon: React.ReactNode;
rotateLeftIcon: React.ReactNode;
rotateRightIcon: React.ReactNode;
zoomOutIcon: React.ReactNode;
zoomInIcon: React.ReactNode;
};
actions: {
onActive?: (index: number) => void; // support after 5.21.0
onFlipY: () => void;
onFlipX: () => void;
onRotateLeft: () => void;
onRotateRight: () => void;
onZoomOut: () => void;
onZoomIn: () => void;
onReset: () => void; // support after 5.17.3
onClose: () => void;
};
transform: TransformType,
current: number;
image: ImgInfo
}

ImgInfo

typescript
{
url: string;
alt: string;
width: string | number;
height: string | number;
}

CoverConfig

typescript
type CoverConfig = {
coverNode?: React.ReactNode; // The custom node of preview mask
placement?: 'top' | 'bottom' | 'center'; // Set the position of the preview mask display.
};

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
previewOperationColorColor of preview operation iconstringrgba(255,255,255,0.65)
previewOperationColorDisabledDisabled color of preview operation iconstringrgba(255,255,255,0.25)
previewOperationHoverColorColor of hovered preview operation iconstringrgba(255,255,255,0.85)
previewOperationSizeSize of preview operation iconnumber18
progressAnimationDurationBase duration of loading animationstring3s
zIndexPopupz-index of preview popupnumber1080
Global TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgBaseUsed to derive the base variable of the background color gradient. In v5, we added a layer of background color derivation algorithm to produce map token of background color. But PLEASE DO NOT USE this Seed Token directly in the code!string#fff
colorBgContainerDisabledControl the background color of container in disabled state.stringrgba(0,0,0,0.04)
colorBgMaskThe background color of the mask, used to cover the content below the mask, Modal, Drawer, Image and other components use this tokenstringrgba(0,0,0,0.45)
colorPrimaryBorderThe stroke color under the main color gradient, used on the stroke of components such as Slider.string#91caff
colorTextLightSolidControl the highlight color of text with background color, such as the text in Primary Button components.string#fff
colorTextSecondaryThe second level of text color is generally used in scenarios where text color is not emphasized, such as label text, menu text selection state, etc.stringrgba(0,0,0,0.65)
borderRadiusXSXS size border radius, used in some small border radius components, such as Segmented, Arrow and other components with small border radius.number2
controlHeightLGLG component heightnumber40
fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
lineWidthFocusControl the width of the line when the component is in focus state.number3
marginControl the margin of an element, with a medium size.number16
marginSMControl the margin of an element, with a medium-small size.number12
marginXLControl the margin of an element, with an extra-large size.number32
marginXSControl the margin of an element, with a small size.number8
motionDurationMidMotion speed, medium speed. Used for medium element animation interaction.string0.2s
motionDurationSlowMotion speed, slow speed. Used for large element animation interaction.string0.3s
motionEaseInOutPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.645, 0.045, 0.355, 1)External Link Icon
motionEaseOutPreset motion curve.string
Cubic Bezier Visualizer
cubic-bezier(0.215, 0.61, 0.355, 1)External Link Icon
paddingLGControl the large padding of the element.number24
paddingSMControl the small padding of the element.number12
Basic Usage

Click the image to zoom in.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Progressive Loading

Set placeholder via placeholder prop. When placeholder is { progress: true }, it shows a watercolor ink loading animation; when set to { progress: { percent: number } }, it shows a progress bar; you can also pass a custom React node as placeholder.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Fault tolerant

Load failed to display image placeholder.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Multiple image preview

Click the left and right switch buttons to preview multiple images.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Preview from one image

Preview a collection from one image.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom preview image

You can set different preview image.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Controlled Preview

You can make preview controlled.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom toolbar render

You can customize the toolbar and add a button for downloading the original image or downloading the flipped and rotated image.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom preview render

You can customize the preview content.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
preview mask

mask effect.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom semantic dom styling

You can customize the semantic dom style of Image by passing objects/functions through classNames and styles.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
6.0.0
nested

Nested in the modal

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
basic
Loading
Loading
loading...
50%
Generating 75%
basic image
Generating 0%
basic image
svg image
svg image
webp image
basic image
scaleStep:

basic image
image-0
image-1
basic image
blur preview
blur
Dimmed mask preview
Dimmed mask
No mask preview
No mask
示例图片
示例图片
  • root
    Root element, sets relative positioning and inline-block layout styles
  • image
    Image element, sets width, height and vertical alignment styles
  • cover
    Image hover display prompt element, sets absolute positioning, background color, opacity and transition animation styles
  • popup.root
    Preview root element, sets fixed positioning, z-index and background mask styles
  • popup.mask
    Preview mask element, sets absolute positioning and semi-transparent background styles
  • popup.body
    Preview body element, sets flex layout, center alignment and pointer event styles
  • popup.footer
    Preview footer element, sets absolute positioning, center layout and bottom operation area styles
  • popup.actions
    Preview actions group element, sets flex layout, background color, border radius and action button styles
  • popup.close
    6.4.0
    Preview close button element, sets basic button styles