Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

feat: move Text Gradient Animation to the guided-steps page

matin83f13c05ffaf
diff --git a/animations/05-text-typography/text-gradient-animation/README.md b/animations/05-text-typography/text-gradient-animation/README.md
index e68d6245..8c49731e 100644
--- a/animations/05-text-typography/text-gradient-animation/README.md
+++ b/animations/05-text-typography/text-gradient-animation/README.md
@@ -1,7 +1,7 @@
# Text Gradient Animation
## What it is
-Text gradient animation flows color through the characters of a text element. The two required CSS properties are `background-clip: text` and `color: transparent` — these expose the element's background image through the character shapes. Animating `background-position` then moves the gradient behind the stationary text, creating the appearance of color flowing through the letters. The text itself never moves.
+Text gradient animation fills the letters with a gradient instead of a flat color, then moves the gradient behind them, so color seems to flow through the word while the letters stay still. The trick is to paint the gradient as the text's background, show that background only inside the letter shapes, and make the text color itself see-through.
## When to use it
- Display headlines on creative, tech, and brand sites
@@ -33,20 +33,17 @@ Two CSS properties expose the background through text shapes, then a keyframe an
The `background-size: 300%` makes the gradient wider than the element, so scrolling `background-position` shows different color sections. The last color stop matches the first, creating a seamless loop.
-For a conic gradient (rotating color wheel):
+For a gradient that turns like a color wheel, register an angle property so the browser can animate the conic gradient's starting angle:
```css
+@property --ang { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
+
.conic-text {
- background-image: conic-gradient(from 0deg, #58a6ff, #56d364, #d2a8ff, #ffa657, #58a6ff);
- background-size: 200% 200%;
- background-position: 50% 50%;
+ background-image: conic-gradient(from var(--ang), #58a6ff, #56d364, #d2a8ff, #ffa657, #58a6ff);
animation: spin 4s linear infinite;
}
-@keyframes spin {
- from { background-position: 0% 0%; }
- to { background-position: 100% 100%; }
-}
+@keyframes spin { to { --ang: 360deg; } }
```
For live JavaScript control (e.g., mouse position driving gradient angle):
@@ -58,10 +55,11 @@ el.style.backgroundImage = `linear-gradient(${angle}deg, ${c1}, ${c2})`;
## Key parameters
| Parameter | Default | Effect |
|-----------|---------|--------|
-| Animation duration | 4s | Slower = more subtle and ambient; faster = more energetic |
-| `background-size` | 300% | Larger = wider gradient, softer transitions; smaller = more color change per pixel |
-| Color stops | 4–5 | More stops = richer; repeat first stop at end to loop seamlessly |
-| Gradient type | Linear | Conic creates a rotation effect; radial creates a pulsing center |
+| Gradient | Flowing | Flowing slides the colors sideways, Spinning turns them like a color wheel, Diagonal slides slanted bands, Two colors flows between two colors of your choice |
+| Speed | Normal | How long one full pass takes: slow is 6.4s, normal 4s and fast 2.4s; slower feels calm, faster feels lively |
+| First color | Blue | With Two colors, the color the gradient starts and ends with |
+| Second color | Purple | With Two colors, the color in the middle |
+| Your text | Flow | The text the colors flow through |
## Production notes
- **`-webkit-background-clip: text`**: the non-prefixed `background-clip: text` is now widely supported (Chrome 119+, Firefox 122+, Safari 14+), but the `-webkit-` prefix is still required for Safari compatibility across all versions. Include both.
@@ -71,6 +69,6 @@ el.style.backgroundImage = `linear-gradient(${angle}deg, ${c1}, ${c2})`;
- **Selection color**: selected text with `color: transparent` may render without a visible selection highlight in some browsers. Test selection behavior and add `::selection { color: white; background: blue; }` if needed.
## See also
-- [Variable Font Morph](../variable-font-morph/) — another CSS-only text animation, morphing font axes rather than color
-- [Outline to Fill](../outline-to-fill/) — color appearing inside text characters via a different mechanism (clip-path reveal)
-- [Kinetic Typography](../kinetic-typography/) — gradient text as one technique within a broader motion sequence
+- [Variable Font Morph](../variable-font-morph/) — the letters themselves change weight and lean
+- [Outline to Fill](../outline-to-fill/) — hollow letters fill with color
+- [Kinetic Typography](../kinetic-typography/) — words that each move in their own way
diff --git a/animations/05-text-typography/text-gradient-animation/index.html b/animations/05-text-typography/text-gradient-animation/index.html
index 7f09c2dd..f1b11643 100644
--- a/animations/05-text-typography/text-gradient-animation/index.html
+++ b/animations/05-text-typography/text-gradient-animation/index.html
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Gradient Animation — Animation Handbook</title>
- <meta name="description" content="background-clip: text + animated background-position flows color through the characters.">
+ <meta name="description" content="Colors flow through the letters while the text stays still. Best for headlines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/text-gradient-animation/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
@@ -12,32 +12,21 @@
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Text Gradient Animation — Animation Handbook">
- <meta property="og:description" content="background-clip: text + animated background-position flows color through the characters.">
+ <meta property="og:description" content="Colors flow through the letters while the text stays still. Best for headlines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/text-gradient-animation/">
<meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Text Gradient Animation — Animation Handbook">
- <meta name="twitter:description" content="background-clip: text + animated background-position flows color through the characters.">
+ <meta name="twitter:description" content="Colors flow through the letters while the text stays still. Best for headlines.">
<meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Text Gradient Animation", "name": "Text Gradient Animation", "description": "background-clip: text + animated background-position flows color through the characters.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/text-gradient-animation/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Text Gradient Animation"}</script>
+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Text Gradient Animation", "name": "Text Gradient Animation", "description": "Colors flow through the letters while the text stays still. Best for headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/text-gradient-animation/", "inLanguage": "en", "articleSection": "Text & Typography", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Text & Typography, Text Gradient Animation"}</script>
<style>
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}
- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}
- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}
- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}
- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#ff6f8b;--ui-text:#f4f4f2;--ui-muted:#77777e;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace;--stage-h:620px;--grad-dur:4s;--grad-size:120px}
+ :root{--ui-accent:#ff6f8b;--grad-dur:4s;--c1:#58a6ff;--c2:#d2a8ff}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}
- header{margin-bottom:20px}
- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}
- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}
- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}
- .stage{flex:1;min-width:0;min-height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#08080a;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:32px;padding:32px}
- /* Gradient text base */
+ .stage{display:flex;align-items:center;justify-content:center;background:#08080a;padding:clamp(24px,4vw,48px)}
.grad-text{
- font-family:Georgia,'Times New Roman',serif;
- font-size:var(--grad-size);
- font-style:italic;
+ font-weight:800;
+ font-size:clamp(64px,14vw,120px);
line-height:1;
letter-spacing:-0.02em;
background-clip:text;
@@ -62,113 +51,164 @@
/* Multi-stop */
.grad-multi{background-image:linear-gradient(135deg,#f85149,#ffa657,#56d364,#58a6ff,#d2a8ff,#f85149)}
/* Custom two-color */
- .grad-custom{background-image:linear-gradient(90deg,var(--c1,#58a6ff),var(--c2,#d2a8ff),var(--c1,#58a6ff))}
+ .grad-custom{background-image:linear-gradient(90deg,var(--c1),var(--c2),var(--c1))}
@keyframes grad-flow{from{background-position:0% 50%}to{background-position:300% 50%}}
@keyframes grad-spin{from{--ang:0deg}to{--ang:360deg}}
- .grad-label{font-size:10px;letter-spacing:3px;text-transform:uppercase;color:var(--ui-muted)}
- /* Panel */
- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}
- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}
- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}
- .div{height:1px;background:var(--ui-border)}
- .sr{display:flex;align-items:center;gap:6px;font-size:10px}
- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}
- .sv{width:44px;text-align:right;color:var(--ui-text)}
- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}
- input[type=text]{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:11px;padding:8px 10px;border-radius:4px;width:100%;min-height:44px;outline:none}
- input[type=text]:focus{border-color:var(--ui-accent)}
- .color-row{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--ui-muted)}
- input[type=color]{border:none;background:none;width:44px;height:44px;cursor:pointer;border-radius:4px;padding:0;flex-shrink:0}
- @media(max-width:600px){.layout{flex-direction:column}aside{width:100%}:root{--stage-h:auto}.stage{width:100%;height:auto;min-height:400px}:root{--grad-size:64px}}
- @media(prefers-reduced-motion:reduce){.grad-text{animation:none!important}.grad-text:not(.grad-conic){background-position:0% 50%!important}}
</style>
-<style id="ah-inject">
-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}
-body{padding-top:46px}
-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}
-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}
-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}
-.ah-home{color:var(--ah-ink);font-weight:600}
-.ah-actions{display:flex;align-items:center;gap:2px}
-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}
-.ah-copied{color:var(--ah-accent)!important}
-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}
-@media print{.ah-bar{display:none}body{padding-top:0}}
-</style>
+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=3">
+ <script src="../../../assets/js/demo-page.js?v=3" defer></script>
</head>
-<body>
-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../text-morphing/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../outline-to-fill/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/05-text-typography/text-gradient-animation/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>
-<header>
- <h1>Text Gradient Animation</h1>
- <p>background-clip: text + animated background-position flows color through the characters.</p>
-</header>
-<div class="layout">
- <div class="stage">
- <div class="grad-label">Gradient</div>
- <div class="grad-text grad-linear" id="grad-text">Flow</div>
- <div class="grad-label" style="opacity:.4;font-size:9px">background-clip: text · color: transparent</div>
- </div>
- <aside>
- <p class="note">The text never animates — only the gradient behind it moves. background-clip: text + color: transparent exposes the background through character shapes.</p>
- <div class="lbl">Gradient Type</div>
- <select id="type-sel">
- <option value="grad-linear" selected>Linear flow</option>
- <option value="grad-conic">Conic rotation</option>
- <option value="grad-multi">Multi-stop 135°</option>
- <option value="grad-custom">Two-color custom</option>
- </select>
- <div class="lbl">Speed</div>
- <div class="sr"><input type="range" id="spd-sl" min="10" max="100" value="40" step="5"><span class="sv" id="spd-v">4.0s</span></div>
- <div class="lbl">Font Size</div>
- <div class="sr"><input type="range" id="size-sl" min="32" max="160" value="120" step="8"><span class="sv" id="size-v">120px</span></div>
- <div class="lbl">Custom Colors</div>
- <div class="color-row">
- <span>Start</span>
- <input type="color" id="c1-pick" value="#58a6ff" aria-label="Start color">
- <span>End</span>
- <input type="color" id="c2-pick" value="#d2a8ff" aria-label="End color">
+<body class="hb" data-hb-kind="loop">
+<nav class="hb-bar" aria-label="Animation Handbook">
+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
+ <span class="hb-pager"><a href="../text-morphing/" rel="prev" aria-label="Previous: Text Morphing"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Text Morphing</span></a><a href="../outline-to-fill/" rel="next" aria-label="Next: Outline to Fill"><span><span class="hb-dir">Next: </span>Outline to Fill</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
+</nav>
+<main class="hb-page">
+ <header class="hb-head">
+ <p class="hb-cat">05.08 · Text &amp; Typography</p>
+ <h1>Text Gradient Animation</h1>
+ <p class="hb-lede">Colors flow through the letters while the text stays still. Best for headlines.</p>
+ </header>
+
+ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">1</span>
+ <div><h2 id="hb-watch-title">Watch it</h2><p>It moves by itself. Pause it to look closely, or turn on slow motion to see each part of the movement.</p></div>
+ </div>
+ <div class="stage hb-dots hb-grow">
+ <div class="grad-text grad-linear" id="grad-text">Flow</div>
+ </div>
+ <div class="hb-player">
+ <button class="hb-play" type="button" id="btn-pause" data-hb-pause="css" data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>
+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo="css" autocomplete="off"><span>Slow motion</span></label>
+ </div>
+ </section>
+
+ <section class="hb-step hb-try" aria-labelledby="hb-try-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">2</span>
+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting and see the difference as it moves.</p></div>
+ </div>
+ <div class="hb-settings">
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="grad-lbl">Gradient</p>
+ <div class="seg" id="grad-seg" role="group" aria-labelledby="grad-lbl">
+ <button type="button" data-cls="grad-linear" class="on" aria-pressed="true">Flowing</button>
+ <button type="button" data-cls="grad-conic" aria-pressed="false">Spinning</button>
+ <button type="button" data-cls="grad-multi" aria-pressed="false">Diagonal</button>
+ <button type="button" data-cls="grad-custom" aria-pressed="false">Two colors</button>
+ </div>
+ <p class="hb-hint">How the colors move through the letters.</p>
+ </div>
+ <div class="hb-setting">
+ <p class="hb-setting-name" id="speed-lbl">Speed</p>
+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
+ <button type="button" data-dur="6.4s" aria-pressed="false">Slow</button>
+ <button type="button" data-dur="4s" class="on" aria-pressed="true">Normal</button>
+ <button type="button" data-dur="2.4s" aria-pressed="false">Fast</button>
+ </div>
+ <p class="hb-hint">Slower feels calm; faster feels lively.</p>
+ </div>
+ </div>
+ <details class="hb-options">
+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
+ <div class="hb-settings">
+ <div class="hb-setting" id="c1-setting" hidden>
+ <p class="hb-setting-name" id="c1-lbl">First color</p>
+ <div class="swatches" id="c1-sw" role="group" aria-labelledby="c1-lbl">
+ <button type="button" aria-pressed="false" aria-label="Pink" data-c="#ff6f8b" style="background:#ff6f8b"></button>
+ <button type="button" aria-pressed="false" aria-label="White" data-c="#f4f4f2" style="background:#f4f4f2"></button>
+ <button type="button" class="on" aria-pressed="true" aria-label="Blue" data-c="#58a6ff" style="background:#58a6ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Purple" data-c="#d2a8ff" style="background:#d2a8ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Green" data-c="#56d364" style="background:#56d364"></button>
+ <button type="button" aria-pressed="false" aria-label="Orange" data-c="#ffa657" style="background:#ffa657"></button>
+ </div>
+ <p class="hb-hint">The color the gradient starts and ends with.</p>
+ </div>
+ <div class="hb-setting" id="c2-setting" hidden>
+ <p class="hb-setting-name" id="c2-lbl">Second color</p>
+ <div class="swatches" id="c2-sw" role="group" aria-labelledby="c2-lbl">
+ <button type="button" aria-pressed="false" aria-label="Pink" data-c="#ff6f8b" style="background:#ff6f8b"></button>
+ <button type="button" aria-pressed="false" aria-label="White" data-c="#f4f4f2" style="background:#f4f4f2"></button>
+ <button type="button" aria-pressed="false" aria-label="Blue" data-c="#58a6ff" style="background:#58a6ff"></button>
+ <button type="button" class="on" aria-pressed="true" aria-label="Purple" data-c="#d2a8ff" style="background:#d2a8ff"></button>
+ <button type="button" aria-pressed="false" aria-label="Green" data-c="#56d364" style="background:#56d364"></button>
+ <button type="button" aria-pressed="false" aria-label="Orange" data-c="#ffa657" style="background:#ffa657"></button>
+ </div>
+ <p class="hb-hint">The color in the middle of the gradient.</p>
+ </div>
+ <div class="hb-setting">
+ <label class="hb-setting-name" for="text-inp">Your text</label>
+ <input class="hb-text" type="text" id="text-inp" value="Flow" autocomplete="off">
+ <p class="hb-hint">Short words show the flow best.</p>
+ </div>
+ </div>
+ </details>
+ </section>
+
+ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
+ <div class="hb-step-head">
+ <span class="hb-num" aria-hidden="true">3</span>
+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
+ </div>
+ <div class="hb-card">
+ <p class="hb-prompt">Add a flowing color gradient to [your headline or logo text]. Fill the letters with a gradient instead of a flat color: paint the gradient as the text's background, show it only inside the letter shapes, and make the text color itself see-through. Then keep moving the gradient behind the letters, or turn it like a color wheel, so color flows through the word while the letters stay still. End the gradient with the color it starts with so the loop has no seam. Give the text a solid fallback color for browsers that cannot clip a background to text. If the visitor has reduced motion turned on, keep the gradient still. Match the settings listed below.</p>
+ <div class="hb-chips-box" hidden>
+ <p class="hb-chips-title">Your settings</p>
+ <ul class="hb-chips"></ul>
+ </div>
+ <div class="hb-copy-row">
+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
+ </div>
</div>
- <div class="div"></div>
- <div class="lbl">Text</div>
- <input type="text" id="text-inp" value="Flow">
- </aside>
-</div>
+ </section>
+
+ <section class="hb-about" aria-labelledby="hb-what-title">
+ <div class="hb-what">
+ <h2 id="hb-what-title">What it is</h2>
+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
+ </div>
+ <div class="hb-fit">
+ <h2>Good for</h2>
+ <ul class="hb-tags hb-good"><li>Headlines</li><li>Logos</li><li>Hero titles</li></ul>
+ <h3>Avoid on</h3>
+ <ul class="hb-tags hb-avoid"><li>Body text</li><li>Small text</li></ul>
+ </div>
+ </section>
+
+ <section class="hb-related" aria-labelledby="hb-related-title" hidden>
+ <h2 id="hb-related-title">Similar animations</h2>
+ <div class="hb-rel-list"></div>
+ </section>
+</main>
+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer>
<script>
const gradText=document.getElementById('grad-text');
+ const vars=document.documentElement.style;
+ const txtIn=document.getElementById('text-inp');
+ const c1Setting=document.getElementById('c1-setting'),c2Setting=document.getElementById('c2-setting');
const CLASSES=['grad-linear','grad-conic','grad-multi','grad-custom'];
- document.getElementById('type-sel').addEventListener('change',e=>{
+ function choices(id,pick){
+ const buttons=document.querySelectorAll('#'+id+' button');
+ buttons.forEach(b=>b.addEventListener('click',()=>{
+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
+ pick(b.dataset);
+ }));
+ }
+ // Gradient: swaps the gradient class, and shows First/Second color only for the two-color custom gradient
+ choices('grad-seg',d=>{
gradText.classList.remove(...CLASSES);
- gradText.classList.add(e.target.value);
- });
- document.getElementById('spd-sl').addEventListener('input',e=>{
- const v=e.target.value/10;
- document.getElementById('spd-v').textContent=v.toFixed(1)+'s';
- document.documentElement.style.setProperty('--grad-dur',v+'s');
- });
- const sizeSl=document.getElementById('size-sl');
- sizeSl.addEventListener('input',e=>{
- document.getElementById('size-v').textContent=e.target.value+'px';
- document.documentElement.style.setProperty('--grad-size',e.target.value+'px');
- });
- // The mobile media query shrinks --grad-size; keep the slider and readout in sync with it,
- // including when the viewport crosses the breakpoint after load (rotation, resize).
- const syncSize=()=>{
- sizeSl.value=parseInt(getComputedStyle(gradText).fontSize,10);
- document.getElementById('size-v').textContent=sizeSl.value+'px';
- };
- syncSize();
- matchMedia('(max-width:600px)').addEventListener('change',syncSize);
- document.getElementById('text-inp').addEventListener('input',e=>{
- gradText.textContent=e.target.value||'Flow';
- });
- document.getElementById('c1-pick').addEventListener('input',e=>{
- document.documentElement.style.setProperty('--c1',e.target.value);
- });
- document.getElementById('c2-pick').addEventListener('input',e=>{
- document.documentElement.style.setProperty('--c2',e.target.value);
+ gradText.classList.add(d.cls);
+ const isCustom=d.cls==='grad-custom';
+ c1Setting.hidden=!isCustom;
+ c2Setting.hidden=!isCustom;
});
+ choices('speed-seg',d=>{vars.setProperty('--grad-dur',d.dur)});
+ choices('c1-sw',d=>{vars.setProperty('--c1',d.c)});
+ choices('c2-sw',d=>{vars.setProperty('--c2',d.c)});
+ txtIn.addEventListener('input',()=>{gradText.textContent=txtIn.value||'Flow'});
</script>
-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script>
</body>
</html>
diff --git a/index.html b/index.html
index 3c0c5771..d4cb194b 100644
--- a/index.html
+++ b/index.html
@@ -994,7 +994,7 @@ const CATS=[
['text-clip-path-reveal','Text Clip-Path Reveal','Each line of a headline is uncovered in turn. Best for big headlines.'],
['marquee-ticker','Marquee / Ticker','Text scrolls sideways in an endless loop, with no seam. Best for news tickers.'],
['text-morphing','Text Morphing','One word changes into the next, letter by letter. Best for short labels.'],
- ['text-gradient-animation','Text Gradient Animation','background-clip: text with animated background-position flows color through the characters.'],
+ ['text-gradient-animation','Text Gradient Animation','Colors flow through the letters while the text stays still. Best for headlines.'],
['outline-to-fill','Outline to Fill','Hollow letters fill with color, as a wipe or a fade. Best for big headlines.'],
['enter-exit-typography','Enter/Exit Typography','Each phrase comes in, stays long enough to read, then leaves. Best for slogans.'],
['rotate-word-carousel','Rotate Word Carousel','One word in a sentence keeps swapping for the next. Best for hero headlines.'],