Watermark
Tile repeated text or image watermarks over a region or an entire page to identify internal material and discourage unauthorized screenshot sharing.
Import
import { HuiWatermark } from '@nscode/handy-ui'
Basic usage
Place the content to watermark in the default slot and set the watermark text with content. The watermark layer sits above the content without blocking clicks or text selection.
<script setup lang="ts">
import { HuiWatermark } from '@nscode/handy-ui'
</script>
<template>
<HuiWatermark content="HandyUI">
<div style="height: 300px">This region has a watermark</div>
</HuiWatermark>
</template>
Overflow and margins
The watermark container follows normal block layout for margins. It does not clip overflow or create a scrolling container. Set overflow explicitly on your application container when clipping or scrolling is needed.
<script setup lang="ts">
import { HuiButton, HuiWatermark } from '@nscode/handy-ui'
</script>
<template>
<HuiWatermark
content="Layout check"
style="height: 180px; border: 1px solid var(--hui-border-color)"
>
<div style="margin: 24px; height: 210px">
<p>
Content retains its 24px margin. The bottom button remains visible and clickable outside the
watermark region.
</p>
<HuiButton style="margin-top: 120px">Button in overflow area</HuiButton>
</div>
</HuiWatermark>
<div style="height: 100px" />
</template>
Multiline text
When content is an array, each element is a centered line. If the text is taller than height, the watermark tile expands to fit it instead of clipping the lower lines.
<template>
<HuiWatermark :content="['HandyUI', 'Vue 3 component library']">
<div style="height: 300px">Multiline watermark example</div>
</HuiWatermark>
</template>
A common pattern combines the viewer and date to help identify the source of a shared screenshot:
<template>
<HuiWatermark
:content="['Zhang San, employee ID 1024', '2026-11-18 Internal material']"
:gap="[60, 60]"
>
<div style="height: 240px; padding: 16px">
<HuiParagraph>This internal report is watermarked with the viewer and date.</HuiParagraph>
<HuiButton type="primary">The watermark does not block clicks</HuiButton>
</div>
</HuiWatermark>
</template>
Image watermarks
image sets the image URL; width and height set its drawing size. If content is also provided, it becomes the text fallback when the image fails to load.
<template>
<HuiWatermark image="/logo.png" :width="48" :height="48" :alpha="0.3">
<div style="height: 300px">Image watermark example</div>
</HuiWatermark>
</template>
If an image URL is invalid or fails to load, content is used as a text watermark. Without content, no watermark is shown:
<template>
<HuiWatermark image="/images/broken.png" content="Image unavailable: text fallback">
<div style="height: 200px">Image loading failure example</div>
</HuiWatermark>
</template>
Custom fonts
font configures color, size, weight, family, and style. Omitted fields use their defaults. fontWeight accepts valid CSS font-weight values: 'normal', 'bold', 'lighter', 'bolder', or a number such as 300 or 600.
<template>
<HuiWatermark
content="Confidential"
:font="{ color: 'rgba(255, 77, 79, 0.3)', fontSize: 20, fontWeight: 'bold' }"
:gap="[80, 80]"
:rotate="-30"
>
<div style="height: 300px">Red watermark style</div>
</HuiWatermark>
</template>
The examples below compare individual font fields. Watermarks are drawn on canvas, so color must be a concrete color value rather than a CSS variable such as var(--hui-...):
<script setup lang="ts">
import { HuiWatermark } from '@nscode/handy-ui'
import type { WatermarkFontConfig } from '@nscode/handy-ui'
const items: { label: string; font: WatermarkFontConfig }[] = [
{ label: 'Default', font: {} },
{ label: 'fontSize: 20', font: { fontSize: 20 } },
{ label: "fontWeight: 'bold'", font: { fontWeight: 'bold' } },
{ label: "fontWeight: 'lighter'", font: { fontWeight: 'lighter' } },
{ label: "fontStyle: 'italic'", font: { fontStyle: 'italic' } },
{ label: "fontStyle: 'oblique'", font: { fontStyle: 'oblique' } },
{ label: "fontFamily: 'serif'", font: { fontFamily: 'serif' } },
{ label: "fontFamily: 'monospace'", font: { fontFamily: 'monospace' } },
{ label: "color: 'rgba(24, 144, 255, 0.3)'", font: { color: 'rgba(24, 144, 255, 0.3)' } }
]
</script>
<template>
<div class="grid">
<div v-for="item in items" :key="item.label">
<p class="label">{{ item.label }}</p>
<HuiWatermark content="HandyUI watermark" :font="item.font" :gap="[40, 40]">
<div class="box" />
</HuiWatermark>
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: var(--hui-spacing-4);
}
.label {
margin: 0 0 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.box {
height: 140px;
border: 1px solid var(--hui-border-color-light);
}
</style>
Rotation, spacing, and offsets
rotate sets the angle. gap sets horizontal and vertical spacing between adjacent watermarks, and offset shifts the entire pattern. Tile size is calculated from the text width and its rotated bounds, keeping long and rotated text fully visible.
<template>
<HuiWatermark content="rotate -45" :rotate="-45" :gap="[120, 120]" :offset="[0, 0]">
<div style="height: 300px" />
</HuiWatermark>
</template>
Compare rotation angles below. The default is -22; negative values rotate counterclockwise and positive values rotate clockwise:
<template>
<div class="grid">
<div v-for="angle in [0, -22, -45, 30, 90]" :key="angle">
<p class="label">rotate {{ angle }}{{ angle === -22 ? ' (default)' : '' }}</p>
<HuiWatermark content="HandyUI" :rotate="angle" :gap="[40, 40]">
<div class="box" />
</HuiWatermark>
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
gap: var(--hui-spacing-4);
}
.label {
margin: 0 0 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.box {
height: 140px;
border: 1px solid var(--hui-border-color-light);
}
</style>
Compare spacing and offsets. gap defaults to [100, 100], and offset defaults to [50, 50]:
<template>
<div class="grid">
<div>
<p class="label">gap [20, 20]</p>
<HuiWatermark content="HandyUI" :gap="[20, 20]"><div class="box" /></HuiWatermark>
</div>
<div>
<p class="label">gap [100, 100] (default)</p>
<HuiWatermark content="HandyUI"><div class="box" /></HuiWatermark>
</div>
<div>
<p class="label">gap [160, 40]</p>
<HuiWatermark content="HandyUI" :gap="[160, 40]"><div class="box" /></HuiWatermark>
</div>
<div>
<p class="label">offset [0, 0]</p>
<HuiWatermark content="HandyUI" :offset="[0, 0]"><div class="box" /></HuiWatermark>
</div>
<div>
<p class="label">offset [50, 50] (default)</p>
<HuiWatermark content="HandyUI"><div class="box" /></HuiWatermark>
</div>
<div>
<p class="label">offset [120, 10]</p>
<HuiWatermark content="HandyUI" :offset="[120, 10]"><div class="box" /></HuiWatermark>
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: var(--hui-spacing-4);
}
.label {
margin: 0 0 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.box {
height: 160px;
border: 1px solid var(--hui-border-color-light);
}
</style>
Opacity
alpha sets the opacity of the entire watermark from 0 to 1, defaulting to 1. It multiplies the color's own opacity: the default color is already 15% opaque, so reducing alpha makes it lighter still. These examples use opaque blue to make the difference clearer:
<template>
<div class="grid">
<div v-for="alpha in [1, 0.6, 0.3, 0.1]" :key="alpha">
<p class="label">alpha {{ alpha }}{{ alpha === 1 ? ' (default)' : '' }}</p>
<HuiWatermark
content="HandyUI"
:alpha="alpha"
:font="{ color: 'rgb(24, 144, 255)', fontSize: 16 }"
:gap="[40, 40]"
>
<div class="box" />
</HuiWatermark>
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
gap: var(--hui-spacing-4);
}
.label {
margin: 0 0 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.box {
height: 140px;
border: 1px solid var(--hui-border-color-light);
}
</style>
Adjusting parameters
Move the sliders or edit the text to regenerate the watermark immediately:
<script setup lang="ts">
import { computed, ref } from 'vue'
import { HuiInput, HuiSlider, HuiWatermark } from '@nscode/handy-ui'
const content = ref('HandyUI watermark')
const fontSize = ref(16)
const rotate = ref(-22)
const gapX = ref(100)
const gapY = ref(100)
const offsetX = ref(50)
const offsetY = ref(50)
const alpha = ref(1)
const font = computed(() => ({ fontSize: fontSize.value }))
const gap = computed<[number, number]>(() => [gapX.value, gapY.value])
const offset = computed<[number, number]>(() => [offsetX.value, offsetY.value])
</script>
<template>
<div class="controls">
<span>content</span>
<HuiInput v-model="content" placeholder="Watermark text" />
<span>fontSize {{ fontSize }}</span>
<HuiSlider v-model="fontSize" :min="12" :max="40" />
<span>rotate {{ rotate }}</span>
<HuiSlider v-model="rotate" :min="-90" :max="90" />
<span>gap {{ gapX }} / {{ gapY }}</span>
<div class="pair">
<HuiSlider v-model="gapX" :min="0" :max="200" />
<HuiSlider v-model="gapY" :min="0" :max="200" />
</div>
<span>offset {{ offsetX }} / {{ offsetY }}</span>
<div class="pair">
<HuiSlider v-model="offsetX" :min="0" :max="200" />
<HuiSlider v-model="offsetY" :min="0" :max="200" />
</div>
<span>alpha {{ alpha.toFixed(1) }}</span>
<HuiSlider v-model="alpha" :min="0" :max="1" :step="0.1" />
</div>
<HuiWatermark
:content="content"
:font="font"
:rotate="rotate"
:gap="gap"
:offset="offset"
:alpha="alpha"
>
<div class="box" />
</HuiWatermark>
</template>
<style scoped>
.controls {
display: grid;
grid-template-columns: 136px 1fr;
gap: var(--hui-spacing-2) var(--hui-spacing-4);
align-items: center;
max-width: 560px;
margin-bottom: var(--hui-spacing-4);
font-size: var(--hui-font-size-sm);
}
.pair {
display: grid;
grid-template-columns: 1fr 1fr;
gap: var(--hui-spacing-4);
}
.box {
height: 300px;
border: 1px solid var(--hui-border-color-light);
}
</style>
Stacking order
z-index sets the watermark layer's stacking order, defaulting to 9. Positioned content with a higher stacking order can cover it; increase z-index to bring the watermark above that content:
<template>
<div class="grid">
<div>
<p class="label">Default 9: covered by the card with z-index 10</p>
<HuiWatermark content="HandyUI" :gap="[40, 40]">
<div class="box"><div class="raised">z-index: 10</div></div>
</HuiWatermark>
</div>
<div>
<p class="label">z-index 11: watermark above the card</p>
<HuiWatermark content="HandyUI" :gap="[40, 40]" :z-index="11">
<div class="box"><div class="raised">z-index: 10</div></div>
</HuiWatermark>
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: var(--hui-spacing-4);
}
.label {
margin: 0 0 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
.box {
display: flex;
align-items: center;
justify-content: center;
height: 180px;
border: 1px solid var(--hui-border-color-light);
}
.raised {
position: relative;
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
width: 60%;
height: 60%;
border-radius: var(--hui-border-radius);
background: var(--hui-color-primary-bg);
}
</style>
Theme-aware default colors
When font.color is omitted, the component uses the container's text color to detect light or dark surroundings: rgba(0, 0, 0, 0.15) in light themes and rgba(255, 255, 255, 0.15) in dark themes. It regenerates when the <html> element's data-theme or class changes, or when the system switches color schemes.
Because detection uses the container's text color, a dark region with white text automatically receives a light watermark:
<template>
<div class="grid">
<HuiWatermark content="HandyUI" :gap="[40, 40]">
<div class="box">Text color follows the theme</div>
</HuiWatermark>
<div class="dark">
<HuiWatermark content="HandyUI" :gap="[40, 40]">
<div class="box">Dark region, white text, light watermark</div>
</HuiWatermark>
</div>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: var(--hui-spacing-4);
}
.box {
height: 160px;
padding: var(--hui-spacing-3);
box-sizing: border-box;
border: 1px solid var(--hui-border-color-light);
}
.dark {
color: var(--hui-color-white);
background: #1f2937;
}
</style>
Fullscreen watermark
When fullscreen is true, the watermark uses position: fixed and covers the viewport.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiWatermark } from '@nscode/handy-ui'
const show = ref(false)
</script>
<template>
<HuiButton @click="show = !show">{{ show ? 'Hide' : 'Show' }} fullscreen watermark</HuiButton>
<HuiWatermark v-if="show" content="HandyUI" fullscreen />
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| content | string | string[] | undefined | Watermark text; an array creates multiple lines. An empty string or array displays no watermark |
| image | string | undefined | Image URL; takes precedence over text and falls back to text if loading fails |
| width | number | 120 | Minimum content width (px); expands for wider text, and sets image drawing width |
| height | number | 64 | Minimum content height (px); expands for taller multiline text, and sets image drawing height |
| rotate | number | -22 | Rotation angle in degrees |
| zIndex | number | 9 | Watermark layer z-index |
| gap | [number, number] | [100, 100] | Spacing between watermarks [horizontal, vertical] (px) |
| offset | [number, number] | [50, 50] | Pattern offset [horizontal, vertical] (px), equivalent to background-position |
| font | WatermarkFontConfig | See table below | Font configuration |
| alpha | number | 1 | Opacity from 0 to 1 |
| fullscreen | boolean | false | Cover the viewport with position: fixed |
WatermarkFontConfig
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | Theme-dependent | Text color; defaults to rgba(0, 0, 0, 0.15) in light surroundings and rgba(255, 255, 255, 0.15) in dark surroundings |
| fontSize | number | 14 | Font size (px) |
| fontWeight | 'normal' | 'bold' | 'lighter' | 'bolder' | number | 'normal' | Font weight |
| fontFamily | string | 'sans-serif' | Font family |
| fontStyle | 'normal' | 'italic' | 'oblique' | 'normal' | Font style |
Slots
| Slot | Scope | Description |
|---|---|---|
| default | Content to watermark |
Types
Public types use a component prefix. Compatibility mapping: FontConfig → WatermarkFontConfig. The old name remains importable from @nscode/handy-ui, is marked @deprecated, and will be removed in 1.0.
import type { WatermarkFontConfig, WatermarkProps } from '@nscode/handy-ui'
interface WatermarkFontConfig {
color?: string
fontSize?: number
fontWeight?: 'normal' | 'bold' | 'lighter' | 'bolder' | number
fontFamily?: string
fontStyle?: 'normal' | 'italic' | 'oblique'
}
interface WatermarkProps {
content?: string | string[]
image?: string
width?: number
height?: number
rotate?: number
zIndex?: number
gap?: [number, number]
offset?: [number, number]
font?: WatermarkFontConfig
alpha?: number
fullscreen?: boolean
}