Skip to documentation content

Contour Lines

Topographic contour lines drifting over a slowly changing field.

contour-lines-demo

Overview

Contour Lines draws the level lines of a slowly shifting terrain, like a topographic map. Every majorEveryth line is an index contour, drawn thicker and brighter. The hills reshape gently over time rather than sliding across the surface.

The background is transparent and the lines use currentColor at low opacity by default, so the effect follows the text color in light and dark themes. Use it behind a section heading, an empty state, or a data product's landing page.

Installation

npm install honestui

Usage

import { ContourLines } from "honestui/shaders"

<div className="relative h-96 bg-background text-foreground">
  <ContourLines className="absolute inset-0" fade="radial" />
  <div className="relative grid h-full place-items-center">
    <h2 className="text-3xl font-medium">Know the terrain.</h2>
  </div>
</div>

Lines are antialiased at their CSS width on any screen density. Lower levels or raise scale for a calmer map, and use fade to keep the lines away from the edges.

Accessibility

Contour Lines is decorative and its canvas is hidden from assistive technology. Keep text and actions in normal HTML; at the default opacity the lines stay well below body text in contrast.

The effect pauses while it is offscreen or the tab is hidden, and shows a still frame when the user prefers reduced motion. Without WebGL the container shows only its own background.

API Reference

PropTypeDefaultDescription
colorstring"currentColor"Line color. Any CSS color; currentColor follows the text color and theme.
opacitynumber0.35Line opacity, from 0 to 1.
lineWidthnumber1Line width in CSS pixels.
levelsnumber14Number of contour levels across the field.
majorEverynumber5Draw every Nth line thicker and brighter. 0 turns index contours off.
scalenumber1Size of the terrain. Larger values draw more, smaller hills.
fadenone|radial|edges|top|bottom"none"Fade the lines out toward the edges.
speednumber1Animation speed. 0 holds the terrain still.
pausedbooleanfalseRenders a still frame instead of animating.
classNamestring–Class for sizing and positioning the container.
childrenReactNode–Content rendered above the lines.