JGuang

Masonry

Masonry · Ant Design

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

Masonry

Arrange items in a masonry layout.

A masonry layout component for displaying content with different heights.

When To Use

  • When displaying images or cards with irregular heights
  • When content needs to be evenly distributed in columns
  • When column count needs to be responsive

Examples

  • Basic · basic
  • Responsive · responsive
  • Image · image
  • Dynamic · dynamic
  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Masonry

PropertyDescriptionTypeDefaultVersionGlobal Config
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
columnsNumber of columns, can be a fixed value or a responsive configurationnumber | { xs?: number; sm?: number; md?: number }3×
freshWhether to continuously monitor the size changes of child itemsbooleanfalse×
gutterSpacing, can be a fixed value, responsive configuration, or a configuration for horizontal and vertical spacingGap | [Gap, Gap]0×
itemsMasonry itemsMasonryItem[]-×
itemRenderCustom item rendering function(item: MasonryItem) => React.ReactNode-×
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
onLayoutChangeCallback for column sorting changes({ key: React.Key; column: number }[]) => void-×

MasonryItem

PropertyDescriptionTypeDefault Value
childrenCustom display content, takes precedence over itemRenderReact.ReactNode-
columnSpecifies the column to which the item belongsnumber-
dataCustom data storageT-
heightHeight of the itemnumber-
keyUnique identifier for the itemstring | number-

Gap

Gap represents the spacing between items. It can either be a fixed value or a responsive configuration.

type Gap = undefined | number | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl', number>>;

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element, sets relative positioning, flex layout and masonry container styles—
itemItem element, sets absolute positioning, width calculation, transition animation and masonry item styles—

Semantic description source: vendor/components/masonry/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/masonry/style/index.ts

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

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

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

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

export interface MasonryToken extends FullToken<'Masonry'> {}

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/masonry/Masonry.tsx
  • vendor/components/masonry/MasonryItem.tsx
  • vendor/components/masonry/hooks/usePositions.ts
  • vendor/components/masonry/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.