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.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Outline to Fill — Animation Handbook</title>
<meta name="description" content="Hollow letters fill with color, as a wipe or a fade. Best for big headlines.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/outline-to-fill/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
<link rel="apple-touch-icon" href="../../../apple-touch-icon.png">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Outline to Fill — Animation Handbook">
<meta property="og:description" content="Hollow letters fill with color, as a wipe or a fade. Best for big headlines.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/outline-to-fill/">
<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="Outline to Fill — Animation Handbook">
<meta name="twitter:description" content="Hollow letters fill with color, as a wipe or a fade. Best for big 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": "Outline to Fill", "name": "Outline to Fill", "description": "Hollow letters fill with color, as a wipe or a fade. Best for big headlines.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/05-text-typography/outline-to-fill/", "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, Outline to Fill"}</script>
<style>
:root{--ui-accent:#ff6f8b;--fill-dur:900ms;--fill-ease:ease-in-out;--stroke-color:#ff6f8b;--fill-color:#ff6f8b;--stroke-w:2px}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:24px;padding:24px;background:#04060c}
.otf-text{font-size:var(--otf-fs,clamp(44px,8vw,84px));line-height:1;letter-spacing:0.06em;font-weight:800;-webkit-user-select:none;user-select:none}
/* Variant A: bottom-up fill via stacked layers */
.otf-wrap{position:relative;display:inline-block}
.outline-layer{
-webkit-text-stroke:var(--stroke-w) var(--stroke-color);
color:transparent;
position:relative;z-index:2
}
.fill-layer{
position:absolute;inset:0;
-webkit-text-stroke:var(--stroke-w) var(--stroke-color);
color:var(--fill-color);
clip-path:inset(100% 0 0 0);
transition:clip-path var(--fill-dur) var(--fill-ease);
z-index:1
}
.fill-layer.dir-down{clip-path:inset(0 0 100% 0)}
.fill-layer.dir-left{clip-path:inset(0 0 0 100%)}
.fill-layer.dir-right{clip-path:inset(0 100% 0 0)}
.fill-layer.dir-center{clip-path:inset(50% 0)}
.fill-layer.filled{clip-path:inset(0%)!important}
/* Variant B: stroke fade, fill fade */
.stroke-fade-wrap{position:relative;display:inline-block}
.stroke-only{
-webkit-text-stroke:var(--stroke-w) var(--stroke-color);
color:transparent;
transition:opacity var(--fill-dur) var(--fill-ease)
}
.fill-only{
position:absolute;inset:0;
color:var(--fill-color);
opacity:0;
transition:opacity var(--fill-dur) var(--fill-ease)
}
.stroke-fade-wrap.filled .stroke-only{opacity:0}
.stroke-fade-wrap.filled .fill-only{opacity:1}
/* Label */
.var-label{font-size:clamp(11px,1.5vw,14px);letter-spacing:2px;text-transform:uppercase;color:#8a8a92;text-align:center;margin-bottom:12px}
/* See inside and Compare. The script sets --otf-fs (the word size that fits the box), --m1 to --m3 and --pb (room for the words above
or below a row) and --rem (how much of the fill is still shut at the pose). */
.otf-cap,.otf-ghost,.otf-win,.twin{display:none}
.otf-cap{position:absolute;left:0;top:0;z-index:4;width:max-content;padding:3px 7px;border-radius:5px;background:rgba(11,11,13,.9);color:#f4f4f2;font:600 13px/1.25 var(--hb-font);pointer-events:none}
#fill-layer{--pc:inset(calc(var(--rem,0)*100%) 0 0 0)}
#fill-layer.dir-down{--pc:inset(0 0 calc(var(--rem,0)*100%) 0)}
#fill-layer.dir-left{--pc:inset(0 0 0 calc(var(--rem,0)*100%))}
#fill-layer.dir-right{--pc:inset(0 calc(var(--rem,0)*100%) 0 0)}
#fill-layer.dir-center{--pc:inset(calc(var(--rem,0)*50%) 0)}
.stage[data-hb-mode="inside"].posed #fill-layer,.stage[data-hb-mode="compare"].posed #fill-layer{clip-path:var(--pc)!important;transition:none!important}
/* See inside: the filled copy is pulled down under the hollow one, with a faint full copy behind it, a dashed frame and a bright edge
that takes the window's own transition (two edges from the middle). The pose holds the fill half way through its time. */
.stage[data-hb-mode="inside"]{gap:10px;padding:8px 24px var(--pb,8px)}
.stage[data-hb-mode="inside"][data-otf="beside"]{padding-right:290px}
.stage[data-hb-mode="inside"] > .otf-cap:not([hidden]){display:block}
.stage[data-hb-mode="inside"] .var-label{margin:0;line-height:14px}
.stage[data-hb-mode="inside"] .wipe .var-label{margin-bottom:var(--m1,0px)}
.stage[data-hb-mode="inside"] .wipe{margin-bottom:var(--m2,0px)}
.stage[data-hb-mode="inside"] .fade{margin-bottom:var(--m3,0px)}
.stage[data-hb-mode="inside"] .fill-layer{position:relative;inset:auto;margin-top:8px}.stage[data-hb-mode="inside"] .otf-text{white-space:nowrap}
.stage[data-hb-mode="inside"] .otf-ghost,.stage[data-hb-mode="inside"] .otf-win{display:block;position:absolute;left:0;right:0;bottom:0;height:var(--otf-fs)}
.stage[data-hb-mode="inside"] .otf-ghost{z-index:0;opacity:.2;-webkit-text-stroke:var(--stroke-w) var(--stroke-color);color:var(--fill-color)}
.stage[data-hb-mode="inside"] .otf-win{z-index:3;pointer-events:none;outline:1.5px dashed rgba(244,244,242,.5);outline-offset:2px}
.otf-edge{position:absolute;inset:0;--k:1;--sx:0;--sy:1;--m:1;
transform:translate(calc(var(--k)*var(--sx)*var(--m)*100%),calc(var(--k)*var(--sy)*var(--m)*100%));
box-shadow:inset calc(var(--sx)*2px) calc(var(--sy)*2px) 0 #fff,inset calc(var(--sx)*3px) calc(var(--sy)*3px) 0 #04060c;
transition:transform var(--fill-dur) var(--fill-ease)}
.otf-edge.e2{display:none;--sy:-1;--m:.5}
.fill-layer.dir-down~.otf-win .otf-edge{--sy:-1}
.fill-layer.dir-left~.otf-win .otf-edge{--sx:1;--sy:0}
.fill-layer.dir-right~.otf-win .otf-edge{--sx:-1;--sy:0}
.fill-layer.dir-center~.otf-win .e1{--m:.5}
.fill-layer.dir-center~.otf-win .e2{display:block}
.fill-layer.filled~.otf-win .otf-edge{--k:0}
.stage[data-hb-mode="inside"].posed .otf-edge{--k:var(--rem);transition:none!important}
.stage[data-hb-mode="inside"].posed .stroke-only{opacity:var(--rem)!important;transition:none!important}
.stage[data-hb-mode="inside"].posed .fill-only{opacity:calc(1 - var(--rem))!important;transition:none!important}
/* Compare: Snaps (a copy whose fill has no transition) above Wipes (the real row). The Fade row is set aside but keeps running. */
.stage[data-hb-mode="compare"]{gap:0;padding:8px 24px}
.stage[data-hb-mode="compare"] .var-label{display:none}
.stage[data-hb-mode="compare"] .otf-item{position:relative;width:100%;padding:30px 0;display:flex;flex-direction:column;align-items:center}
.stage[data-hb-mode="compare"] .fade{position:absolute;visibility:hidden}
.stage[data-hb-mode="compare"] .twin{display:flex;border-bottom:1px solid rgba(244,244,242,.14)}
.stage[data-hb-mode="compare"] .otf-name{display:block;top:3px;left:50%;transform:translateX(-50%)}
.stage[data-hb-mode="compare"].posed .otf-note{display:block;top:auto;bottom:3px;left:50%;transform:translateX(-50%)}
.stage[data-hb-mode="compare"].posed #otf-wrap::after{content:'';position:absolute;inset:0;outline:1.5px dashed rgba(244,244,242,.5);outline-offset:2px;border-radius:2px}
.twin .fill-layer{transition:none!important}
@media(prefers-reduced-motion:reduce){.fill-layer,.stroke-only,.fill-only,.otf-edge{transition:none!important}.fill-layer{clip-path:inset(0%)!important}.stroke-fade-wrap.filled .fill-only{opacity:1!important}.stroke-fade-wrap.filled .stroke-only{opacity:0!important}}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=11">
<script src="../../../assets/js/demo-page.js?v=11" defer></script>
</head>
<body class="hb" data-hb-kind="once" data-hb-autoplay>
<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-gradient-animation/" rel="prev" aria-label="Previous: Text Gradient Animation"><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 Gradient Animation</span></a><a href="../enter-exit-typography/" rel="next" aria-label="Next: Enter/Exit Typography"><span><span class="hb-dir">Next: </span>Enter/Exit Typography</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
<a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg><span>Star on GitHub</span></a>
</nav>
<main class="hb-page">
<header class="hb-head">
<p class="hb-cat">05.09 · Text & Typography</p>
<h1>Outline to Fill</h1>
<p class="hb-lede">Hollow letters fill with color, as a wipe or a fade. Best for big 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 plays by itself. Turn on slow motion to see each part of the movement.</p></div>
</div>
<div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
<button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
<button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
<button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
</div>
<div class="stage hb-dots">
<div class="otf-item wipe">
<p class="var-label">Wipe</p>
<div class="otf-wrap" id="otf-wrap">
<div class="otf-text outline-layer" id="outline-layer">OUTLINE</div>
<div class="otf-text fill-layer" id="fill-layer" aria-hidden="true">OUTLINE</div>
</div>
<p class="otf-cap otf-name" data-hb-caption aria-hidden="true">Wipes</p>
<p class="otf-cap otf-note" data-hb-caption aria-hidden="true">Half way through the fill</p>
</div>
<div class="otf-item fade">
<p class="var-label">Fade</p>
<div class="stroke-fade-wrap" id="stroke-wrap">
<div class="otf-text stroke-only" id="stroke-only">OUTLINE</div>
<div class="otf-text fill-only" id="fill-only" aria-hidden="true">OUTLINE</div>
</div>
</div>
<p class="otf-cap" data-hb-caption aria-hidden="true">Hollow copy, always on top</p>
<p class="otf-cap" data-hb-caption aria-hidden="true"></p>
<p class="otf-cap" data-hb-caption aria-hidden="true">Fade: the hollow copy fades out as the filled one fades in</p>
<p class="otf-cap" data-hb-caption aria-hidden="true"></p>
</div>
<div class="hb-player">
<button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>
<label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop autocomplete="off"><span>Loop</span></label>
<label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo autocomplete="off"><span>Slow motion</span></label>
</div>
<div class="hb-mode-notes" aria-live="polite">
<p data-hb-for="inside" hidden>Here the word's two copies are pulled apart: hollow on top, filled below. The wipe uncovers the filled copy through a growing window; the fade swaps the two by fading.</p>
<p data-hb-for="compare" hidden>Snaps fills the hollow letters in a single jump. Wipes pours the color in, so you see the fill travel across the letters.</p>
</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 the animation plays again.</p></div>
</div>
<div class="hb-settings">
<div class="hb-setting">
<p class="hb-setting-name" id="dir-lbl">Fill direction</p>
<div class="seg" id="dir-seg" role="group" aria-labelledby="dir-lbl">
<button type="button" data-dir="up" class="on" aria-pressed="true">Bottom up</button>
<button type="button" data-dir="down" aria-pressed="false">Top down</button>
<button type="button" data-dir="right" aria-pressed="false">Left to right</button>
<button type="button" data-dir="left" aria-pressed="false">Right to left</button>
<button type="button" data-dir="center" aria-pressed="false">From the middle</button>
</div>
<p class="hb-hint">Where the wipe starts; the fade fills all at once.</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-ms="1500" aria-pressed="false">Slow</button>
<button type="button" data-ms="900" class="on" aria-pressed="true">Normal</button>
<button type="button" data-ms="550" aria-pressed="false">Fast</button>
</div>
<p class="hb-hint">How long the letters take to fill.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="thick-lbl">Outline thickness</p>
<div class="seg" id="thick-seg" role="group" aria-labelledby="thick-lbl">
<button type="button" data-px="1" aria-pressed="false">Thin</button>
<button type="button" data-px="2" class="on" aria-pressed="true">Medium</button>
<button type="button" data-px="4" aria-pressed="false">Thick</button>
</div>
<p class="hb-hint">Thin looks precise; thick looks bold and graphic.</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">
<p class="hb-setting-name" id="feel-lbl">Feel</p>
<div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">
<button type="button" data-ease="ease-out" aria-pressed="false">Smooth</button>
<button type="button" data-ease="ease-in-out" class="on" aria-pressed="true">Gentle</button>
<button type="button" data-ease="linear" aria-pressed="false">Even</button>
</div>
<p class="hb-hint">Gentle eases in and out; Even keeps one pace.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="outline-color-lbl">Outline color</p>
<div class="swatches" id="outline-color-sw" role="group" aria-labelledby="outline-color-lbl">
<button type="button" class="on" aria-pressed="true" 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" 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 of the letters' edges.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="fill-color-lbl">Fill color</p>
<div class="swatches" id="fill-color-sw" role="group" aria-labelledby="fill-color-lbl">
<button type="button" class="on" aria-pressed="true" 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" 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 that pours into the letters.</p>
</div>
<div class="hb-setting">
<label class="hb-setting-name" for="txt-in">Your text</label>
<input class="hb-text" type="text" id="txt-in" value="OUTLINE" maxlength="10" autocomplete="off">
<p class="hb-hint">Short words work best, up to 10 letters.</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 an outline-to-fill effect to [your headline or logo word]. The text should start hollow, with only the outline of each letter showing, then fill with color. The fill can wipe in from one side, like paint, or fade in everywhere at once, like ink soaking through. Draw the outline and the filled text as two layers in exactly the same place so the letters never shift. Use large, heavy letters so there is enough inside each one to fill. The text must stay readable by screen readers. If the visitor has reduced motion turned on, show the filled text straight away. 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="hb-star-row"><p>Free and open source. If this helped, a star on GitHub helps other people find it.</p><a class="hb-star-btn" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star on GitHub</a></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>Big headlines</li><li>Logos</li><li>Posters</li><li>Section titles</li></ul>
<h3>Avoid on</h3>
<ul class="hb-tags hb-avoid"><li>Small text</li><li>Body 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="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><a href="#top">Back to top ↑</a></footer>
<script>
const stage=document.querySelector('.stage');
const fillLayer=document.getElementById('fill-layer');
const strokeWrap=document.getElementById('stroke-wrap');
const outlineLayer=document.getElementById('outline-layer'),strokeOnly=document.getElementById('stroke-only'),fillOnly=document.getElementById('fill-only');
const vars=document.documentElement.style;
const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');
const txtIn=document.getElementById('txt-in');
const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;
const DIR_CLASSES=['dir-down','dir-left','dir-right','dir-center'];
let dir='up',ms=900,strokeW=2,ease='ease-in-out',timers=[],mode='normal',posed=false;
// See inside and Compare. Compare's first half is a copy of the Wipe row (no ids, inert) whose filled copy has no transition, so its
// letters go from hollow to full in one frame. See inside adds to the real row a faint full copy behind the filled one and a frame
// with a bright edge that moves with the window (two edges from the middle).
const wipeItem=fillLayer.closest('.otf-item'),fadeItem=strokeWrap.closest('.otf-item');
const twinItem=wipeItem.cloneNode(true);
twinItem.querySelectorAll('[id]').forEach(el=>el.removeAttribute('id'));
twinItem.classList.add('twin');twinItem.inert=true;twinItem.setAttribute('aria-hidden','true');
twinItem.querySelector('.otf-name').textContent='Snaps';twinItem.querySelector('.otf-note').remove();
wipeItem.before(twinItem);
const twinFill=twinItem.querySelector('.fill-layer');
const ghost=document.createElement('div'),win=document.createElement('div');
ghost.className='otf-text otf-ghost';ghost.textContent=outlineLayer.textContent;win.className='otf-win';win.innerHTML='<i class="otf-edge e1"></i><i class="otf-edge e2"></i>';
[ghost,win].forEach(el=>{el.inert=true;el.setAttribute('aria-hidden','true')});
fillLayer.parentElement.append(ghost,win);
const anim=[fillLayer,strokeOnly,fillOnly,twinFill,...win.children]; // everything with a transition of its own
const caps=[...stage.querySelectorAll(':scope > .otf-cap')],[,cFill,cFade,cTime]=caps,fadeLong=cFade.textContent;
// Under reduced motion both views are still pictures, and their notes say so
if(!motionOk){
document.querySelector('[data-hb-for="inside"]').textContent='Shown still, half way through the fill: the filled copy is partly uncovered by its window, and the Fade row is part way from outline to fill.';
document.querySelector('[data-hb-for="compare"]').textContent='Shown still, half way through the fill: Snaps is already full, while Wipes is filled only part of the way.';
}
// The Feel choices as the numbers of their speed curves (the browser's own), and the words for the captions
const CURVES={'ease-out':[0,0,.58,1],'ease-in-out':[.42,0,.58,1],linear:[0,0,1,1]};
const FEEL={'ease-out':', starting fast and easing out','ease-in-out':', easing in and out',linear:' at one steady pace'};
const SIDE={up:'from below',down:'from above',right:'from the left',left:'from the right',center:'from the middle'};
const SECS={1:'half a second',2:'a second',3:'a second and a half',5:'two and a half seconds',9:'four and a half seconds'}; // by half seconds
function dur(){return slowTog.checked?ms*3:ms}
function apply(){
vars.setProperty('--fill-dur',dur()+'ms');
vars.setProperty('--fill-ease',ease);
vars.setProperty('--stroke-w',strokeW+'px');
}
function later(fn,wait){timers.push(setTimeout(fn,wait))}
function applyDir(){
fillLayer.classList.remove(...DIR_CLASSES);
if(dir!=='up')fillLayer.classList.add('dir-'+dir);
}
function fitText(){
// Scale long words down so they never get clipped by the stage on narrow screens
const cs=getComputedStyle(stage),avail=stage.clientWidth-parseFloat(cs.paddingLeft)-parseFloat(cs.paddingRight);
document.querySelectorAll('.otf-wrap,.stroke-fade-wrap').forEach(w=>{
w.style.transform='';
const s=avail>0?Math.min(1,avail/w.offsetWidth):1;
if(s<1)w.style.transform='scale('+s.toFixed(3)+')';
});
}
function applyText(t){
[outlineLayer,fillLayer,strokeOnly,fillOnly,ghost,...twinItem.querySelectorAll('.otf-text')].forEach(el=>{el.textContent=t;});
layout();
}
// Snaps both variants back to hollow without a reverse transition, so the next fill runs at full length from the start.
function reset(){
snap(()=>{[fillLayer,twinFill,strokeWrap].forEach(el=>el.classList.remove('filled'));applyDir()});
}
// One play fills both words together. While Loop is on it then holds filled for 1400ms, snaps back
// to hollow at once, waits 300ms and plays again; switching Loop off lets the words finish filled.
// Slow motion stretches the fill itself, not the hold or the wait. In a view a play lifts the pose, which comes back after it with
// Loop off. In Compare a play from Replay starts with both halves hollow for a beat.
function cycle(beat){
apply();
pose(false);
reset();
const fill=()=>[fillLayer,twinFill,strokeWrap].forEach(el=>el.classList.add('filled'));
if(beat&&mode==='compare'&&motionOk)later(fill,200);else fill();
if(!loopTog.checked||!motionOk){poseLater(motionOk?dur()+900:700);return}
later(()=>{
if(!loopTog.checked)return;
reset();
later(cycle,300);
},dur()+1400);
}
function play(){timers.forEach(clearTimeout);timers=[];cycle(true)}
function poseLater(wait){if(mode!=='normal')later(()=>{if(!loopTog.checked)pose(true)},wait)}
// The value of a speed curve at a share x of its time: the curve's own t for x found by halving, then its height there
function curveAt([a,b,c,e],x){
const at=(p,q,t)=>3*p*t*(1-t)*(1-t)+3*q*t*t*(1-t)+t*t*t;
let lo=0,hi=1,t=x;
for(let i=0;i<30;i++){t=(lo+hi)/2;if(at(a,c,t)<x)lo=t;else hi=t}
return at(b,e,t);
}
// Draws a change at once, with no transition running through it (also forces a reflow)
function snap(fn){
anim.forEach(el=>el.style.transition='none');
fn();void stage.offsetWidth;
anim.forEach(el=>el.style.transition='');
}
// The pose, for a view at rest: the fill half way through its time, as far open as the Feel's curve has it by then (--rem is the
// part still shut). A play lifts it; leaving it shows the fill as it is, with no wipe from the pose.
function pose(on){
on=on&&mode!=='normal';
if(on)stage.style.setProperty('--rem',(1-curveAt(CURVES[ease],.5)).toFixed(3));
if(on===posed)return;
posed=on;
snap(()=>stage.classList.toggle('posed',on));
if(mode==='inside')layout();
}
// The word size, up to Normal's, at which the stacked rows fit the box: their height is a fixed part plus the words' own
function fitSize(n,first,last,extra){
const s=stage.style,cs=getComputedStyle(stage);
s.removeProperty('--otf-fs');
const f0=parseFloat(getComputedStyle(outlineLayer).fontSize);
const used=last.getBoundingClientRect().bottom-first.getBoundingClientRect().top+extra+parseFloat(cs.paddingTop)+parseFloat(cs.paddingBottom);
s.setProperty('--otf-fs',Math.floor(Math.max(24,Math.min(f0,f0-(used-stage.clientHeight)/n)))+'px');
}
// See inside's words, from measured sizes: beside their rows on a wide box, above or below them (in room --m1 to --m3 keep) on a
// narrow one; the last (the time, or the pose) has a strip along the bottom.
function place(){
const S=stage.getBoundingClientRect(),ox=S.left+stage.clientLeft,oy=S.top+stage.clientTop,W=stage.clientWidth,H=stage.clientHeight;
const A=[outlineLayer,fillLayer,strokeOnly].map(el=>el.getBoundingClientRect());
const beside=stage.dataset.otf==='beside',x0=Math.max(...A.map(a=>a.right))-ox+16;
let low=4;
caps.forEach((c,i)=>{
if(c.hidden)return;
const w=c.offsetWidth,h=c.offsetHeight,a=A[Math.min(i,2)];
const top=i===3?H-h-6:beside?Math.max((a.top+a.bottom)/2-oy-h/2,low):i===0?a.top-oy-h-3:a.bottom-oy+3;
c.style.left=Math.max(4,Math.min(beside&&i<3?x0:(W-w)/2,W-w-4))+'px';
c.style.top=Math.max(2,Math.min(top,H-h-4))+'px';
low=top+h+6;
});
}
// Sizes for the mode on show: the word size and the room for See inside's words. Normal has none of it.
function layout(){
const s=stage.style;
['--m1','--m2','--m3','--pb','--otf-fs'].forEach(p=>s.removeProperty(p));
delete stage.dataset.otf;
if(mode==='normal'){fitText();return}
if(mode==='compare')fitSize(2,twinItem,wipeItem,0);
else{
const beside=stage.clientWidth>=560,rest=posed||!beside;
stage.dataset.otf=beside?'beside':'above';
cFill.textContent=(beside?'Filled copy, uncovered by a window ':'Filled copy, window ')+SIDE[dir];
cFade.textContent=beside?fadeLong:'Fade: hollow fades out, filled fades in';
cTime.textContent=rest?'Shown half way through the fill':'Both take about '+SECS[Math.round(dur()/500)]+FEEL[ease];
cTime.hidden=false;
caps.forEach((c,i)=>{c.style.left=c.style.top='0px';c.style.maxWidth=(i<3&&beside?250:stage.clientWidth-16)+'px'});
const h=caps.map(c=>c.offsetHeight+4);
if(!beside)['--m1','--m2','--m3'].forEach((p,i)=>s.setProperty(p,h[i]+'px'));
s.setProperty('--pb',h[3]+6+'px');
cTime.hidden=!posed&&!beside;
fitSize(3,wipeItem,fadeItem,beside?0:h[2]);
}
fitText();
if(mode==='inside')place();
}
// The mode switch draws the mode at once (at rest, posed); the shared script then presses Replay (not under reduced motion)
document.addEventListener('hb:mode',e=>{
mode=e.detail.mode;
pose(!loopTog.checked);
layout();
});
document.getElementById('btn-play').addEventListener('click',play);
loopTog.addEventListener('change',()=>{if(loopTog.checked)play();else poseLater(dur()+1000)});
slowTog.addEventListener('change',()=>{if(mode!=='normal')layout()});
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);
if(mode!=='normal'){apply();applyDir();pose(posed);layout()}
}));
}
choices('dir-seg',d=>{dir=d.dir});
choices('speed-seg',d=>{ms=+d.ms});
choices('thick-seg',d=>{strokeW=+d.px});
choices('feel-seg',d=>{ease=d.ease});
choices('outline-color-sw',d=>{vars.setProperty('--stroke-color',d.c)});
choices('fill-color-sw',d=>{vars.setProperty('--fill-color',d.c)});
txtIn.addEventListener('input',()=>{applyText(txtIn.value.trim()?txtIn.value.toUpperCase():'OUTLINE')});
window.addEventListener('resize',layout);
apply();applyDir();fitText();
if(document.fonts)document.fonts.ready.then(layout); // the site font can still be loading when fitText() first runs
</script>
</body>
</html>