08타이포 배율 사다리
기준 크기와 배율 하나로 여섯 단계를 계산해 사다리로 보여 주고, 그 값이 사용자 지정 속성 목록으로 떨어집니다.
쓰임디자인 시스템의 글자 크기 표, 랜딩 페이지 제목 단계
clampMath.pow--step-3

<main class="stage">
<div class="gen is-demo" id="gen">
<div class="gen__top">
<div class="gen__preview" aria-hidden="true">
<span class="gen__step gen__step--1">Step 1</span>
<span class="gen__step gen__step--2">Step 2</span>
<span class="gen__step gen__step--3">Step 3</span>
<span class="gen__step gen__step--4">Step 4</span>
<span class="gen__step gen__step--5">Step 5</span>
<span class="gen__step gen__step--6">Step 6</span>
</div>
<div class="gen__grid">
<label class="gen__row">
<span class="gen__lab">기준</span>
<span class="gen__slot">
<input class="gen__rng" type="range" min="12" max="16" step="1" value="14" data-var="--s-base" aria-label="기준 글자 크기">
<span class="gen__thumb" aria-hidden="true"></span>
</span>
</label>
<label class="gen__row">
<span class="gen__lab">배율</span>
<span class="gen__slot">
<input class="gen__rng" type="range" min="110" max="140" step="5" value="120" data-var="--s-ratio" aria-label="단계 배율">
<span class="gen__thumb" aria-hidden="true"></span>
</span>
</label>
</div>
</div>
<div class="gen__out">
<code class="gen__code"><span class="gen__prop">--step-1:</span> <span class="gen__v gen__v--s1"></span>rem; <span class="gen__prop">--step-2:</span> <span class="gen__v gen__v--s2"></span>rem; <span class="gen__prop">--step-3:</span> <span class="gen__v gen__v--s3"></span>rem</code>
<button class="gen__copy" type="button" id="copy">복사</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 타이포 배율 사다리 — 기준 크기와 배율 하나로 여섯 단계가 calc 곱으로 저절로 계산된다.
// 배율은 백분율 정수(125 = 1.25 배)로 등록하고 calc 안에서 0.01 을 곱해 쓴다.
// 몇 곱이 되는지만 단계마다 다르지 식은 하나다 — JS 의 scaleText() 도 같은 식으로 rem 값을 만든다.
// 미리보기 계수 0.6 은 사다리 여섯 단계를 무대(480×300) 안에 들어가게 하는 표시 배율이다 —
// 단계 사이 비율은 그대로다(06 미리보기의 0.32 계수와 같은 관례). 복사 코드는 실제 px 값.
$duration: $dur-loop;
$easing: $ease-spring;
$color: $subject-ink;
$mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
$line: rgba(23, 20, 26, .14);
$track: rgba(23, 20, 26, .18);
$rail: 4px;
$thumb: 12px;
@property --s-base { syntax: "<integer>"; inherits: true; initial-value: 14; }
@property --s-ratio { syntax: "<integer>"; inherits: true; initial-value: 120; }
@include stage($stage-paper);
.gen {
min-width: 0; // stage grid item 의 자동 최소폭(min-content) 을 끊는다 — BD9
--s-base: 14;
--s-ratio: 120;
display: flex; flex-direction: column; gap: $sp-3;
box-sizing: border-box; width: min(100%, 400px);
padding: $sp-3; border: 1px solid $line; border-radius: $r-card;
background: rgba(23, 20, 26, .04);
}
.gen__top { display: flex; align-items: center; gap: $sp-3; }
// ── 미리보기 — 여섯 단계 사다리. calc 곱의 개수만 단계마다 다르다
.gen__preview {
flex: 0 0 auto;
display: flex; flex-direction: column; align-items: flex-start; gap: $sp-1;
box-sizing: border-box; width: 148px; padding: $sp-2;
border-radius: $r-sm;
background: rgba(23, 20, 26, .05);
overflow: hidden;
}
.gen__step {
display: block; white-space: nowrap;
color: $subject-ink;
font-family: $mono; font-weight: 700; line-height: 1.1;
}
.gen__step--1 { font-size: calc(var(--s-base) * 0.6px); }
.gen__step--2 { font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * 0.01); }
.gen__step--3 { font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * 0.0001); }
.gen__step--4 { font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * 0.000001); }
.gen__step--5 { font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * 0.00000001); }
.gen__step--6 { font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * 0.0000000001); }
.gen__grid { flex: 1 1 auto; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: $sp-1; }
.gen__row { display: flex; align-items: center; gap: $sp-1; cursor: pointer; }
.gen__lab {
flex: 0 0 auto; width: 30px;
color: $subject-ink;
font-weight: 700; font-size: 10px; line-height: 1.4;
}
.gen__slot {
position: relative; flex: 1 1 auto; min-width: 0;
display: grid; align-items: center; height: 16px;
}
.gen__slot::before {
content: ""; grid-area: 1 / 1;
height: $rail; border-radius: $r-pill; background: $track;
}
.gen__rng {
grid-area: 1 / 1; appearance: none; -webkit-appearance: none;
width: 100%; min-width: 0; height: 16px; margin: 0; background: transparent;
cursor: pointer;
}
.gen__rng::-webkit-slider-thumb {
-webkit-appearance: none; appearance: none;
width: $thumb; height: $thumb; border: 0; border-radius: 50%;
background: transparent;
}
.gen__rng::-moz-range-thumb {
width: $thumb; height: $thumb; border: 0; border-radius: 50%;
background: transparent;
}
.gen__rng:focus-visible { outline: 2px solid $color; outline-offset: 2px; border-radius: $r-pill; }
.gen__thumb {
position: absolute; top: 50%; left: calc(var(--pct) * 1%);
width: $thumb; height: $thumb; margin-top: -($thumb * .5); margin-left: -($thumb * .5);
border-radius: 50%; background: $color;
pointer-events: none;
}
.gen__row:nth-child(1) .gen__thumb { --pct: calc((var(--s-base) - 12) / 4 * 100); }
.gen__row:nth-child(2) .gen__thumb { --pct: calc((var(--s-ratio) - 110) / 30 * 100); }
.gen__out { display: flex; align-items: flex-start; gap: $sp-2; }
.gen__code {
flex: 1 1 auto; min-width: 0;
padding: $sp-2; border-radius: $r-sm;
background: $subject-ink; color: $subject-cream;
font-family: $mono; font-weight: 500; font-size: 10px; line-height: 1.5;
white-space: nowrap; overflow: hidden;
}
.gen__prop { color: $subject-blue-light; }
// 코드 숫자는 rem 세 자리 소수라 counter 정수로 못 쓴다 — 첫 단계 px 값만 표시하고
// 나머지는 미리보기 사다리가 그대로 보여 준다(전체 목록은 복사로 얻는다)
.gen__v { font-weight: 700; }
.gen__v--s1::after { counter-reset: v var(--s-base); content: counter(v); }
.gen__copy {
flex: 0 0 auto;
padding: $sp-2 $sp-3; border: 0; border-radius: $r-sm;
background: $subject-blue-deep; color: $subject-cream;
font-family: inherit; font-weight: 700; font-size: 11px; line-height: 1.4;
cursor: pointer;
}
.gen__copy:focus-visible { outline: 2px solid $color; outline-offset: 2px; }
// ── 격자 미리보기 — 기준과 배율이 오가면 사다리 전체가 숨쉰다
@keyframes sBase { 0%, 100% { --s-base: 14; } 40% { --s-base: 16; } 75% { --s-base: 12; } }
@keyframes sRatio { 0%, 100% { --s-ratio: 120; } 50% { --s-ratio: 140; } 85% { --s-ratio: 112; } }
.gen.is-demo {
animation-name: sBase, sRatio;
animation-duration: $duration;
animation-timing-function: $easing;
animation-iteration-count: infinite;
}
@media (prefers-reduced-motion: reduce) {
.gen.is-demo { animation: none !important; }
}
@media (max-width: 340px) {
.gen { gap: $sp-2; padding: $sp-2; }
.gen__top { gap: $sp-2; }
// 폰 높이(200px) 안에 들어가게 사다리 아래쪽을 자른다 — 비율은 그대로다
.gen__preview { width: 116px; height: 92px; }
.gen__code { font-size: 9px; }
}@property --s-base {
syntax: "<integer>";
inherits: true;
initial-value: 14;
}
@property --s-ratio {
syntax: "<integer>";
inherits: true;
initial-value: 120;
}
html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffffff;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.gen {
min-width: 0;
--s-base: 14;
--s-ratio: 120;
display: flex;
flex-direction: column;
gap: 12px;
box-sizing: border-box;
width: min(100%, 400px);
padding: 12px;
border: 1px solid rgba(23, 20, 26, 0.14);
border-radius: 16px;
background: rgba(23, 20, 26, 0.04);
}
.gen__top {
display: flex;
align-items: center;
gap: 12px;
}
.gen__preview {
flex: 0 0 auto;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 4px;
box-sizing: border-box;
width: 148px;
padding: 8px;
border-radius: 8px;
background: rgba(23, 20, 26, 0.05);
overflow: hidden;
}
.gen__step {
display: block;
white-space: nowrap;
color: #17141a;
font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
font-weight: 700;
line-height: 1.1;
}
.gen__step--1 {
font-size: calc(var(--s-base) * 0.6px);
}
.gen__step--2 {
font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * 0.01);
}
.gen__step--3 {
font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * 0.0001);
}
.gen__step--4 {
font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * 0.000001);
}
.gen__step--5 {
font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * 0.00000001);
}
.gen__step--6 {
font-size: calc(var(--s-base) * 0.6px * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * var(--s-ratio) * 0.0000000001);
}
.gen__grid {
flex: 1 1 auto;
min-width: 0;
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 4px;
}
.gen__row {
display: flex;
align-items: center;
gap: 4px;
cursor: pointer;
}
.gen__lab {
flex: 0 0 auto;
width: 30px;
color: #17141a;
font-weight: 700;
font-size: 10px;
line-height: 1.4;
}
.gen__slot {
position: relative;
flex: 1 1 auto;
min-width: 0;
display: grid;
align-items: center;
height: 16px;
}
.gen__slot::before {
content: "";
grid-area: 1/1;
height: 4px;
border-radius: 999px;
background: rgba(23, 20, 26, 0.18);
}
.gen__rng {
grid-area: 1/1;
appearance: none;
-webkit-appearance: none;
width: 100%;
min-width: 0;
height: 16px;
margin: 0;
background: transparent;
cursor: pointer;
}
.gen__rng::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 12px;
height: 12px;
border: 0;
border-radius: 50%;
background: transparent;
}
.gen__rng::-moz-range-thumb {
width: 12px;
height: 12px;
border: 0;
border-radius: 50%;
background: transparent;
}
.gen__rng:focus-visible {
outline: 2px solid #17141a;
outline-offset: 2px;
border-radius: 999px;
}
.gen__thumb {
position: absolute;
top: 50%;
left: calc(var(--pct) * 1%);
width: 12px;
height: 12px;
margin-top: -6px;
margin-left: -6px;
border-radius: 50%;
background: #17141a;
pointer-events: none;
}
.gen__row:nth-child(1) .gen__thumb {
--pct: calc((var(--s-base) - 12) / 4 * 100);
}
.gen__row:nth-child(2) .gen__thumb {
--pct: calc((var(--s-ratio) - 110) / 30 * 100);
}
.gen__out {
display: flex;
align-items: flex-start;
gap: 8px;
}
.gen__code {
flex: 1 1 auto;
min-width: 0;
padding: 8px;
border-radius: 8px;
background: #17141a;
color: #fff7e6;
font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
font-weight: 500;
font-size: 10px;
line-height: 1.5;
white-space: nowrap;
overflow: hidden;
}
.gen__prop {
color: #5b8cf8;
}
.gen__v {
font-weight: 700;
}
.gen__v--s1::after {
counter-reset: v var(--s-base);
content: counter(v);
}
.gen__copy {
flex: 0 0 auto;
padding: 8px 12px;
border: 0;
border-radius: 8px;
background: #0a4fe8;
color: #fff7e6;
font-family: inherit;
font-weight: 700;
font-size: 11px;
line-height: 1.4;
cursor: pointer;
}
.gen__copy:focus-visible {
outline: 2px solid #17141a;
outline-offset: 2px;
}
@keyframes sBase {
0%, 100% {
--s-base: 14;
}
40% {
--s-base: 16;
}
75% {
--s-base: 12;
}
}
@keyframes sRatio {
0%, 100% {
--s-ratio: 120;
}
50% {
--s-ratio: 140;
}
85% {
--s-ratio: 112;
}
}
.gen.is-demo {
animation-name: sBase, sRatio;
animation-duration: 2s;
animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
animation-iteration-count: infinite;
}
@media (prefers-reduced-motion: reduce) {
.gen.is-demo {
animation: none !important;
}
}
@media (max-width: 340px) {
.gen {
gap: 8px;
padding: 8px;
}
.gen__top {
gap: 8px;
}
.gen__preview {
width: 116px;
height: 92px;
}
.gen__code {
font-size: 9px;
}
}var gen = document.getElementById('gen');
var copyBtn = document.getElementById('copy');
var ranges = Array.prototype.slice.call(gen.querySelectorAll('.gen__rng'));
var COPY_LABEL = '복사';
var DONE_LABEL = '복사됨';
// 기준 크기와 배율 — 다섯 단계 사다리가 calc 곱으로 저절로 따라온다(scss 의 calc 랑 같은 식).
// 속성은 --s-base(정수 px) 와 --s-ratio(백분율 정수) 둘뿐이다
function readVar(name) {
return parseInt(getComputedStyle(gen).getPropertyValue(name), 10) || 0;
}
function scaleText() {
var base = readVar('--s-base');
var ratio = readVar('--s-ratio') / 100;
var lines = [];
for (var i = 1; i <= 6; i++) {
lines.push('--step-' + i + ': ' + (Math.round(base * Math.pow(ratio, i - 1) * 100) / 100 / 16).toFixed(3) + 'rem;');
}
return ':root {\n ' + lines.join('\n ') + '\n}';
}
// 클립보드는 iframe·http 환경에서 막힐 수 있다 — 거부된 프로미스를 반드시 catch 로 받아 선택 방식으로 떨어진다
function fallbackCopy(text) {
var area = document.createElement('textarea');
area.value = text;
area.setAttribute('readonly', '');
area.style.position = 'fixed';
area.style.opacity = '0';
document.body.appendChild(area);
area.select();
try { document.execCommand('copy'); } catch (err) { /* 여기까지 막히면 조용히 포기한다 */ }
document.body.removeChild(area);
}
ranges.forEach(function (input) {
input.addEventListener('input', function () {
gen.classList.remove('is-demo');
gen.style.setProperty(input.dataset.var, input.value);
});
input.addEventListener('pointerdown', function () { gen.classList.remove('is-demo'); });
});
copyBtn.addEventListener('click', function () {
gen.classList.remove('is-demo');
var text = scaleText();
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(text).catch(function () { fallbackCopy(text); });
} else {
fallbackCopy(text);
}
copyBtn.textContent = DONE_LABEL;
setTimeout(function () { copyBtn.textContent = COPY_LABEL; }, 1200);
});import { useState, useMemo } from 'react';
import styles from './TypeScale.module.scss';
type Axis = { key: string; label: string; min: number; max: number; step: number };
// ambient 선언에 React 이벤트 제네릭이 없어 로컬 타입으로 받는다 (blog-demo TS7006 항)
type RangeEvt = { target: { value: string } };
const AXES: Axis[] = [
{ key: 'base', label: '기준', min: 12, max: 16, step: 1 },
{ key: 'ratio', label: '배율', min: 110, max: 140, step: 5 }
];
export type TypeScaleProps = {
duration?: string;
easing?: string;
color?: string;
};
export default function TypeScale({ duration = '2s', easing = 'cubic-bezier(.2, .8, .2, 1)', color = '#17141a' }: TypeScaleProps) {
const [values, setValues] = useState<Record<string, number>>({ base: 14, ratio: 120 });
const [live, setLive] = useState(true);
const codeText = useMemo(() => {
const ratio = values.ratio / 100;
const lines: string[] = [];
for (let i = 1; i <= 6; i++) {
lines.push(`--step-${i}: ${(values.base * Math.pow(ratio, i - 1) / 16).toFixed(3)}rem;`);
}
return `:root {\n ${lines.join('\n ')}\n}`;
}, [values]);
const stepSizes = useMemo(() => {
// 미리보기 계수 0.6 은 사다리를 무대 안에 들어가게 하는 표시 배율이다 — 단계 비율은 그대로다
const sizes: number[] = [];
for (let i = 0; i < 6; i++) {
sizes.push(values.base * Math.pow(values.ratio / 100, i) * 0.6);
}
return sizes;
}, [values]);
const style = {
'--dur-loop': duration,
'--ease-spring': easing,
'--accent': color
} as Record<string, string | number>;
function copy() {
setLive(false);
try {
navigator.clipboard.writeText(codeText);
} catch (err) {
/* 클립보드가 막힌 환경에서는 조용히 넘어간다 */
}
}
return (
<div className={live ? `${styles.gen} ${styles.isDemo}` : styles.gen} style={style}>
<div className={styles.top}>
<div className={styles.preview} aria-hidden="true">
{stepSizes.map((size, i) => (
<span key={i} style={{ fontSize: `${size.toFixed(2)}px` }}>{'Step ' + (i + 1)}</span>
))}
</div>
<div className={styles.grid}>
{AXES.map((axis) => (
<label className={styles.row} key={axis.key}>
<span className={styles.lab}>{axis.label}</span>
<span className={styles.slot}>
<input
className={styles.rng}
type="range"
min={axis.min}
max={axis.max}
step={axis.step}
value={values[axis.key]}
aria-label={axis.label}
onChange={(e: RangeEvt) => {
setLive(false);
setValues((v) => ({ ...v, [axis.key]: Number(e.target.value) }));
}}
/>
<span
className={styles.thumb}
aria-hidden="true"
style={{ left: `${((values[axis.key] - axis.min) / (axis.max - axis.min)) * 100}%` }}
/>
</span>
</label>
))}
</div>
</div>
<div className={styles.out}>
<code className={styles.code}>
<span className={styles.prop}>--step-1:</span> {(values.base / 16).toFixed(3)}rem; <span className={styles.prop}>--step-2:</span> {(values.base * values.ratio / 100 / 16).toFixed(3)}rem; <span className={styles.prop}>--step-3:</span> {(values.base * Math.pow(values.ratio / 100, 2) / 16).toFixed(3)}rem
</code>
<button className={styles.copy} type="button" onClick={copy}>복사</button>
</div>
</div>
);
}08 타이포 배율 사다리 — 측정 누적면적 42.674% · 움직인 프레임 21/23GODRICH 원작 · zip 에 SCSS·React 포함 · css generator 9종 — 슬라이더로 만드는 css 그림자 효과
이 데모가 속한 글
css generator 9종 — 슬라이더로 만드는 css 그림자 효과css generator 는 CSS 값을 손으로 만지는 웹 화면입니다 — 슬라이더를 끌면 코드가 바뀝니다. 그림자·그라디언트·모서리·타이밍 같은 CSS 속성을 눈으로 맞추고, 아래 코드 상자에서 그대로 복사해 씁니다 이 글의 데모 전부 보기


