# Dot Pattern

A grid of small dots behind your content, with an optional radial or linear fade. Pure CSS, no JavaScript.

- Category: Backgrounds
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/dot-pattern.json
- CLI: `npx markasui@latest add dot-pattern`

## When to use

A quiet texture behind a hero, CTA card, empty state, or section without adding images.

- Set the background color, padding, and radius with class on the component
- Use mask=radial behind centered text so the dots fade out under the heading
- Use spacing between 12 and 28 for most layouts

## Code

### Blade

Save at `resources/views/components/markas/dot-pattern.blade.php`. No extra dependencies.

```blade
@props([
    'spacing' => 16,
    'dotSize' => 1,
    'color' => 'muted',
    'mask' => 'none',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]';
    $content = 'relative';
    $colors = [
        'muted' => 'text-muted/50',
        'primary' => 'text-primary/40',
        'success' => 'text-success/50',
        'warning' => 'text-warning/50',
        'danger' => 'text-danger/50',
    ];
    $masks = [
        'none' => '',
        'radial' => '[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]',
        'linear' => '[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]',
    ];

    $vars = '--markas-dot-spacing: '.(float) $spacing.'px; --markas-dot-size: '.(float) $dotSize.'px';
@endphp

<div {{ $attributes->merge(['style' => $vars])->class([$base]) }}>
    <div aria-hidden="true" @class([$layer, $colors[$color] ?? $colors['muted'], $masks[$mask] ?? ''])></div>
    <div class="{{ $content }}">{{ $slot }}</div>
</div>
```

```blade
<x-markas.dot-pattern mask="radial" class="rounded-xl border border-line bg-surface px-6 py-12">
    <h2 class="text-2xl font-semibold text-ink">Build interfaces that feel at home</h2>
    <x-markas.button>Get started</x-markas.button>
</x-markas.dot-pattern>
```

No JavaScript or Alpine.js needed.

### React

Save at `src/components/markas/DotPattern.tsx`. No extra dependencies.

```tsx
import type { ComponentProps, CSSProperties } from "react";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type DotPatternProps = ComponentProps<"div"> & {
  spacing?: number;
  dotSize?: number;
  color?: keyof typeof colors;
  mask?: keyof typeof masks;
};

export function DotPattern({
  spacing = 16,
  dotSize = 1,
  color = "muted",
  mask = "none",
  className,
  style,
  children,
  ...props
}: DotPatternProps) {
  const vars = {
    "--markas-dot-spacing": `${spacing}px`,
    "--markas-dot-size": `${dotSize}px`,
  } as CSSProperties;

  return (
    <div
      {...props}
      className={cx(base, className)}
      style={{ ...vars, ...style }}
    >
      <div
        aria-hidden="true"
        className={cx(layer, colors[color], masks[mask])}
      />
      <div className={content}>{children}</div>
    </div>
  );
}
```

```tsx
import { Button } from "@/components/markas/Button";
import { DotPattern } from "@/components/markas/DotPattern";

<DotPattern
  mask="radial"
  className="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 className="text-2xl font-semibold text-ink">
    Build interfaces that feel at home
  </h2>
  <Button>Get started</Button>
</DotPattern>;
```

### Vue

Save at `src/components/markas/DotPattern.vue`. No extra dependencies.

```vue
<script setup lang="ts">
import { computed } from "vue";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};

const props = withDefaults(
  defineProps<{
    spacing?: number;
    dotSize?: number;
    color?: keyof typeof colors;
    mask?: keyof typeof masks;
  }>(),
  { spacing: 16, dotSize: 1, color: "muted", mask: "none" },
);

const vars = computed(() => ({
  "--markas-dot-spacing": `${props.spacing}px`,
  "--markas-dot-size": `${props.dotSize}px`,
}));
</script>

<template>
  <div :class="base" :style="vars">
    <div
      aria-hidden="true"
      :class="[layer, colors[props.color], masks[props.mask]]"
    />
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <DotPattern
    mask="radial"
    class="rounded-xl border border-line bg-surface px-6 py-12"
  >
    <h2 class="text-2xl font-semibold text-ink">
      Build interfaces that feel at home
    </h2>
    <Button>Get started</Button>
  </DotPattern>
</template>
```

### Svelte

Save at `src/lib/components/markas/DotPattern.svelte`. No extra dependencies.

```svelte
<script lang="ts">
  import type { Snippet } from "svelte";
  import type { HTMLAttributes } from "svelte/elements";

  const base = "relative isolate overflow-hidden";
  const layer =
    "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
  const content = "relative";
  const colors = {
    muted: "text-muted/50",
    primary: "text-primary/40",
    success: "text-success/50",
    warning: "text-warning/50",
    danger: "text-danger/50",
  };
  const masks = {
    none: "",
    radial:
      "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
    linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
  };

  type Props = HTMLAttributes<HTMLDivElement> & {
    spacing?: number;
    dotSize?: number;
    color?: keyof typeof colors;
    mask?: keyof typeof masks;
    children?: Snippet;
  };

  let {
    spacing = 16,
    dotSize = 1,
    color = "muted",
    mask = "none",
    class: className,
    style,
    children,
    ...rest
  }: Props = $props();
</script>

<div
  {...rest}
  class={[base, className]}
  style="--markas-dot-spacing:{spacing}px;--markas-dot-size:{dotSize}px;{style ??
    ''}"
>
  <div aria-hidden="true" class={[layer, colors[color], masks[mask]]}></div>
  <div class={content}>{@render children?.()}</div>
</div>
```

```svelte
<script lang="ts">
  import Button from "$lib/components/markas/Button.svelte";
  import DotPattern from "$lib/components/markas/DotPattern.svelte";
</script>

<DotPattern
  mask="radial"
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Build interfaces that feel at home
  </h2>
  <Button>Get started</Button>
</DotPattern>
```

### Astro

Save at `src/components/markas/DotPattern.astro`. No extra dependencies.

```astro
---
import type { HTMLAttributes } from "astro/types";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};

type Props = Omit<HTMLAttributes<"div">, "style"> & {
  spacing?: number;
  dotSize?: number;
  color?: keyof typeof colors;
  mask?: keyof typeof masks;
  style?: string;
};

const {
  spacing = 16,
  dotSize = 1,
  color = "muted",
  mask = "none",
  class: className,
  style,
  ...rest
} = Astro.props;
---

<div
  {...rest}
  class:list={[base, className]}
  style={`--markas-dot-spacing:${spacing}px;--markas-dot-size:${dotSize}px;${style ?? ""}`}
>
  <div aria-hidden="true" class:list={[layer, colors[color], masks[mask]]}></div>
  <div class={content}><slot /></div>
</div>
```

```astro
---
import Button from "@/components/markas/Button.astro";
import DotPattern from "@/components/markas/DotPattern.astro";
---

<DotPattern
  mask="radial"
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Build interfaces that feel at home
  </h2>
  <Button>Get started</Button>
</DotPattern>
```

No client-side JavaScript; the markup is rendered on the server.

### Angular

Save at `src/app/markas/dot-pattern.component.ts`. No extra dependencies.

```ts
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
  numberAttribute,
} from "@angular/core";

const base = "relative isolate overflow-hidden";
const layer =
  "pointer-events-none absolute inset-0 bg-[radial-gradient(circle,currentColor_var(--markas-dot-size),transparent_calc(var(--markas-dot-size)_+_0.5px))] [background-size:var(--markas-dot-spacing)_var(--markas-dot-spacing)]";
const content = "relative";
const colors = {
  muted: "text-muted/50",
  primary: "text-primary/40",
  success: "text-success/50",
  warning: "text-warning/50",
  danger: "text-danger/50",
};
const masks = {
  none: "",
  radial:
    "[mask-image:radial-gradient(ellipse_at_center,black_20%,transparent_75%)]",
  linear: "[mask-image:linear-gradient(to_bottom,black_10%,transparent_90%)]",
};

export type DotPatternColor = keyof typeof colors;
export type DotPatternMask = keyof typeof masks;

/** Attribute selector on a native div: the user's class, style, and attributes stay on the root. */
@Component({
  selector: "div[markas-dot-pattern]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    "[class]": "base",
    "[style.--markas-dot-spacing]": "spacing() + 'px'",
    "[style.--markas-dot-size]": "dotSize() + 'px'",
  },
  template: `
    <div aria-hidden="true" [class]="layerClasses()"></div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class DotPattern {
  readonly spacing = input(16, { transform: numberAttribute });
  readonly dotSize = input(1, { transform: numberAttribute });
  readonly color = input<DotPatternColor>("muted");
  readonly mask = input<DotPatternMask>("none");

  protected readonly base = base;
  protected readonly content = content;
  protected readonly layerClasses = computed(
    () => `${layer} ${colors[this.color()]} ${masks[this.mask()]}`,
  );
}
```

```ts
import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { DotPattern } from "./markas/dot-pattern.component";

@Component({
  selector: "app-hero",
  imports: [Button, DotPattern],
  template: `
    <div
      markas-dot-pattern
      mask="radial"
      class="rounded-xl border border-line bg-surface px-6 py-12"
    >
      <h2 class="text-2xl font-semibold text-ink">
        Build interfaces that feel at home
      </h2>
      <button markas-button>Get started</button>
    </div>
  `,
})
export class Hero {}
```

The component is an attribute on a div, so class, style, and other attributes stay on the root element.

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `spacing` | `number` | 16 | Distance between dots in pixels. Smaller values make a denser pattern. |
| `dotSize` | `number` | 1 | Dot radius in pixels. |
| `color` | `muted \| primary \| success \| warning \| danger` | muted | Token color of the dots, already softened with opacity. |
| `mask` | `none \| radial \| linear` | none | Fade the dots toward the edges (radial) or toward the bottom (linear). |
| `children / slot` | `slot / ReactNode / snippet` | - | Content shown on top of the pattern. |

## Accessibility

- The pattern layer is aria-hidden and ignores pointer events, so only your content is announced and clickable.
- Keep text contrast in mind: put the pattern on bg-surface or bg-canvas and use a mask behind long text.

## Notes

- `spacing` and `dotSize` are in pixels. Use `color` for a token tint and `mask` to fade the edges.
- Pure CSS: no JavaScript and nothing to animate, so it costs nothing at runtime.
- The component has no built-in text, so there are no label props to translate.
