Vilqor

Floating Glass Navbar

Navigation

About

A header that is open at the top of the page and gathers into a floating glass island once you scroll. A lit pill follows your pointer, then the section you are reading. Part of Midnight, the full template on 21st; also in the free Midnight Lite (MIT).

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Floating Glass Navbar to your project and fits it to your theme.

Code

How Floating Glass Navbar is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { useSyncExternalStore, type CSSProperties } from "react"

import { IslandHeader } from "@/components/ui/island-header"

const fonts =
  "@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght,SOFT@0,9..144,300..600,0..100;1,9..144,300..600,0..100&family=Geist:wght@400..600&display=swap');"

// Midnight by day: warm paper, white cards, night-blue ink, deep gold for the button and one word
const settings = {
  brand: "Midnight",
  background: "#f7f5f0",
  card: "#ffffff",
  text: "#141a2e",
  muted: "#4a5166",
  accent: "#a8803a",
  accentText: "#ffffff",
}

// Midnight by night, the template's own palette
const night: Partial<typeof settings> = {
  background: "#0b1020",
  card: "#111731",
  text: "#ece9e1",
  muted: "#a9afc4",
  accent: "#d9b77e",
  accentText: "#0b1020",
}

// 21st marks its dark theme with .dark on <html>; the demo answers with Midnight by night
function useDark() {
  return useSyncExternalStore(
    (on) => {
      const watch = new MutationObserver(on)
      watch.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] })
      return () => watch.disconnect()
    },
    () => document.documentElement.classList.contains("dark"),
    () => false,
  )
}

// the palette as theme tokens; the component itself only reads the tokens
function tokens(s: typeof settings) {
  const t: Record<string, string> = {
    background: s.background,
    foreground: s.text,
    card: s.card,
    primary: s.accent,
    "primary-foreground": s.accentText,
    "muted-foreground": s.muted,
    ring: s.accent,
  }
  return Object.fromEntries(Object.entries(t).flatMap(([k, v]) => [[`--${k}`, v], [`--color-${k}`, v]])) as CSSProperties
}

const serif = { fontFamily: "Fraunces, ui-serif, Georgia, serif", fontWeight: 340, fontVariationSettings: '"SOFT" 60, "opsz" 144' }

export default function Demo(props: Partial<typeof settings>) {
  const dark = useDark()
  const s = { ...settings, ...props, ...(dark ? night : {}) }
  const card: CSSProperties = dark
    ? { background: `color-mix(in oklab, ${s.card} 70%, ${s.background})`, boxShadow: "inset 0 1px 0 0 rgb(255 255 255 / 0.07)" }
    : { background: s.card, boxShadow: "inset 0 0 0 1px rgb(20 26 46 / 0.07), 0 1px 2px rgb(20 26 46 / 0.05), 0 16px 32px -20px rgb(20 26 46 / 0.22)" }
  return (
    <div
      className="min-h-svh w-full"
      style={{ ...tokens(s), "--font-display": "Fraunces, ui-serif, Georgia, serif", fontFamily: "Geist, ui-sans-serif, system-ui, sans-serif", background: s.background, color: s.text } as CSSProperties}
    >
      <style>{fonts}</style>
      <IslandHeader
        brand={s.brand}
        nav={[
          { label: "Product", href: "#product" },
          { label: "Pricing", href: "#pricing" },
          { label: "Get started", href: "#start" },
        ]}
        link={{ label: "Docs", href: "#" }}
        cta={{ label: "Start free", short: "Start", href: "#start" }}
      />
      <section id="top" className="flex min-h-[78svh] flex-col items-center justify-center px-6 pt-24 text-center">
        <h1 className="text-[clamp(44px,8vw,96px)] leading-[0.98] tracking-[-0.03em]" style={serif}>
          Scroll to see
          <br />
          <em style={{ color: s.accent }}>the island.</em>
        </h1>
        <p className="mt-6 max-w-[460px] text-[17px] leading-7" style={{ color: s.muted }}>
          The bar gathers into a floating glass pill. The lit pill follows your pointer, then the section you are reading.
        </p>
      </section>
      {[
        { id: "product", title: "Product" },
        { id: "pricing", title: "Pricing" },
        { id: "start", title: "Get started" },
      ].map((sec) => (
        <section key={sec.id} id={sec.id} className="mx-auto flex min-h-[70svh] max-w-[1000px] items-center px-6">
          <div className="w-full rounded-[32px] px-8 py-16" style={card}>
            <h2 className="text-[clamp(32px,4.6vw,56px)] leading-[1.02] tracking-[-0.02em]" style={serif}>
              {sec.title}
            </h2>
          </div>
        </section>
      ))}
    </div>
  )
}

Dependencies

More by Vilqor

View all
  • 3D Glass Cube Hero

    3D Glass Cube Hero

    210
  • Footer with Big Wordmark

    Footer with Big Wordmark

    163
  • Guilloche Background Pattern

    Guilloche Background Pattern

    8
  • Card Carousel to Grid

    Card Carousel to Grid

  • AI Email Reply with Tones

    AI Email Reply with Tones

  • AI Memory Timeline

    AI Memory Timeline

  • Use Cases Tabs Section

    Use Cases Tabs Section

  • Pricing Section with Toggle

    Pricing Section with Toggle

More in Navigation

View all
  • Liquid Glass Expandable Sidebar

    Liquid Glass Expandable Sidebar

    427
  • Meniscus — Liquid Bottom Navigation Bar

    Meniscus — Liquid Bottom Navigation Bar

    27
  • Sidebar

    Sidebar

    441
  • Tabs

    Tabs

    38
  • Footer Section

    Footer Section

    2
  • Sidebar

    Sidebar

    366
  • Pagination

    Pagination

    119
  • Pagination with Ellipsis

    Pagination with Ellipsis

    31