BorderBeam
Decorative ray along the border: container, hover, multiple rays, gradients, speed, size and thickness.
When to use
BorderBeam adds a moving decorative beam along the border of a card or other container. It helps highlight an area without creating business status. Keep the usual focus ring, error border, and text explanation regardless of decoration.
Real DOM container and target
In Svelte the target is passed explicitly: bind:this of a regular element or bind:nativeElement of a component, for example Card. The DOM-ref is not automatically extracted from children. children is output without any additional wrapper.
| Problem | Opportunity | Example |
|---|---|---|
| Highlight card | Card.nativeElement, target |
Beam around the card |
| Show effect when interacting | CSS hover/focus |
Pointing and Focus |
| Distribute multiple rays | count |
Multiple layers |
| Transfer decoration between nodes | change target |
Your own container |
| Choose a color transition | color |
Gradients |
| Fit effect into crop | outset={0} |
Thickness and borders |
Decoration is created only for HTMLElement. SVGElement is allowed by the type, but ignored by runtime. The container must specify a positioning context, usually position:relative. The effect requires support for CSS mask-composite and offset-path. Before mount or without a suitable target, the usual content remains.
Color, number and size of beam
count evenly distributes the rays and their phases. The final value from 1 is rounded down, the rest are replaced by 1. duration sets the revolution in seconds, default - 6; CSS animation does not require a background JS application timer.
color accepts one CSS color or an array of stops with percent from 0 to 100 in the desired order. The stops are scaled to the colored 70% gradient, leaving a transparent tail. This is not a percentage of the path length.
size specifies the side of the moving square layer. A square that is too large may highlight the opposite side. Choose a size noticeably smaller than twice the short side of the container and take into account the radius, lineWidth and outset.
lineWidth and outset accept a number in px or a CSS length. The radius is inherited via CSS and updated with the container. Automatic outset - a snapshot of four border-width values when binding a target; for dynamic thickness, set it explicitly. outset:0 is needed for a container with overflow:hidden.
Life cycle, theme and limitations of
When changing target, old layers are deleted, new ones are added to the new HTMLElement. Disabling the effect and unmount removes the decoration while preserving the original DOM. SSR displays content without decorative layers.
Prefers-reduced-motion hides the beam and disables animation. The effect is aria-hidden, does not intercept the pointer and does not participate in Tab order. Therefore, the semantics and availability of the action are determined by the container itself and its contents.
ConfigProvider.borderBeam sets the general class/style. Then the local style is applied, followed by the explicit props variables. Without color, primary/primaryHover themes are used. There are no named semantic slots or BorderBeam component design tokens.
items and BorderBeamItem from Ant Design 6.7 have not yet been carried over. The current API uses count with generic color/lineWidth/outset/size. Do not transfer new per-beam settings to an example without public package support.
A non-empty local prefixCls specifies the full CSS class of each layer. The empty string and undefined inherit ConfigProvider.prefixCls with the -border-beam suffix, defaulting to ant-border-beam. Example of prefixes uses one local project-beam in two independent areas. Changing prefix preserves layers, target, editor DOM, focus and selection; the animation name antBorderBeamMove remains the same.
Geometry service variables use a common provider prefix without dots: for example, --suite-border-beam-*. Local prefixCls and theme.cssVar.prefix have no effect on this namespace. These are internal parameters: set duration/size/lineWidth/outset via props. For hover and other custom CSS, use a class rather than binding to the standard ant-border-beam.
Examples
The ray follows the radius of the true root of the Card.
Beam around Card
bind:nativeElement of the Card root, without additional wrapper.
<script lang="ts">
import { BorderBeam, Button, Card } from '@woodger/antd';
let target = $state<HTMLDivElement>();
let clicks = $state(0);
</script>
<style>
output {
display: block;
margin-top: 16px;
}
</style>
<Card
title={("Svelte Documentation")}
bind:nativeElement={target}
style="position: relative"
>
<p>{("The ray follows the radius of the true root of the Card.")}</p>
<Button onclick={() => { clicks++; }}>{("Action inside the border")}</Button>
<output
aria-label={("BorderBeam Action")}
>{("Presses: ")}{clicks}</output>
<BorderBeam {target} />
</Card>
Hover or focus on a button.
Display with hover and focus
Hiding via CSS; the keyboard also reveals the scenery.
<script lang="ts">
import { BorderBeam, Button } from '@woodger/antd';
let target = $state<HTMLDivElement>();
</script>
<style>
.host {
position: relative;
padding: 24px;
border: 1px solid var(--ant-color-border);
border-radius: 16px;
}
.host :global(.hover-beam) {
opacity: 0;
transition: opacity 150ms;
}
.host:hover :global(.hover-beam), .host:focus-within :global(.hover-beam) { opacity: 1; }
p { margin: 0 0 16px; }
@media (prefers-reduced-motion: reduce) { .host :global(.hover-beam) { transition: none; } }
</style>
<div class="host" bind:this={target}>
<p>{("Hover or focus on a button.")}</p>
<Button>{("Focus inside BorderBeam")}</Button>
<BorderBeam {target} class="hover-beam" color="#d48806" />
</div>
Multiple beams
count distributes the rays and their negative phases evenly.
<script lang="ts">
import { BorderBeam, RadioGroup } from '@woodger/antd';
let target = $state<HTMLDivElement>();
let count = $state(2);
</script>
<style>
.settings { margin-bottom: 16px; }
.host {
position: relative;
min-height: 120px;
padding: 24px;
border: 1px solid var(--ant-color-border);
border-radius: 16px;
}
</style>
<div
class="settings"
><RadioGroup
aria-label={("Number of decorative rays")}
bind:value={count}
options={([{ value: 1, label: "One" }, { value: 2, label: "Two" }, {
value: 3,
label: "Three"
}])}
/></div>
<div
class="host"
bind:this={target}
>{("Uniform distribution along the contour.\n ")}<BorderBeam
{target}
{count}
color="#389e0d"
/>
</div>
Own container
Explicit target, switching between nodes and removing effect.
<script lang="ts">
import { BorderBeam, Checkbox } from '@woodger/antd';
let first = $state<HTMLDivElement>();
let second = $state<HTMLDivElement>();
let alternate = $state(false);
let enabled = $state(true);
</script>
<style>
.settings {
display: grid;
gap: 12px;
margin-bottom: 16px;
}
.hosts {
display: grid;
gap: 16px;
}
.host {
position: relative;
padding: 24px;
border: 2px solid var(--ant-color-border);
border-radius: 16px;
}
.second { border-radius: 32px; }
</style>
<div class="settings">
<Checkbox bind:checked={alternate}>
{("Highlight the second container")}
</Checkbox>
<Checkbox
bind:checked={enabled}
>{("Enable beam of own container")}</Checkbox>
</div>
<div
class="hosts"
><div
class="host first"
bind:this={first}
>{("First container")}</div>
<div class="host second" bind:this={second}>{("Second container")}</div></div>
{#if enabled}<BorderBeam target={alternate ? second : first} color="#722ed1" lineWidth={2} />{/if}
Gradients
Six palettes with 0-100% stops and a transparent tail.
<script lang="ts">
import { BorderBeam, RadioGroup, type BorderBeamGradient } from '@woodger/antd';
const palettes: { value: string; label: string; color: BorderBeamGradient }[] = [
{
value: 'forest', label: "Forest", color: [{ color: '#237804', percent: 0 }, {
color: '#a0d911',
percent: 50
}, { color: '#faad14', percent: 100 }]
},
{
value: 'sunset', label: "Sunset", color: [{ color: '#d4380d', percent: 0 }, {
color: '#fa8c16',
percent: 50
}, { color: '#ffd666', percent: 100 }]
},
{
value: 'orchid', label: "Orchid", color: [{ color: '#531dab', percent: 0 }, {
color: '#c41d7f',
percent: 100
}]
},
{
value: 'lagoon', label: "Lagoon", color: [{ color: '#006d75', percent: 0 }, {
color: '#36cfc9',
percent: 100
}]
},
{
value: 'ember', label: "Coal", color: [{ color: '#820014', percent: 0 }, {
color: '#f5222d',
percent: 60
}, { color: '#fa8c16', percent: 100 }]
},
{
value: 'gold', label: "Gold", color: [{ color: '#874d00', percent: 0 }, {
color: '#ffc53d',
percent: 100
}]
}
];
let selected = $state('forest');
let target = $state<HTMLDivElement>();
const palette = $derived(palettes.find(item => item.value === selected) ?? palettes[0]);
</script>
<style>
.settings { margin-bottom: 16px; }
.host {
position: relative;
min-height: 120px;
padding: 24px;
border: 1px solid var(--ant-color-border);
border-radius: 16px;
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
<div
class="settings"
><RadioGroup
aria-label={("BorderBeam Palette")}
bind:value={selected}
options={(palettes)}
/></div>
<div class="host" bind:this={target}>{(palette.label)}{(": color stops 0–100%.\n ")}<BorderBeam {target} color={palette
.color} />
</div>
<output aria-label={("BorderBeam Colors")}>{palette.color.map(
stop => `${stop.color}: ${stop.percent}%`
).join('; ')}</output>
Turnover time
3, 6 or 12 seconds without timers in the app.
<script lang="ts">
import { BorderBeam, RadioGroup } from '@woodger/antd';
let target = $state<HTMLDivElement>();
let duration = $state(6);
</script>
<style>
.settings { margin-bottom: 16px; }
.host {
position: relative;
min-height: 120px;
padding: 24px;
border: 1px solid var(--ant-color-border);
border-radius: 16px;
}
</style>
<div
class="settings"
><RadioGroup
aria-label={("BorderBeam Duration")}
bind:value={duration}
options={([{ value: 3, label: "3 s" }, { value: 6, label: "6 s" }, {
value: 12,
label: "12 s"
}])}
/></div>
<div class="host" bind:this={target}>{("Full turn for ")}{duration}{(" seconds.\n ")}<BorderBeam {target} {duration} color="#d48806" />
</div>
Segment size
56, 100 or 160px; the size of the square layer, not the length of the path.
<script lang="ts">
import { BorderBeam, RadioGroup } from '@woodger/antd';
let target = $state<HTMLDivElement>();
let size = $state(100);
</script>
<style>
.settings { margin-bottom: 16px; }
.host {
position: relative;
min-height: 140px;
padding: 24px;
border: 1px solid var(--ant-color-border);
border-radius: 16px;
}
</style>
<div class="settings"><RadioGroup aria-label={("BorderBeam Size")} bind:value={size}
options={([{ value: 56, label: '56 px' }, { value: 100, label: '100 px' }, {
value: 160,
label: '160 px'
}])} /></div>
<div class="host" bind:this={target}>{("Gradient layer size: ")}{size} px.
<BorderBeam {target} {size} color="#722ed1" />
</div>
Thickness and outset
Numerical thickness and outset=0 for overflow: hidden.
<script lang="ts">
import { BorderBeam, RadioGroup } from '@woodger/antd';
let target = $state<HTMLDivElement>();
let lineWidth = $state(2);
</script>
<style>
.settings { margin-bottom: 16px; }
.host {
position: relative;
overflow: hidden;
padding: 24px;
border: solid var(--ant-color-border);
border-radius: 24px;
}
</style>
<div
class="settings"
><RadioGroup
aria-label={("BorderBeam Thickness")}
bind:value={lineWidth}
options={([{ value: 1, label: '1 px' }, { value: 2, label: '2 px' }, {
value: 4,
label: '4 px'
}])}
/></div>
<div
class="host"
bind:this={target}
style:border-width={("" + String((lineWidth)) + "px")}
>{("Outset=0 keeps the effect inside the clipped container.\n ")}<BorderBeam {target} {lineWidth} outset={0} color="#d48806" />
</div>
Theme and ConfigProvider
Color/thickness from tokens, nested RTL, class/style and local priority.
<script lang="ts">
import { BorderBeam, ConfigProvider } from '@woodger/antd';
let target = $state<HTMLDivElement>();
</script>
<style>
.host {
position: relative;
padding: 24px;
border: 2px solid var(--ant-color-border);
border-radius: 16px;
}
</style>
<ConfigProvider direction="rtl" theme={{ token: { colorPrimary: '#389e0d', lineWidth: 2 } }}
borderBeam={{ class: 'beam-provider-layer', style: 'opacity: 0.4' }}>
<div class="host" bind:this={target}>{("The color is taken from the theme; local style overrides provider transparency.\n ")}<BorderBeam {target} class="beam-local-layer" style="opacity: 1" />
</div>
</ConfigProvider>
Single beam independent area.
The same local class does not mix the parameters of the two areas. The namespace of the utility geometry follows a common prefix, separate from theme.cssVar.prefix.
Local and general prefix
Same class in different areas, independent ray parameters and saving the editor.
<script lang="ts">
import { BorderBeam, Checkbox, ConfigProvider, Input } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
let target = $state<HTMLDivElement>();
let neighbor = $state<HTMLDivElement>();
let draft = $state('');
const prefix = $derived(custom ? 'suite' : 'ant');
</script>
<style>
.example {
display: grid;
gap: 20px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.host {
position: relative;
box-sizing: border-box;
min-height: 112px;
padding: 20px;
border: 1px solid var(--ant-color-border);
border-radius: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix BorderBeam suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix BorderBeam")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'beam-theme' } }}>
<div class="host" bind:this={target} role="group" aria-label={("Main container BorderBeam")}>
<Input
bind:value={draft}
aria-label={("BorderBeam draft with prefix")}
placeholder={("Draft")}
/>
<BorderBeam {target} prefixCls={local ? 'project-beam' : ''} class="prefix-beam-layer"
count={2} size={64} duration={8} lineWidth={2} outset={0} />
</div>
</ConfigProvider>
<ConfigProvider prefixCls="neighbor" theme={{ cssVar: { prefix: 'neighbor-theme' } }}>
<div class="host" bind:this={neighbor} role="group" aria-label={("Neighboring BorderBeam Container")}>
<p>{("Single beam independent area.")}</p>
<BorderBeam
target={neighbor}
prefixCls={local ? 'project-beam' : ''}
class="prefix-beam-layer"
size={40}
duration={12}
lineWidth={1}
outset={0}
/>
</div>
</ConfigProvider>
<output
aria-label={("BorderBeam Prefix")}
>{("\n General: ")}{prefix}{("; class: ")}{(local ? 'project-beam' : prefix + '-border-beam')}
</output>
<p>
{("The same local class does not mix the parameters of the two areas. The namespace of the utility geometry follows a common prefix, separate from theme.cssVar.prefix.")}
</p>
</div>
Light along the border
Several rays move along the contour of the card. Choose their number or turn off the effect.
Initial interactive example
Saved demo with effect enabled and number of rays selected.
<script lang="ts">
import { BorderBeam, RadioGroup } from '@woodger/antd';
let target = $state<HTMLDivElement>();
let count = $state(2);
let enabled = $state(true);
</script>
<style>
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.controls label {
display: flex;
align-items: center;
gap: 8px;
}
.card {
position: relative;
max-width: 480px;
padding: 24px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 12px;
background: var(--ant-color-bg-container);
}
h3 {
margin: 0 0 8px;
font-size: 16px;
}
p {
margin: 0;
color: var(--ant-color-text-secondary);
line-height: 1.6;
}
</style>
<div class="controls">
<label><input
type="checkbox"
bind:checked={enabled}
/>{(" Border illumination")}</label>
<RadioGroup
aria-label={("Number of beams")}
options={([{ value: 1, label: "One" }, { value: 2, label: "Two" }, {
value: 3,
label: "Three"
}])}
value={count}
optionType="button"
onValueChange={next => { count = next; }}
/>
</div>
<div class="card" bind:this={target}>
<h3>{("Light along the border")}</h3>
<p>{("Several rays move along the contour of the card. Choose their number or turn off the effect.")}</p>
{#if enabled}
<BorderBeam
{target}
{count}
duration={6}
color={[{ color: '#1677ff', percent: 0 }, { color: '#722ed1', percent: 100 }]}
/>
{/if}
</div>
API
Themes and behavior verified against BorderBeam on ant.design 6.7.0. The current build retains the 6.6.8 generation API and replaces React child ref with an explicit target. The new items from 6.7 are not yet supported.
| Theme | Example or limitation |
|---|---|
| Basic | Card with an explicit DOM target. |
| Show on hover | CSS hover/focus-within; also available from the keyboard. |
| Multiple beams | count supported. New items from 6.7 and BorderBeamItem are not yet available. |
| Custom container | Native HTMLElement and target rebinding. |
| Gradients | Six palettes, percent 0–100 and a transparent tail. |
| Duration | Duration of a full revolution in seconds. |
| Size | The size of the moving square gradient layer. |
| Line width | lineWidth and explicit outset in the clipped container. |
| CSS prefixes | Local classes and common namespace of geometry of independent areas. |
BorderBeam
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS layer class. The empty string and undefined inherit the same prefix. The namespace of service variables depends on ConfigProvider.prefixCls, separate from the local class and theme.cssVar.prefix. | string | ConfigProvider + -border-beam |
target | In fact, decoration is created only for HTMLElement. SVGElement is accepted by the type but ignored. Without target, only children remain. | HTMLElement | SVGElement | null | — |
children | Contents without new wrapper. boolean/null are not output. | Snippet | string | number | boolean | null | — |
color | A color or array of color stops in original order. | string | BorderBeamGradient | primary / primaryHover |
count | Final number ≥1 is rounded down; other values are replaced by 1. | number | 1 |
duration | Duration of rotation in seconds. | number | 6 |
lineWidth | Line thickness. Number - px, line - CSS length. | number | string | theme.lineWidth |
outset | External offset. 0 keeps the layer inside. Border widths are measured when the target is changed, not every time the CSS is changed. | number | string | shot border-width target |
size | The size of the square gradient layer. | number | string | 100px |
class | A local class is added to the provider class on each layer. | string | ConfigProvider.borderBeam.class |
style | Local CSS comes after provider; explicit props set variables after style. | string | ConfigProvider.borderBeam.style |
BorderBeamGradient: color stop
| Property | Description | Type | Default |
|---|---|---|---|
color | CSS color color stop. | string | is required |
percent | Position 0–100 displayed in color 70% layer; the remaining part fades to transparent. | number | is required |
ConfigProvider.borderBeam
| Property | Description | Type | Default |
|---|---|---|---|
class | General class of all decorative layers. | string | — |
style | General CSS layers; local style takes precedence. The nested borderBeam config is replaced entirely. | string | — |
Decorative layers are added after mount inside the HTMLElement and removed when the target is changed or unmounted. children is simply output without any additional wrapper; target is not automatically determined by it.
Semantic DOM
The official page does not publish Semantic DOM slots BorderBeam. The actual @woodger/antd layers are described below: class/style refers to the decoration, not the host. Layers are excluded from the accessibility tree and do not intercept the pointer.
The selectors below are for the standard prefix. For native CSS, pass persistent class, as in the hover example: it persists when changed prefixCls.
| Element | Purpose |
|---|---|
target | An existing container with position: relative and radius. Its markings belong to the owner. |
.ant-border-beam | Decorative div inside target, aria-hidden=true and pointer-events=none. One layer per beam. |
.ant-border-beam::before | Moving square gradient, CSS offset-path and mask. Hidden during reduced motion. |
Registration tokens
BorderBeam does not have its own component tokens. The default color and line thickness are inherited from the three common tokens below. Props color/lineWidth override them for a specific ray.
| Token | Meaning |
|---|---|
colorPrimary | #2f54eb |
colorPrimaryHover | #597ef7 |
lineWidth | 1 |
FAQ
Why didn't the beam appear?
We need a real HTMLElement in the target, a positioned container and CSS support. Use bind:this or bind:nativeElement.
What happens with reduced motion?
The beam is hidden, but the normal border and content remain.
What does percent mean at the color stop?
A position from 0 to 100, scaled to the visible part of the gradient with a transparent tail.
Why does large size highlight the opposite edge?
This is the size of the square layer. Compare it to the short side of the container, not the length of the path.
Is the radius and thickness updated?
Radius is inherited through CSS. Automatic outset is measured when changing target; for dynamic thickness, pass outset explicitly.
What remains after changing target or unmount?
Decorative layers are removed from the old node. The original content is retained.
Are there items for individual rays?
Not yet. count and general settings supported; per-beam API 6.7 remains a gap.
How to redefine the appearance?
Provider style, then local style, then explicit props variables. class is added to the general provider class.