JGuang

Watermark

Watermark · Ant Design

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

Watermark

Add specific text or patterns to the page.

When To Use

  • Use when the page needs to be watermarked to identify the copyright.
  • Suitable for preventing information theft.

Examples

  • Basic · basic
  • Multi-line watermark · multi-line
  • Image watermark · image
  • Custom configuration · custom
  • Modal or Drawer · portal

API

Common props ref:Common props

This component is available since antd@5.1.0.

Watermark

PropertyDescriptionTypeDefaultVersionGlobal Config
widthThe width of the watermark, the default value of content is its own widthnumber120×
heightThe height of the watermark, the default value of content is its own heightnumber64×
inheritPass the watermark to the pop-up component such as Modal, Drawerbooleantrue5.11.0×
rotateWhen the watermark is drawn, the rotation Angle, unit °number-22×
zIndexThe z-index of the appended watermark elementnumber999×
imageImage source, it is recommended to export 2x or 3x image, high priority (support base64 format)string-×
contentWatermark text contentstring | WatermarkText | (string | WatermarkText)[]-WatermarkText: 6.5.0×
fontText styleFontFont×
gapThe spacing between watermarks[number, number][100, 100]×
offsetThe offset of the watermark from the upper left corner of the container. The default is gap/2[number, number][gap[0]/2, gap[1]/2]×
onRemoveCallback when the watermark is removed by DOM mutation() => void-6.0.0×

WatermarkText

PropertyDescriptionTypeDefaultVersion
fontCustom line text styleFont-6.5.0
textLine textstring-6.5.0

Font

PropertyDescriptionTypeDefaultVersion
colorfont colorCanvasFillStrokeStyles.fillStylergba(0,0,0,.15)
fontSizefont sizenumber16
fontWeightfont weightnormal | lighter | bold | bolder | numbernormal
fontFamilyfont familystringsans-serif
fontStylefont stylenone | normal | italic | obliquenormal
textAlignspecify the text alignment directionCanvasTextAligncenter5.10.0

Design Token

The pinned source has no separate ComponentToken declaration for this component. Styling follows native global tokens or the composed component's tokens; additional fields and defaults are not inferred.

FAQ

Handle abnormal image watermarks

When using an image watermark and the image loads abnormally, you can add content at the same time to prevent the watermark from becoming invalid (since 5.2.3).

<Watermark
  height={30}
  width={130}
  content="Ant Design"
  image="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*lkAoRbywo0oAAAAAAAAAAAAADrJ8AQ/original"
>
  <div style={{ height: 500 }} />
</Watermark>

Why overflow: hidden style is added since version 5.18.0?

User can hide the watermark by setting the container height to 0 through the developer tool in the previous version. To avoid this situation, we added the overflow: hidden style to the container. When the container height changes, the content is also hidden. You can override the style to modify this behavior:

<Watermark style={{ overflow: 'visible' }} />

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/watermark/context.ts
  • vendor/components/watermark/index.tsx
  • vendor/components/watermark/useSingletonCache.ts
  • vendor/components/watermark/useWatermark.ts
  • vendor/components/watermark/utils.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.