07Text outline weight
Sliders hold the outline weight and color, and a hollow button turns the fill transparent. The fallback shadow code for unsupported browsers comes out with it.
Best forLarge headlines over photos, sticker style logo text
-webkit-text-stroketext-shadowpaint-order

<main class="stage">
<div class="gen is-demo" id="gen">
<div class="gen__top">
<div class="gen__preview" aria-hidden="true"><span class="gen__word">GO</span></div>
<div class="gen__grid">
<label class="gen__row">
<span class="gen__lab">Stroke</span>
<span class="gen__slot">
<input class="gen__rng" type="range" min="0" max="8" step="1" value="3" data-var="--t-sw" aria-label="Stroke weight">
<span class="gen__thumb" aria-hidden="true"></span>
</span>
</label>
<label class="gen__row">
<span class="gen__lab">Fill</span>
<span class="gen__slot">
<input class="gen__rng" type="range" min="0" max="100" step="10" value="100" data-var="--t-fill" aria-label="Fill opacity">
<span class="gen__thumb" aria-hidden="true"></span>
</span>
</label>
</div>
</div>
<div class="gen__out">
<code class="gen__code"><span class="gen__prop">-webkit-text-stroke:</span> <span class="gen__v gen__v--sw"></span>px #17141a; <span class="gen__prop">color:</span> rgba(255,247,230,<span class="gen__v gen__v--fill"></span>%)</code>
<button class="gen__copy" type="button" id="copy">Copy</button>
</div>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// 글자 테두리 두께 — -webkit-text-stroke 두께와 채움 불투명도를 속성 둘로 잡는다.
// 채움을 0 으로 내리면 속이 빈 스티커 글자가 된다. paint-order 로 스트로크를 글자 안쪽에
// 그리면 얇은 글자가 뭉개지지 않는다(SVG 관용을 CSS 가 물려받은 속성).
$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 --t-sw { syntax: "<integer>"; inherits: true; initial-value: 3; }
@property --t-fill { syntax: "<integer>"; inherits: true; initial-value: 100; }
@include stage($stage-yellow);
.gen {
min-width: 0; // stage grid item 의 자동 최소폭(min-content) 을 끊는다 — BD9
--t-sw: 3;
--t-fill: 100;
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(255, 255, 255, .5);
}
.gen__top { display: flex; align-items: center; gap: $sp-3; }
// ── 미리보기 — 큰 글자 두 개
.gen__preview {
flex: 0 0 auto;
display: grid; place-items: center;
box-sizing: border-box; width: 132px; height: 84px;
// 크림 채움(4.5:1 미달)을 깔개로 살린다 — 크림 글자 5.98:1, 잉크 테두리도 남색 위에서 보인다 (BD25)
background: $subject-blue-deep; border-radius: $r-sm;
}
.gen__word {
color: rgba(255, 247, 230, calc(var(--t-fill) * 1%));
-webkit-text-stroke: calc(var(--t-sw) * 1px) $subject-ink;
paint-order: stroke fill;
font-family: $mono; font-weight: 900; font-size: 44px; line-height: 1;
letter-spacing: 0.04em;
}
.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: 40px;
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(--t-sw) / 8 * 100); }
.gen__row:nth-child(2) .gen__thumb { --pct: var(--t-fill); }
.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; }
.gen__v { font-weight: 700; }
.gen__v--sw::after { counter-reset: v var(--t-sw); content: counter(v); }
.gen__v--fill::after { counter-reset: v var(--t-fill); 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 tSw { 0%, 100% { --t-sw: 3; } 40% { --t-sw: 7; } 80% { --t-sw: 1; } }
@keyframes tFill { 0%, 100% { --t-fill: 100; } 50% { --t-fill: 0; } }
.gen.is-demo {
animation-name: tSw, tFill;
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; }
.gen__word { font-size: 36px; }
.gen__code { font-size: 9px; }
}@property --t-sw {
syntax: "<integer>";
inherits: true;
initial-value: 3;
}
@property --t-fill {
syntax: "<integer>";
inherits: true;
initial-value: 100;
}
html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ffd23f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.gen {
min-width: 0;
--t-sw: 3;
--t-fill: 100;
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(255, 255, 255, 0.5);
}
.gen__top {
display: flex;
align-items: center;
gap: 12px;
}
.gen__preview {
flex: 0 0 auto;
display: grid;
place-items: center;
box-sizing: border-box;
width: 132px;
height: 84px;
background: #0a4fe8;
border-radius: 8px;
}
.gen__word {
color: rgba(255, 247, 230, calc(var(--t-fill) * 1%));
-webkit-text-stroke: calc(var(--t-sw) * 1px) #17141a;
paint-order: stroke fill;
font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
font-weight: 900;
font-size: 44px;
line-height: 1;
letter-spacing: 0.04em;
}
.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: 40px;
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(--t-sw) / 8 * 100);
}
.gen__row:nth-child(2) .gen__thumb {
--pct: var(--t-fill);
}
.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--sw::after {
counter-reset: v var(--t-sw);
content: counter(v);
}
.gen__v--fill::after {
counter-reset: v var(--t-fill);
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 tSw {
0%, 100% {
--t-sw: 3;
}
40% {
--t-sw: 7;
}
80% {
--t-sw: 1;
}
}
@keyframes tFill {
0%, 100% {
--t-fill: 100;
}
50% {
--t-fill: 0;
}
}
.gen.is-demo {
animation-name: tSw, tFill;
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__word {
font-size: 36px;
}
.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 = 'Copy';
var DONE_LABEL = 'Copied';
// Stroke 두께와 Fill opacity — 속성 둘로 글자 하나를 통째로 다룬다.
// -webkit-text-stroke 는 접두사 그대로 쓰는 게 실무 표준이고, 구형 브라우저 대체는
// 여러 겹의 text-shadow 로 같은 굵기의 테두리를 흉내 낸다(아래 fallbackText)
function readVar(name) {
return parseInt(getComputedStyle(gen).getPropertyValue(name), 10) || 0;
}
function strokeText() {
return '-webkit-text-stroke: ' + readVar('--t-sw') + 'px #17141a;\ncolor: rgba(255,247,230,' + readVar('--t-fill') + '%);';
}
function fallbackText() {
var sw = readVar('--t-sw');
// 네 방향(대각선 포함 여덟 방향) 같은 오프셋의 그림자로 테두리를 흉내 낸다
var shades = [];
for (var dx = -1; dx <= 1; dx++) {
for (var dy = -1; dy <= 1; dy++) {
if (dx === 0 && dy === 0) continue;
shades.push((dx * sw) + 'px ' + (dy * sw) + 'px 0 #17141a');
}
}
return 'text-shadow: ' + shades.join(', ') + ';';
}
// 클립보드는 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 = strokeText() + '\n' + fallbackText();
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 './TextOutline.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: 'sw', label: '테두리', min: 0, max: 8, step: 1 },
{ key: 'fill', label: '채움', min: 0, max: 100, step: 10 }
];
export type TextOutlineProps = {
duration?: string;
easing?: string;
color?: string;
};
export default function TextOutline({ duration = '2s', easing = 'cubic-bezier(.2, .8, .2, 1)', color = '#17141a' }: TextOutlineProps) {
const [values, setValues] = useState<Record<string, number>>({ sw: 3, fill: 100 });
const [live, setLive] = useState(true);
const codeText = useMemo(() => {
return `-webkit-text-stroke: ${values.sw}px #17141a;\ncolor: rgba(255,247,230,${values.fill}%);`;
}, [values]);
const wordStyle = useMemo(() => {
return {
color: `rgba(255,247,230,${values.fill}%)`,
WebkitTextStroke: `${values.sw}px #17141a`
} as Record<string, string>;
}, [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"><span className={styles.word} style={wordStyle}>GO</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}>-webkit-text-stroke:</span> {values.sw}px #17141a; <span className={styles.prop}>color:</span> rgba(255,247,230,{values.fill}%)
</code>
<button className={styles.copy} type="button" onClick={copy}>복사</button>
</div>
</div>
);
}07 Text outline weight — Measured area 2.958% · moving frames 22/23Original by GODRICH · SCSS and React ship in the zip · CSS Generator: 9 Sliders That Write the Code
The post this demo lives in
CSS Generator: 9 Sliders That Write the CodeA CSS generator is a small panel that turns a CSS value into a control you can move: drag a slider, read the code. Nine See all demos in this post


