09Heading Whose Range Value Stretches Letter Spacing
The range value is converted into a letter-spacing value, so the heading starts tightly packed and its letters spread apart as the value fills.
Best forSection title letter-spacing expand
letter-spacingIntersectionObserverlssStretch

<main class="stage">
<div class="lss is-demo" id="lssRoot">
<div class="lss__badge" id="lssBadge">entry range 0%~0%</div>
<button class="lss__ctrl" id="lssCtrl" type="button">Pause</button>
<div class="lss__view" id="lssView">
<div class="lss__track" id="lssTrack">
<div class="lss__spacer lss__spacer--top"></div>
<h2 class="lss__title" id="lssTitle">Section title</h2>
<div class="lss__spacer lss__spacer--bottom"></div>
</div>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 핵심: animation-timeline: view() + animation-range: entry 로 글자 사이 간격 값을
// 진입 구간 값(0~1)에 직접 묶는다 — 좁게 뭉쳐 있다가 값이 채워질수록 넓게 벌어진다.
// 미지원 환경은 교차 비율로 같은 글자 간격 값을 계산한다.
$duration: $dur-loop;
$easing: linear;
$color: $subject-cream;
@include stage($stage-ink);
.lss {
position: relative;
width: min(100%, 280px);
display: flex;
flex-direction: column;
align-items: center;
gap: $sp-3;
}
.lss__badge {
padding: $sp-1 $sp-3;
border-radius: $r-pill;
background: rgba(255, 247, 230, .08);
color: $subject-cream;
font-weight: 700;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.lss__ctrl {
position: absolute;
top: 0;
right: 0;
border: 0;
border-radius: $r-xs;
padding: $sp-1 $sp-2;
background: rgba(255, 247, 230, .12);
color: $subject-cream;
font-weight: 600;
font-size: 10px;
line-height: 1.4;
cursor: pointer;
}
.lss__ctrl:focus-visible { outline: 2px solid $subject-blue-light; outline-offset: 2px; }
.lss__view {
box-sizing: border-box;
width: 100%;
height: 176px;
overflow-y: auto;
overflow-x: hidden;
border-radius: $r-card;
background: rgba(255, 255, 255, .05);
scrollbar-width: thin;
}
.lss__track {
display: flex;
flex-direction: column;
align-items: center;
}
.lss__spacer--top { height: 190px; flex: 0 0 auto; }
.lss__spacer--bottom { height: 40px; flex: 0 0 auto; }
.lss__title {
flex: 0 0 auto;
margin: 0;
color: $color;
font-weight: 800;
font-size: 22px;
line-height: 1.3;
letter-spacing: -0.04em;
opacity: .35;
}
.supports-vt .lss__title {
animation-name: lssStretch;
animation-duration: 1s;
animation-timing-function: linear;
animation-fill-mode: both;
animation-timeline: view();
animation-range: entry;
}
@keyframes lssStretch {
0% { letter-spacing: -0.04em; opacity: .35; }
100% { letter-spacing: 0.4em; opacity: 1; }
}
@media (max-width: 340px) {
.lss { gap: $sp-2; }
.lss__view { height: 130px; }
.lss__spacer--top { height: 130px; }
.lss__spacer--bottom { height: 26px; }
.lss__title { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
.lss__title { animation: none !important; letter-spacing: 0.4em !important; opacity: 1 !important; }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #17141a;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.lss {
position: relative;
width: min(100%, 280px);
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
}
.lss__badge {
padding: 4px 12px;
border-radius: 999px;
background: rgba(255, 247, 230, 0.08);
color: #fff7e6;
font-weight: 700;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.lss__ctrl {
position: absolute;
top: 0;
right: 0;
border: 0;
border-radius: 4px;
padding: 4px 8px;
background: rgba(255, 247, 230, 0.12);
color: #fff7e6;
font-weight: 600;
font-size: 10px;
line-height: 1.4;
cursor: pointer;
}
.lss__ctrl:focus-visible {
outline: 2px solid #5b8cf8;
outline-offset: 2px;
}
.lss__view {
box-sizing: border-box;
width: 100%;
height: 176px;
overflow-y: auto;
overflow-x: hidden;
border-radius: 16px;
background: rgba(255, 255, 255, 0.05);
scrollbar-width: thin;
}
.lss__track {
display: flex;
flex-direction: column;
align-items: center;
}
.lss__spacer--top {
height: 190px;
flex: 0 0 auto;
}
.lss__spacer--bottom {
height: 40px;
flex: 0 0 auto;
}
.lss__title {
flex: 0 0 auto;
margin: 0;
color: #fff7e6;
font-weight: 800;
font-size: 22px;
line-height: 1.3;
letter-spacing: -0.04em;
opacity: 0.35;
}
.supports-vt .lss__title {
animation-name: lssStretch;
animation-duration: 1s;
animation-timing-function: linear;
animation-fill-mode: both;
animation-timeline: view();
animation-range: entry;
}
@keyframes lssStretch {
0% {
letter-spacing: -0.04em;
opacity: 0.35;
}
100% {
letter-spacing: 0.4em;
opacity: 1;
}
}
@media (max-width: 340px) {
.lss {
gap: 8px;
}
.lss__view {
height: 130px;
}
.lss__spacer--top {
height: 130px;
}
.lss__spacer--bottom {
height: 26px;
}
.lss__title {
font-size: 18px;
}
}
@media (prefers-reduced-motion: reduce) {
.lss__title {
animation: none !important;
letter-spacing: 0.4em !important;
opacity: 1 !important;
}
}(function () {
var supportsVt = CSS.supports('animation-timeline: view()');
var root = document.getElementById('lssRoot');
var view = document.getElementById('lssView');
var title = document.getElementById('lssTitle');
var badge = document.getElementById('lssBadge');
var ctrl = document.getElementById('lssCtrl');
root.classList.add(supportsVt ? 'supports-vt' : 'no-vt');
var SPACING_START = -0.04;
var SPACING_END = 0.4;
// 계산 한 겹: 요소 높이·뷰포트 높이에서 진입 구간(시작~끝 %) 값을 구해 배지에 표시한다.
function entryRangePct() {
var elH = title.offsetHeight;
var viewH = view.clientHeight;
return Math.round(Math.min(100, (elH / viewH) * 100));
}
var rangeEnd = entryRangePct();
var rangeText = 'entry range 0%~' + rangeEnd + '%';
function render(ratio) {
if (!supportsVt) {
var spacing = SPACING_START + (SPACING_END - SPACING_START) * ratio;
title.style.letterSpacing = spacing.toFixed(3) + 'em';
title.style.opacity = String(0.35 + 0.65 * ratio);
}
badge.textContent = rangeText + ' · progress ' + Math.round(ratio * 100) + '%';
}
var lastRatio = 0;
if (!supportsVt) {
var STEPS = [];
for (var s = 0; s <= 50; s += 1) { STEPS.push(s / 50); }
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
lastRatio = entry.intersectionRatio;
render(lastRatio);
});
}, { root: view, threshold: STEPS });
io.observe(title);
} else {
badge.textContent = rangeText;
}
view.addEventListener('scroll', function () {
if (supportsVt) {
var max = view.scrollHeight - view.clientHeight;
var p = max > 0 ? Math.min(1, Math.max(0, view.scrollTop / max)) : 0;
badge.textContent = rangeText + ' · scroll ' + Math.round(p * 100) + '%';
}
}, { passive: true });
var playing = true;
var frame = 0;
var PERIOD = 66;
function tick() {
if (playing) {
frame += 1;
var max = view.scrollHeight - view.clientHeight;
var t = frame % (PERIOD * 2);
var f = t < PERIOD ? (t / PERIOD) : ((PERIOD * 2 - t) / PERIOD);
view.scrollTop = f * max;
}
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
function stopAuto() {
if (root.classList.contains('is-demo')) { root.classList.remove('is-demo'); }
playing = false;
ctrl.textContent = 'Play';
}
view.addEventListener('wheel', stopAuto, { passive: true });
view.addEventListener('touchstart', stopAuto, { passive: true });
ctrl.addEventListener('click', function () {
playing = !playing;
ctrl.textContent = playing ? 'Pause' : 'Play';
if (playing) { root.classList.add('is-demo'); }
});
ctrl.addEventListener('keydown', function (e) {
if (e.key === 'r' || e.key === 'R') {
frame = 0;
view.scrollTop = 0;
lastRatio = 0;
render(0);
playing = true;
root.classList.add('is-demo');
ctrl.textContent = 'Pause';
}
});
window.addEventListener('resize', function () {
rangeEnd = entryRangePct();
rangeText = 'entry range 0%~' + rangeEnd + '%';
});
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (reduce) {
playing = false;
root.classList.remove('is-demo');
lastRatio = 1;
render(1);
title.style.letterSpacing = SPACING_END.toFixed(3) + 'em';
title.style.opacity = '1';
badge.textContent = rangeText + ' · final state';
}
})();import { useEffect, useRef, useState } from "react";
import styles from "./LetterSpacingStretch.module.scss";
// 핵심: animation-timeline: view() + animation-range: entry 로 글자 사이 간격 값을
// 진입 구간 값(0~1)에 직접 묶는다 — 좁게 뭉쳐 있다가 값이 채워질수록 넓게 벌어지며
// 함께 밝아진다. 미지원 환경은 교차 비율로 같은 글자 간격·투명도 값을 계산한다.
const SPACING_START = -0.04;
const SPACING_END = 0.4;
export default function LetterSpacingStretch() {
const rootRef = useRef<HTMLDivElement>(null);
const viewRef = useRef<HTMLDivElement>(null);
const titleRef = useRef<HTMLHeadingElement>(null);
const [badge, setBadge] = useState("진입 구간 0%~0%");
const [demo, setDemo] = useState(true);
const [supportsVt, setSupportsVt] = useState(false);
useEffect(() => {
const view = viewRef.current;
const title = titleRef.current;
const root = rootRef.current;
if (!view || !title || !root) { return; }
const vt = CSS.supports("animation-timeline: view()");
setSupportsVt(vt);
function entryRangePct() {
const elH = title!.offsetHeight;
const viewH = view!.clientHeight;
return Math.round(Math.min(100, (elH / viewH) * 100));
}
let rangeEnd = entryRangePct();
let rangeText = "진입 구간 0%~" + rangeEnd + "%";
function render(ratio: number) {
if (!vt) {
const spacing = SPACING_START + (SPACING_END - SPACING_START) * ratio;
title!.style.letterSpacing = spacing.toFixed(3) + "em";
title!.style.opacity = String(0.35 + 0.65 * ratio);
}
setBadge(rangeText + " · 진행 " + Math.round(ratio * 100) + "%");
}
let io: IntersectionObserver | null = null;
if (!vt) {
const STEPS: number[] = [];
for (let s = 0; s <= 50; s += 1) { STEPS.push(s / 50); }
io = new IntersectionObserver((entries) => {
entries.forEach((entry) => { render(entry.intersectionRatio); });
}, { root: view, threshold: STEPS });
io.observe(title);
} else {
setBadge(rangeText);
}
function onScroll() {
if (vt) {
const max = view!.scrollHeight - view!.clientHeight;
const p = max > 0 ? Math.min(1, Math.max(0, view!.scrollTop / max)) : 0;
setBadge(rangeText + " · 스크롤 " + Math.round(p * 100) + "%");
}
}
view.addEventListener("scroll", onScroll, { passive: true });
let playing = true;
let frame = 0;
const PERIOD = 66;
let rafId = 0;
function tick() {
if (playing) {
frame += 1;
const max = view!.scrollHeight - view!.clientHeight;
const t = frame % (PERIOD * 2);
const f = t < PERIOD ? (t / PERIOD) : ((PERIOD * 2 - t) / PERIOD);
view!.scrollTop = f * max;
}
rafId = requestAnimationFrame(tick);
}
rafId = requestAnimationFrame(tick);
function stopAuto() {
setDemo(false);
playing = false;
}
view.addEventListener("wheel", stopAuto, { passive: true });
view.addEventListener("touchstart", stopAuto, { passive: true });
function onClick() {
playing = !playing;
setDemo(playing);
}
function onKeyDown(e: KeyboardEvent) {
if (e.key === "r" || e.key === "R") {
frame = 0;
view!.scrollTop = 0;
render(0);
playing = true;
setDemo(true);
}
}
root.addEventListener("keydown", onKeyDown);
function onResize() {
rangeEnd = entryRangePct();
rangeText = "진입 구간 0%~" + rangeEnd + "%";
}
window.addEventListener("resize", onResize);
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (reduce) {
playing = false;
setDemo(false);
render(1);
title.style.letterSpacing = SPACING_END.toFixed(3) + "em";
title.style.opacity = "1";
setBadge(rangeText + " · 최종 상태");
}
const ctrl = root.querySelector("button");
ctrl?.addEventListener("click", onClick);
return () => {
cancelAnimationFrame(rafId);
io?.disconnect();
view.removeEventListener("scroll", onScroll);
view.removeEventListener("wheel", stopAuto);
view.removeEventListener("touchstart", stopAuto);
root.removeEventListener("keydown", onKeyDown);
window.removeEventListener("resize", onResize);
ctrl?.removeEventListener("click", onClick);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<main className={styles.stage}>
<div ref={rootRef} className={`${styles.lss} ${demo ? styles["is-demo"] : ""} ${supportsVt ? styles["supports-vt"] : styles["no-vt"]}`}>
<div className={styles["lss__badge"]}>{badge}</div>
<button className={styles["lss__ctrl"]} type="button">{demo ? "일시정지" : "재생"}</button>
<div ref={viewRef} className={styles["lss__view"]}>
<div className={styles["lss__track"]}>
<div className={`${styles["lss__spacer"]} ${styles["lss__spacer--top"]}`} />
<h2 ref={titleRef} className={styles["lss__title"]}>섹션 타이틀</h2>
<div className={`${styles["lss__spacer"]} ${styles["lss__spacer--bottom"]}`} />
</div>
</div>
</div>
</main>
);
}09 Heading Whose Range Value Stretches Letter Spacing — Measured area 4.267% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · CSS Scroll Animation: 9 View-Timeline Examples
The post this demo lives in
CSS Scroll Animation: 9 View-Timeline ExamplesNine css scroll animation demos, one idea: A card sits blurred, then sharpens as you scroll past it — one range value dr See all demos in this post


