# Stars Background

A field of twinkling stars placed from a fixed seed, so every render looks the same. Best in dark mode.

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

## When to use

A night sky behind a launch hero, event countdown, or waitlist card, especially in dark mode.

- Set the background color, padding, and radius with class on the component
- Change seed to get a different but stable layout
- Keep count under 200 for cards and small sections

## Code

### Blade

Save at `resources/views/components/markas/stars-background.blade.php`. No extra dependencies.

```blade
@props([
    'count' => 80,
    'seed' => 7,
    'color' => 'primary',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0';
    $star = 'absolute rounded-full bg-current animate-[markas-twinkle_3s_ease-in-out_infinite] motion-reduce:animate-none';
    $content = 'relative';
    $colors = [
        'muted' => 'text-muted',
        'primary' => 'text-primary',
        'success' => 'text-success',
        'warning' => 'text-warning',
        'danger' => 'text-danger',
    ];
    $keyframes = '@keyframes markas-twinkle{50%{opacity:.15}}';

    // Park-Miller: hanya operasi bilangan bulat, jadi Blade, React, dan Vue menghasilkan bintang yang sama.
    $modulus = 2147483647;
    $multiplier = 48271;
    $maxStars = 400;

    $state = abs((int) $seed) % ($modulus - 1) + 1;
    $next = function () use (&$state, $modulus, $multiplier) {
        return $state = ($state * $multiplier) % $modulus;
    };
    $stars = [];
    $total = max(0, min((int) $count, $maxStars));
    for ($i = 0; $i < $total; $i++) {
        $size = $next() % 5 === 0 ? 2 : 1;
        $stars[] = 'left: '.(($next() % 10000) / 100).'%; top: '.(($next() % 10000) / 100).'%; width: '.$size.'px; height: '.$size.'px; opacity: '.((($next() % 6) + 4) / 10).'; animation-delay: '.(($next() % 30) * 100).'ms; animation-duration: '.(($next() % 3) + 2).'s';
    }
@endphp

<div {{ $attributes->class([$base]) }}>
    <style>{!! $keyframes !!}</style>
    <div aria-hidden="true" wire:ignore @class([$layer, $colors[$color] ?? $colors['primary']])>
        @foreach ($stars as $style)
            <span class="{{ $star }}" style="{{ $style }}"></span>
        @endforeach
    </div>
    <div class="{{ $content }}">{{ $slot }}</div>
</div>
```

```blade
<x-markas.stars-background :count="120" :seed="7" class="rounded-xl border border-line bg-surface px-6 py-12">
    <h2 class="text-2xl font-semibold text-ink">Deploys that ship while you sleep</h2>
    <x-markas.button>Get started</x-markas.button>
</x-markas.stars-background>
```

No JavaScript or Alpine.js needed.

### React

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

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

const base = "relative isolate overflow-hidden";
const layer = "pointer-events-none absolute inset-0";
const star =
  "absolute rounded-full bg-current animate-[markas-twinkle_3s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes = "@keyframes markas-twinkle{50%{opacity:.15}}";
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

/** Park-Miller: hanya operasi bilangan bulat, jadi Blade, React, dan Vue menghasilkan bintang yang sama. */
const MODULUS = 2147483647;
const MULTIPLIER = 48271;
const MAX_STARS = 400;

function makeStars(count: number, seed: number) {
  let state = (Math.abs(Math.trunc(seed)) % (MODULUS - 1)) + 1;
  const next = () => (state = (state * MULTIPLIER) % MODULUS);
  const total = Math.max(0, Math.min(Math.trunc(count), MAX_STARS));
  return Array.from({ length: total }, () => {
    const size = next() % 5 === 0 ? 2 : 1;
    return {
      left: `${(next() % 10000) / 100}%`,
      top: `${(next() % 10000) / 100}%`,
      width: `${size}px`,
      height: `${size}px`,
      opacity: ((next() % 6) + 4) / 10,
      animationDelay: `${(next() % 30) * 100}ms`,
      animationDuration: `${(next() % 3) + 2}s`,
    };
  });
}

export type StarsBackgroundProps = ComponentProps<"div"> & {
  count?: number;
  seed?: number;
  color?: keyof typeof colors;
};

export function StarsBackground({
  count = 80,
  seed = 7,
  color = "primary",
  className,
  children,
  ...props
}: StarsBackgroundProps) {
  return (
    <div {...props} className={cx(base, className)}>
      <style>{keyframes}</style>
      <div aria-hidden="true" className={cx(layer, colors[color])}>
        {makeStars(count, seed).map((style, index) => (
          <span key={index} className={star} style={style} />
        ))}
      </div>
      <div className={content}>{children}</div>
    </div>
  );
}
```

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

<StarsBackground
  count={120}
  seed={7}
  className="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 className="text-2xl font-semibold text-ink">
    Deploys that ship while you sleep
  </h2>
  <Button>Get started</Button>
</StarsBackground>;
```

### Vue

Save at `src/components/markas/StarsBackground.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";
const star =
  "absolute rounded-full bg-current animate-[markas-twinkle_3s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes = "@keyframes markas-twinkle{50%{opacity:.15}}";

/** Park-Miller: hanya operasi bilangan bulat, jadi Blade, React, dan Vue menghasilkan bintang yang sama. */
const MODULUS = 2147483647;
const MULTIPLIER = 48271;
const MAX_STARS = 400;

function makeStars(count: number, seed: number) {
  let state = (Math.abs(Math.trunc(seed)) % (MODULUS - 1)) + 1;
  const next = () => (state = (state * MULTIPLIER) % MODULUS);
  const total = Math.max(0, Math.min(Math.trunc(count), MAX_STARS));
  return Array.from({ length: total }, () => {
    const size = next() % 5 === 0 ? 2 : 1;
    return {
      left: `${(next() % 10000) / 100}%`,
      top: `${(next() % 10000) / 100}%`,
      width: `${size}px`,
      height: `${size}px`,
      opacity: ((next() % 6) + 4) / 10,
      animationDelay: `${(next() % 30) * 100}ms`,
      animationDuration: `${(next() % 3) + 2}s`,
    };
  });
}

const props = withDefaults(
  defineProps<{
    count?: number;
    seed?: number;
    color?: keyof typeof colors;
  }>(),
  { count: 80, seed: 7, color: "primary" },
);

const stars = computed(() => makeStars(props.count, props.seed));
</script>

<template>
  <div :class="base">
    <component :is="'style'">{{ keyframes }}</component>
    <div aria-hidden="true" :class="[layer, colors[props.color]]">
      <span
        v-for="(style, index) in stars"
        :key="index"
        :class="star"
        :style="style"
      />
    </div>
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <StarsBackground
    :count="120"
    :seed="7"
    class="rounded-xl border border-line bg-surface px-6 py-12"
  >
    <h2 class="text-2xl font-semibold text-ink">
      Deploys that ship while you sleep
    </h2>
    <Button>Get started</Button>
  </StarsBackground>
</template>
```

### Svelte

Save at `src/lib/components/markas/StarsBackground.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";
  const star =
    "absolute rounded-full bg-current animate-[markas-twinkle_3s_ease-in-out_infinite] motion-reduce:animate-none";
  const content = "relative";
  const colors = {
    muted: "text-muted",
    primary: "text-primary",
    success: "text-success",
    warning: "text-warning",
    danger: "text-danger",
  };
  const keyframes = "@keyframes markas-twinkle{50%{opacity:.15}}";

  /** Park-Miller: integer math only, so every framework draws the same stars. */
  const MODULUS = 2147483647;
  const MULTIPLIER = 48271;
  const MAX_STARS = 400;

  function makeStars(count: number, seed: number) {
    let state = (Math.abs(Math.trunc(seed)) % (MODULUS - 1)) + 1;
    const next = () => (state = (state * MULTIPLIER) % MODULUS);
    const total = Math.max(0, Math.min(Math.trunc(count), MAX_STARS));
    return Array.from({ length: total }, () => {
      const size = next() % 5 === 0 ? 2 : 1;
      const left = (next() % 10000) / 100;
      const top = (next() % 10000) / 100;
      const opacity = ((next() % 6) + 4) / 10;
      const delay = (next() % 30) * 100;
      const duration = (next() % 3) + 2;
      return `left: ${left}%; top: ${top}%; width: ${size}px; height: ${size}px; opacity: ${opacity}; animation-delay: ${delay}ms; animation-duration: ${duration}s`;
    });
  }

  type Props = HTMLAttributes<HTMLDivElement> & {
    count?: number;
    seed?: number;
    color?: keyof typeof colors;
    children?: Snippet;
  };

  let {
    count = 80,
    seed = 7,
    color = "primary",
    class: className,
    children,
    ...rest
  }: Props = $props();

  const items = $derived(makeStars(count, seed));
</script>

<div {...rest} class={[base, className]}>
  {@html `<style>${keyframes}</style>`}
  <div aria-hidden="true" class={[layer, colors[color]]}>
    {#each items as style, index (index)}
      <span class={star} {style}></span>
    {/each}
  </div>
  <div class={content}>{@render children?.()}</div>
</div>
```

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

<StarsBackground
  count={120}
  seed={7}
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Deploys that ship while you sleep
  </h2>
  <Button>Get started</Button>
</StarsBackground>
```

### Astro

Save at `src/components/markas/StarsBackground.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";
const star =
  "absolute rounded-full bg-current animate-[markas-twinkle_3s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes = "@keyframes markas-twinkle{50%{opacity:.15}}";

/** Park-Miller: integer math only, so every framework draws the same stars. */
const MODULUS = 2147483647;
const MULTIPLIER = 48271;
const MAX_STARS = 400;

function makeStars(count: number, seed: number) {
  let state = (Math.abs(Math.trunc(seed)) % (MODULUS - 1)) + 1;
  const next = () => (state = (state * MULTIPLIER) % MODULUS);
  const total = Math.max(0, Math.min(Math.trunc(count), MAX_STARS));
  return Array.from({ length: total }, () => {
    const size = next() % 5 === 0 ? 2 : 1;
    return {
      left: `${(next() % 10000) / 100}%`,
      top: `${(next() % 10000) / 100}%`,
      width: `${size}px`,
      height: `${size}px`,
      opacity: ((next() % 6) + 4) / 10,
      animationDelay: `${(next() % 30) * 100}ms`,
      animationDuration: `${(next() % 3) + 2}s`,
    };
  });
}

type Props = HTMLAttributes<"div"> & {
  count?: number;
  seed?: number;
  color?: keyof typeof colors;
};

const {
  count = 80,
  seed = 7,
  color = "primary",
  class: className,
  ...rest
} = Astro.props;
---

<div {...rest} class:list={[base, className]}>
  <style is:inline set:html={keyframes} />
  <div aria-hidden="true" class:list={[layer, colors[color]]}>
    {makeStars(count, seed).map((style) => <span class={star} style={style} />)}
  </div>
  <div class={content}><slot /></div>
</div>
```

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

<StarsBackground
  count={120}
  seed={7}
  class="rounded-xl border border-line bg-surface px-6 py-12"
>
  <h2 class="text-2xl font-semibold text-ink">
    Deploys that ship while you sleep
  </h2>
  <Button>Get started</Button>
</StarsBackground>
```

### Angular

Save at `src/app/markas/stars-background.component.ts`. No extra dependencies.

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

const base = "relative isolate overflow-hidden";
const layer = "pointer-events-none absolute inset-0";
const star =
  "absolute rounded-full bg-current animate-[markas-twinkle_3s_ease-in-out_infinite] motion-reduce:animate-none";
const content = "relative";
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const keyframes = "@keyframes markas-twinkle{50%{opacity:.15}}";

/** Park-Miller: integer math only, so every framework draws the same stars. */
const MODULUS = 2147483647;
const MULTIPLIER = 48271;
const MAX_STARS = 400;

export type StarsBackgroundColor = keyof typeof colors;

function makeStars(count: number, seed: number) {
  let state = (Math.abs(Math.trunc(seed)) % (MODULUS - 1)) + 1;
  const next = () => (state = (state * MULTIPLIER) % MODULUS);
  const total = Math.max(0, Math.min(Math.trunc(count), MAX_STARS));
  return Array.from({ length: total }, () => {
    const size = next() % 5 === 0 ? 2 : 1;
    const left = (next() % 10000) / 100;
    const top = (next() % 10000) / 100;
    const opacity = ((next() % 6) + 4) / 10;
    const delay = (next() % 30) * 100;
    const duration = (next() % 3) + 2;
    return `left: ${left}%; top: ${top}%; width: ${size}px; height: ${size}px; opacity: ${opacity}; animation-delay: ${delay}ms; animation-duration: ${duration}s`;
  });
}

/**
 * Attribute selector on the native root div: the user's class and attributes stay on it.
 * The keyframes are a global style, so encapsulation is off.
 */
@Component({
  selector: "div[markas-stars-background]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  styles: [keyframes],
  host: { "[class]": "base" },
  template: `
    <div aria-hidden="true" [class]="layerClasses()">
      @for (style of items(); track $index) {
        <span [class]="star" [style]="style"></span>
      }
    </div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class StarsBackground {
  readonly count = input(80, { transform: numberAttribute });
  readonly seed = input(7, { transform: numberAttribute });
  readonly color = input<StarsBackgroundColor>("primary");

  protected readonly base = base;
  protected readonly star = star;
  protected readonly content = content;
  protected readonly layerClasses = computed(
    () => `${layer} ${colors[this.color()]}`,
  );
  protected readonly items = computed(() =>
    makeStars(this.count(), this.seed()),
  );
}
```

```ts
import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { StarsBackground } from "./markas/stars-background.component";

@Component({
  selector: "app-launch",
  imports: [Button, StarsBackground],
  template: `
    <div
      markas-stars-background
      count="120"
      seed="7"
      class="rounded-xl border border-line bg-surface px-6 py-12"
    >
      <h2 class="text-2xl font-semibold text-ink">
        Deploys that ship while you sleep
      </h2>
      <button markas-button>Get started</button>
    </div>
  `,
})
export class Launch {}
```

Angular uses an attribute selector on the native div, so `class`, `aria-*`, and other attributes stay on the root element.

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `count` | `number` | 80 | Number of stars, up to 400. More stars make a denser sky. |
| `seed` | `number` | 7 | Whole number that decides star positions. The same seed always gives the same sky. |
| `color` | `muted \| primary \| success \| warning \| danger` | primary | Token color of the stars. |
| `children / slot` | `slot / ReactNode` | - | Content shown on top of the stars. |

## Accessibility

- The star layer is aria-hidden and ignores pointer events.
- With reduced motion, stars stop twinkling and keep their own brightness.

## Notes

- Star positions come from `seed` with integer math, so all six frameworks render the same sky on the server and client.
- Add the `dark` class to keep a section dark in every theme. With reduced motion the stars stop twinkling.
- The component has no built-in text, so there are no label props to translate.
