StealThis .dev
Patterns Medium

Theme Transition

Dark/light theme toggle with circular clip-path wipe powered by the View Transitions API.

Open in Lab
view-transitions-apiclip-path
Targets: JS HTML

Code

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Theme tokens ── */
[data-theme="dark"] {
  --bg: #070a12;
  --bg-elevated: #121a2b;
  --border: #263249;
  --text: #f0f4fb;
  --text-secondary: #8a95a8;
  --accent: #86e8ff;
  --secondary: #ae52ff;
  --tertiary: #ff40d6;
  --code-bg: rgba(134, 232, 255, 0.1);
  --code-color: #86e8ff;
  --card-shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-elevated: #ffffff;
  --border: #dce3ed;
  --text: #1a1f2e;
  --text-secondary: #5a6478;
  --accent: #0077cc;
  --secondary: #7c3aed;
  --tertiary: #db2777;
  --code-bg: rgba(0, 119, 204, 0.08);
  --code-color: #0077cc;
  --card-shadow: rgba(0, 0, 0, 0.06);
}

html {
  font-family: 'Inter', 'SF Pro Display', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: none; /* transitions handled by View Transitions API */
}

/* ── Page ── */
.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 5rem 2rem 4rem;
}

.header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.eyebrow {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  margin-bottom: 1rem;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  color: var(--text-secondary);
  max-width: 500px;
  margin: 0.75rem auto 0;
  line-height: 1.6;
}

/* ── Toggle button ── */
.toggle-area {
  display: flex;
  justify-content: center;
  margin-bottom: 3rem;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: 600 0.85rem/1 'Inter', system-ui, sans-serif;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.1);
}

.toggle-icon {
  display: flex;
  align-items: center;
  color: var(--accent);
}

[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }

/* ── Cards ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.demo-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 2px 12px var(--card-shadow);
}

.card-header {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot-color);
}

.demo-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.demo-card p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

code {
  background: var(--code-bg);
  color: var(--code-color);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* ── Sample text ── */
.sample-text {
  margin-bottom: 2.5rem;
}

.sample-text h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}

.sample-text p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 1rem;
}

/* ── Back button ── */
.btn-back {
  display: inline-block;
  padding: 0.7rem 2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  font: 600 0.85rem/1 'Inter', system-ui, sans-serif;
  transition: border-color 0.25s, background 0.25s;
}

.btn-back:hover {
  background: var(--bg-elevated);
  border-color: var(--accent);
}

/* ══════════════════════════════════════════
   View Transition: Circular clip-path wipe
   ══════════════════════════════════════════ */

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* Old snapshot fades, new snapshot clips in */
::view-transition-old(root) {
  z-index: 1;
}

::view-transition-new(root) {
  z-index: 9999;
  animation: clip-reveal 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes clip-reveal {
  from {
    clip-path: circle(0% at var(--click-x, 50%) var(--click-y, 50%));
  }
  to {
    clip-path: circle(150% at var(--click-x, 50%) var(--click-y, 50%));
  }
}

/* ── Fallback for no View Transitions ── */
.no-vt body {
  transition: background 0.3s ease, color 0.3s ease;
}

@media (max-width: 640px) {
  .page { padding: 3rem 1rem 3rem; }
  .card-grid { grid-template-columns: 1fr; }
}

Theme Transition

Dark/light theme toggle with circular clip-path wipe powered by the View Transitions API.

Source

  • Repository: libs-genclaude
  • Original demo id: 13-theme-transition

Notes

Dark/light theme toggle with circular clip-path wipe powered by the View Transitions API.