DocumentationSpaceType

SpaceType

Wraps a phrase around rotating rings with a soft radial wave.

Words in orbit · Make it yours
KIDA-UI / SMALL-DETAILS-BIG-DELIGHT /
1.00×
#211C24
#FFFAFB
Auto

Smaller rings pack the letters closer. Letter size stays fixed.

0%

Pulse the rings and tilt the letters with the wave.

Make it yours. Set speed to zero to pause.

Pass the phrase through the text prop. Native attributes and events use Svelte spelling, such as onclick, and bind:element gives you the root DOM element.

Quick start

Add to your project

Copy the component and everything it needs into your Svelte 5 project.

RecommendedUse the shadcn-svelte CLI
npx shadcn-svelte@1.8.0 add https://kida-ui.onrender.com/r/svelte/space-type.json

Run this from a project with components.json. The CLI creates all required files and installs the declared runtime dependencies. New to shadcn? Follow theinstallation guide first.

Files land in src/lib/components/ui/kida by default. SvelteKit 3 projects import them through #lib; SvelteKit 2 and Vite projects use $lib, as in the examples here.

View registry JSON
Copy manually6 files

1. Create the source files

Keep this directory structure so the component's relative imports continue to work.

src/lib/components/ui/kida/space-type.svelte
<script lang="ts">
import './space-type.css'
import { getSpaceTypeGeometry, type SpaceTypeControls, spaceType } from './space-type.motion.js'
import { untrack } from 'svelte'
import type { SpaceTypeProps } from './space-type.types.js'

let {
  text,
  rows = 1,
  color,
  background,
  longitude = 0,
  radius,
  speed = 1,
  paused = false,
  onGeometryChange,
  element = $bindable(null),
  style,
  ...rest
}: SpaceTypeProps = $props()

let size = $state({ width: 0, height: 0 })
let controls: SpaceTypeControls | null = null
const root = $derived(element)

const rowCount = $derived(Number.isFinite(rows) ? Math.max(1, Math.min(6, Math.round(rows))) : 1)
const wave = $derived(Number.isFinite(longitude) ? Math.max(0, Math.min(100, longitude)) : 0)
const characters = $derived(Array.from(text))
const rowIndexes = $derived(Array.from({ length: rowCount }, (_, row) => row))
const geometry = $derived(
  getSpaceTypeGeometry(size.width, size.height, characters.length, rowCount, wave, radius),
)
const geometryKey = $derived(JSON.stringify(geometry))
const stopped = $derived(paused || characters.length === 0)
const playbackKey = $derived(`${speed}:${stopped}`)

$effect(() => {
  const node = root
  if (!node) return
  const observer = new ResizeObserver(([entry]) => {
    if (!entry) return
    const { width, height } = entry.contentRect
    if (size.width !== width || size.height !== height) size = { width, height }
  })
  observer.observe(node)
  const created = untrack(() => spaceType(node, { speed, paused: stopped }))
  controls = created
  return () => {
    observer.disconnect()
    created.destroy()
    if (controls === created) controls = null
  }
})

$effect(() => {
  void playbackKey
  untrack(() => controls?.setPlayback({ speed, paused: stopped }))
})

$effect(() => {
  void geometryKey
  untrack(() => onGeometryChange?.(geometry))
})

const rootStyle = $derived(
  [
    `--kida-space-type-count: ${Math.max(characters.length, 1)}`,
    `--kida-space-type-rows: ${rowCount}`,
    `--kida-space-type-longitude: ${wave}`,
    color === undefined ? '' : `--kida-space-type-color: ${color}`,
    background === undefined ? '' : `--kida-space-type-background: ${background}`,
    geometry ? `--kida-space-type-size: ${geometry.fontSize}px` : '',
    geometry ? `--kida-space-type-radius: ${geometry.radius}px` : '',
    geometry ? `--kida-space-type-perspective: ${geometry.perspective}px` : '',
    style,
  ]
    .filter(Boolean)
    .join('; '),
)
</script>

<div {...rest} bind:this={element} data-kida-space-type="" style={rootStyle}>
  <span data-kida-space-type-text="">{text}</span>
  <div data-kida-space-type-space="" aria-hidden="true">
    <div data-kida-space-type-camera="">
      <div data-kida-space-type-ring="">
        {#each rowIndexes as row (row)}
          <div data-kida-space-type-row="" style:--kida-space-type-row={row}>
            {#each characters as character, index (index)}<span data-kida-space-type-letter="" style:--kida-space-type-index={index}><span data-kida-space-type-face="front">{character}</span><span data-kida-space-type-face="back">{character}</span></span>{/each}
          </div>
        {/each}
      </div>
    </div>
  </div>
</div>
src/lib/components/ui/kida/space-type.types.ts
import type { SpaceTypeGeometry, SpaceTypeOptions } from './space-type.motion.js';

import type { HTMLAttributes } from 'svelte/elements';

export type { SpaceTypeGeometry } from './space-type.motion.js';

type TextAttributes<T extends EventTarget> = Omit<HTMLAttributes<T>, 'children'>;

export interface SpaceTypeProps extends SpaceTypeOptions, TextAttributes<HTMLDivElement> {
    text: string;
    rows?: number;
    color?: string;
    background?: string;
    longitude?: number;
    radius?: number;
    onGeometryChange?: (geometry: SpaceTypeGeometry | null) => void;
    element?: HTMLDivElement | null;
}
src/lib/components/ui/kida/space-type.css
[data-kida-space-type] {
  --kida-space-type-color: #211c24;
  --kida-space-type-background: #fffafb;
  width: 100%;
  --kida-space-type-size: calc(
    min(9cqw, 350cqw / var(--kida-space-type-count), 20cqw / var(--kida-space-type-rows))
  );
  /* Reserve the strongest wave before measurement as well. */
  --kida-space-type-radius: calc(34cqw / 1.32);
  position: relative;
  container-type: inline-size;
  height: var(--kida-space-type-height, clamp(15rem, 40vw, 28rem));
  padding: 0;
  border: 0;
  overflow: clip;
  background: var(--kida-space-type-background);
}

[data-kida-space-type] [data-kida-space-type-space] {
  position: relative;
  width: 100%;
  height: 100%;
  user-select: none;
  pointer-events: none;
  perspective: var(--kida-space-type-perspective, 1200cqw);
}

[data-kida-space-type] [data-kida-space-type-camera],
[data-kida-space-type] [data-kida-space-type-ring],
[data-kida-space-type] [data-kida-space-type-row],
[data-kida-space-type] [data-kida-space-type-letter] {
  position: absolute;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

[data-kida-space-type] [data-kida-space-type-camera] {
  top: 50%;
  left: 50%;
  transform: rotateX(18deg) rotateZ(-3deg);
}

[data-kida-space-type] [data-kida-space-type-ring] {
  transform: rotateY(-90deg);
}

[data-kida-space-type] [data-kida-space-type-row] {
  /* A wave travels along the cylinder's rows. Each letter follows its local slope. */
  --kida-space-type-wave-angle: calc(
    var(--kida-space-type-phase) *
    2880deg +
    var(--kida-space-type-row) *
    2160deg /
    var(--kida-space-type-count)
  );
  --kida-space-type-wave-amplitude: calc(
    var(--kida-space-type-radius) *
    var(--kida-space-type-longitude) *
    0.0032
  );
  --kida-space-type-row-radius: calc(
    var(--kida-space-type-radius) +
    sin(var(--kida-space-type-wave-angle)) *
    var(--kida-space-type-wave-amplitude)
  );
  --kida-space-type-surface-tilt: atan2(
    calc(
      var(--kida-space-type-wave-amplitude) *
      cos(var(--kida-space-type-wave-angle)) *
      sin(2160deg / var(--kida-space-type-count))
    ),
    calc(var(--kida-space-type-size) * 1.2)
  );
  transform: translateY(
    calc(
      (var(--kida-space-type-row) - (var(--kida-space-type-rows) - 1) / 2) *
      var(--kida-space-type-size) *
      1.2
    )
  );
}

[data-kida-space-type] [data-kida-space-type-letter] {
  transform: rotateY(calc(var(--kida-space-type-index) * 360deg / var(--kida-space-type-count)))
    translateZ(var(--kida-space-type-row-radius)) rotateX(var(--kida-space-type-surface-tilt));
}

[data-kida-space-type] [data-kida-space-type-face] {
  position: absolute;
  top: calc(var(--kida-space-type-size) * -0.5);
  left: calc(var(--kida-space-type-size) * -0.4);
  width: calc(var(--kida-space-type-size) * 0.8);
  height: var(--kida-space-type-size);
  backface-visibility: hidden;
  font-family: var(--kida-space-type-font, "Helvetica Neue", "Segoe UI", sans-serif);
  font-size: var(--kida-space-type-size);
  font-weight: 200;
  line-height: 1;
  text-align: center;
  white-space: pre;
}

[data-kida-space-type] [data-kida-space-type-face="front"] {
  color: var(--kida-space-type-color);
  transform: translateZ(0.1px) scaleX(0.7);
}

[data-kida-space-type] [data-kida-space-type-face="back"] {
  color: color-mix(in srgb, var(--kida-space-type-color) 30%, var(--kida-space-type-background));
  transform: rotateY(180deg) translateZ(0.1px) scaleX(-0.7);
}

[data-kida-space-type] [data-kida-space-type-text] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@property --kida-space-type-phase {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}
src/lib/components/ui/kida/space-type.motion.ts
import { prefersReducedMotion, watchReducedMotion } from './reduced-motion.motion.js'

export { getSpaceTypeGeometry, type SpaceTypeGeometry } from './space-type-geometry.motion.js'

export interface SpaceTypeOptions {
  /** Rotation rate; zero freezes the current angle. @default 1 */
  speed?: number
  /** Pause without resetting the current angle. @default false */
  paused?: boolean
}

export interface SpaceTypeControls {
  setPlayback(options: SpaceTypeOptions): void
  destroy(): void
}

/** Shared loop lifecycle; adapters only render the geometry and update playback options. */
export function spaceType(root: HTMLElement, options: SpaceTypeOptions = {}): SpaceTypeControls {
  const ring = root.querySelector<HTMLElement>('[data-kida-space-type-ring]')
  let animation: Animation | undefined
  let visible = false
  let destroyed = false
  let speed = 1
  let paused = false

  const sync = () => {
    if (destroyed || !ring) return
    if (prefersReducedMotion()) {
      animation?.cancel()
      animation = undefined
      root.dataset.state = 'reduced'
      return
    }
    if (!animation) {
      animation = ring.animate(
        [
          { transform: 'rotateY(-90deg)', '--kida-space-type-phase': '0' },
          { transform: 'rotateY(270deg)', '--kida-space-type-phase': '1' },
        ],
        { duration: 24000, iterations: Number.POSITIVE_INFINITY, easing: 'linear' },
      )
      animation.pause()
    }
    if (animation.playbackRate !== speed) animation.updatePlaybackRate(speed)
    if (paused || speed === 0 || !visible || document.hidden) {
      animation.pause()
      root.dataset.state = 'paused'
    } else {
      animation.play()
      root.dataset.state = 'active'
    }
  }

  const setPlayback = (next: SpaceTypeOptions) => {
    speed = Number.isFinite(next.speed) ? Math.max(0, Math.min(3, next.speed ?? 1)) : 1
    paused = next.paused ?? false
    sync()
  }
  const observer = new IntersectionObserver(([entry]) => {
    visible = entry?.isIntersecting ?? false
    sync()
  })
  observer.observe(root)
  document.addEventListener('visibilitychange', sync)
  const unwatch = watchReducedMotion(sync)
  setPlayback(options)

  return {
    setPlayback,
    destroy() {
      destroyed = true
      observer.disconnect()
      document.removeEventListener('visibilitychange', sync)
      unwatch()
      animation?.cancel()
      animation = undefined
      root.dataset.state = 'idle'
    },
  }
}
src/lib/components/ui/kida/space-type-geometry.motion.ts
const TILT = (18 * Math.PI) / 180
const ROLL = (3 * Math.PI) / 180
const PROJECTION_ALLOWANCE = 1.1
const RADIUS_RESERVE = 0.88
const MAX_WAVE = 0.32

/** Bounds reserve the full longitude wave, so its strength never changes the base radius. */
export function getSpaceTypeGeometry(
  width: number,
  height: number,
  characterCount: number,
  rows: number,
  _longitude: number,
  requestedRadius?: number,
) {
  if (width <= 0 || height <= 0) return null

  rows = Number.isFinite(rows) ? Math.max(1, Math.min(6, Math.round(rows))) : 1
  const count = Math.max(1, characterCount)
  const inset = Math.max(8, width * 0.018)
  const halfWidth = Math.max(0, width / 2 - inset) / PROJECTION_ALLOWANCE
  const halfHeight = Math.max(0, height / 2 - inset) / PROJECTION_ALLOWANCE
  const radialX = Math.cos(ROLL)
  const stackX = Math.sin(ROLL)
  const radialY = Math.hypot(Math.cos(TILT) * Math.sin(ROLL), Math.sin(TILT))
  const stackY = Math.cos(TILT) * Math.cos(ROLL)

  const radiusLimit = (fontSize: number, tilted = false) => {
    // Tilting the glyph surface can project half its height into the radial plane.
    const glyphRadialExtent = fontSize * (tilted ? 0.9 : 0.4)
    const stackHalfHeight = fontSize * ((rows - 1) * 0.6 + 0.5)
    return Math.max(
      0,
      Math.min(
        (halfWidth - stackHalfHeight * stackX) / radialX - glyphRadialExtent,
        (halfHeight - stackHalfHeight * stackY) / radialY - glyphRadialExtent,
      ),
    )
  }

  // Size type against the resting ring, independently of radius and wave strength.
  let fontSize = Math.min(width * 0.09, (width * 3.5) / count, (width * 0.2) / rows)
  const nominalRadius = width * 0.34
  const initialRadius = Math.min(nominalRadius, radiusLimit(fontSize) * RADIUS_RESERVE)
  if (count > 1) {
    fontSize = Math.min(fontSize, (2 * initialRadius * Math.sin(Math.PI / count)) / 0.7)
  }

  const maxRadius = radiusLimit(fontSize, true) / (1 + MAX_WAVE)
  const defaultRadius = Math.min(nominalRadius, maxRadius * RADIUS_RESERVE)
  // Compact rings intentionally pack the same-sized letters more densely.
  const minRadius = Math.min(maxRadius, (width * 0.1) / (1 + MAX_WAVE))
  const radius = Math.max(
    minRadius,
    Math.min(
      maxRadius,
      typeof requestedRadius === 'number' && Number.isFinite(requestedRadius)
        ? requestedRadius
        : defaultRadius,
    ),
  )

  return {
    fontSize,
    radius,
    minRadius,
    maxRadius,
    perspective: Math.max(width, height) * 12,
  }
}

export type SpaceTypeGeometry = NonNullable<ReturnType<typeof getSpaceTypeGeometry>>
src/lib/components/ui/kida/reduced-motion.motion.ts
const QUERY = '(prefers-reduced-motion: reduce)'

/**
 * Whether the user has asked for reduced motion.
 *
 * SSR-safe: returns `false` when there is no `window`, matching the CSS default
 * (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;
 * this is for the JS-driven paths that CSS cannot express).
 */
export function prefersReducedMotion(): boolean {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false
  return window.matchMedia(QUERY).matches
}

/**
 * Subscribe to changes of the reduced-motion preference.
 * Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.
 */
export function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {
  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}

  const list = window.matchMedia(QUERY)
  const handler = (event: MediaQueryListEvent) => onChange(event.matches)
  list.addEventListener('change', handler)
  return () => list.removeEventListener('change', handler)
}
<script lang="ts">
import SpaceType from '$lib/components/ui/kida/space-type.svelte'
</script>

<SpaceType text="KIDA-UI / MADE-TO-MOVE / " rows={2} speed={0.75} />

Customization

Edit the phrase, change its colors, add rows with the number control, and adjust speed, radius, and longitude. Set speed to zero to pause. Smaller rings pack the same-sized letters closer; larger rings spread them out. Radius changes preserve the current rotation and font size.

Longitude makes the rings pulse inward and outward while the letters tilt to follow the cylinder’s changing surface. The wave travels along the rows and completes eight pulses per rotation. Its strength changes without changing the base radius, resizing the letters, or resetting playback. The radius range reserves room for maximum Longitude strength upfront, so its value and limits stay fixed as you adjust the wave. The range still adapts to the container, text, and rows to keep the animation inside its frame. Compact rings intentionally produce dense, overlapping typography, like a typographic sculpture.

API

Props

Prop Type Default Description
text string required Phrase rendered around each ring.
rows number 1 Number of rings, rounded and clamped to 1–6.
speed number 1 Rotation rate from 0–3×. One turn takes 24 seconds at 1×. Zero freezes the current angle.
paused boolean false Pause and resume without resetting rotation.
radius number auto Base radius in CSS pixels, clamped to the measured frame.
longitude number 0 Strength of the pulsing rings and tilting letter surface, clamped to 0–100.
color string CSS value Front text color. Back letters blend this with the background.
background string CSS value Ring surface color.
onGeometryChange (geometry: SpaceTypeGeometry | null) => void — Reports fitted fontSize, radius, minRadius, maxRadius, and perspective; null before measurement. Called in the browser only.
element HTMLDivElement | null null Use bind:element to read the root DOM element.

Native div attributes, class, style, and event handlers are passed to the root. Text, colors, radius, rows, and longitude update without restarting rotation.

CSS custom properties

Property Default Description
--kida-space-type-color #211c24 Front text color.
--kida-space-type-background #fffafb Surface color used to blend the back letters.
--kida-space-type-font Helvetica Neue, Segoe UI, sans-serif Thin display font.
--kida-space-type-height clamp(15rem, 40vw, 28rem) Preview frame height; changes trigger measurement.

Accessibility and input behavior

The authored phrase is exposed once to assistive technology. Repeated rows and front/back glyphs are decorative copies hidden from the accessibility tree. Use SpaceType as display typography alongside readable essential copy. The customization controls use native labeled inputs and buttons; the text input keeps the complete phrase editable and copyable.

Reduced motion keeps the ring static and preserves the authored phrase. Playback pauses off-screen and in hidden tabs. Observers, preference listeners, and animations are released on unmount.

Server markup is deterministic and contains the phrase before hydration. Geometry fits the container after hydration using ResizeObserver. Modern browsers with CSS 3D transforms, registered custom properties, trigonometric functions, and Web Animations are required for the complete effect.

Troubleshooting

Use short display phrases. Long phrases automatically use smaller letters. Radius changes never change their size. If a requested radius exceeds the frame, it is clamped; increase the container size or --kida-space-type-height to give the ring more room. Letter spacing is controlled by the circle’s radius and has no separate prop or control.