---
title: Astro Dot Pattern with Glow
description: A dot background that reveals a colored glow under the pointer.
seo:
    title: "Astro Dot Pattern with Glow: examples and source"
sidebar:
    label: "Dot Pattern with Glow"
related:
    - /patterns
    - /patterns/hexagon-pattern
    - /patterns/hover-glow
    - /themes
---

```astro
---
import { DotPatternWithGlow } from "@/components/patterns/dot-pattern-with-glow"
---

<DotPatternWithGlow class="bg-background flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border">
  <p class="text-sm font-medium">Move the pointer</p>
</DotPatternWithGlow>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/dot-pattern-with-glow
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/patterns/dot-pattern-with-glow/dot-pattern-with-glow.astro

```astro
---
import type { HTMLAttributes } from "astro/types"
import type { DotPatternWithGlowProps } from "./types.ts"

import { mergeStyles } from "@/lib/merge-styles.ts"

import DotPattern from "@/components/patterns/dot-pattern/dot-pattern.astro"
import HoverGlow from "@/components/patterns/hover-glow/hover-glow.astro"

/**
 * Dot background with a glow clipped to each dot.
 *
 * HoverGlow tracks the pointer. This component adds the base dots and
 * the mask that shows the glow only inside those dots.
 */
type Props = HTMLAttributes<"div"> & DotPatternWithGlowProps

const {
  glowColor,
  glowSize,
  maskDotSize = 1.25,
  dotLayerProps,
  class: className,
  style: styleProp,
  ...props
} = Astro.props

/** Space between dots. The mask tile uses the same distance. */
const dotSpace = dotLayerProps?.dotSpace ?? 16
/** Radius of each base dot. */
const dotSize = dotLayerProps?.dotSize ?? 1

/** The mask repeats so the glow is visible only inside each dot. */
// const style = mergeStyles(
//   {
//     "--pattern-mask-dot-size": `${maskDotSize}px`,
//   },
//   styleProp,
// )
const style =
  typeof styleProp === "string"
    ? `--pattern-mask-dot-size: ${maskDotSize}px; ${styleProp}`
    : {
        ...styleProp,
        "--pattern-mask-dot-size": `${maskDotSize}px`,
      }
---

<HoverGlow
  glowColor={glowColor}
  glowSize={glowSize}
  maskImage="radial-gradient(circle, black var(--pattern-mask-dot-size), transparent var(--pattern-mask-dot-size))"
  maskSize={`${dotSpace}px ${dotSpace}px`}
  maskPosition="center"
  class={className}
  style={style}
  {...props}
>
  <slot />
  <DotPattern
    dotSize={dotSize}
    dotSpace={`${dotSpace}px`}
    dotColor={dotLayerProps?.dotColor}
    dotBg={dotLayerProps?.dotBg}
    class={dotLayerProps?.class}
    style={dotLayerProps?.style}
  />
</HoverGlow>
```

#### src/components/patterns/dot-pattern-with-glow/index.ts

```ts
export { default as DotPatternWithGlow } from './dot-pattern-with-glow.astro'
export type { DotPatternWithGlowProps } from './types.ts'
```

#### src/components/patterns/dot-pattern-with-glow/types.ts

```ts
/**
 * Options forwarded to the base dot layer.
 * `dotSize` and `dotSpace` also align the glow mask with those dots.
 */

type DotLayerProps = {
    /** Radius of each base dot, in pixels. */
    dotSize?: number
    /** Distance from one base dot to the next, in pixels. */
    dotSpace?: number
    /** CSS color of each base dot. */
    dotColor?: string
    /** CSS color behind the base dots. */
    dotBg?: string
    /** Extra classes on the base dot layer. */
    class?: string
    /** Extra CSS declarations on the base dot layer. */
    style?: astroHTML.JSX.CSSProperties
}

/**
 * Dot background with a glow that follows the pointer.
 *
 * The base dots stay visible. HoverGlow paints the color layer. A dot mask
 * shows that color only inside the dot shapes.
 */
export type DotPatternWithGlowProps = {
    /**
     * CSS color of the glow.
     * Use the color's alpha value to set the glow opacity.
     * The default keeps the glow soft.
     *
     * @default "color-mix(in oklch, var(--primary) 72%, transparent)"
     */
    glowColor?: string
    /**
     * Radius of the glow, in pixels.
     * @default 96
     */
    glowSize?: number
    /**
     * Radius of each dot in the glow mask, in pixels.
     * @default 1.25
     */
    maskDotSize?: number
    /**
     * Props for the base dot layer.
     *
     * @link {DotPatternProps}
     */
    dotLayerProps?: DotLayerProps
}
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

The component is the positioned container. Move the pointer over it to show
the glow. The slot renders inside that container, under the dot layers.

The pointer effect comes from [Hover Glow](/ui/patterns/hover-glow). This
component adds the base dots and a mask, so the color shows only inside each
dot.

```ts
import { DotPatternWithGlow } from "@/components/patterns/dot-pattern-with-glow"
```

```astro
<DotPatternWithGlow class="h-72">
  <p>Move the pointer</p>
</DotPatternWithGlow>
```

The glow color defaults to a 40 percent mix of `var(--color-primary)`.
Pass `var(--color-primary)` when the glow should be stronger:

```astro
<DotPatternWithGlow class="h-72" glowColor="var(--color-primary)" />
```

The glow fades out when the pointer leaves the container or the window loses focus.

## Examples

### Larger glow

`glowSize` sets the glow radius. `maskDotSize` sets the radius of each glowing
dot. `dotLayerProps` sets the base dots and keeps the mask on the same grid.

```astro
---
import { DotPatternWithGlow } from "@/components/patterns/dot-pattern-with-glow"
---

<DotPatternWithGlow
  class="bg-background flex h-72 w-full items-center justify-center overflow-hidden rounded-lg border"
  glowColor="color-mix(in oklch, var(--color-foreground) 75%, transparent)"
  glowSize={140}
  maskDotSize={2}
  dotLayerProps={{ dotSize: 1.25, dotSpace: 22 }}
>
  <p class="text-sm font-medium">Larger glow</p>
</DotPatternWithGlow>
```

## API Reference

### DotPatternWithGlowProps

<AutoTypeTable
    path="../../packages/ui/src/components/patterns/dot-pattern-with-glow/types.ts"
    name="DotPatternWithGlowProps"
/>

See the [registry source](/ui/r/dot-pattern-with-glow.json) for the component source.
