05パーセントリングと数字の同期
1つの整数@propertyが数字テキストとconic-gradientリングの塗り角度を同時に駆動し、常に同じ値を示す。
使いどころ進捗表示、目標達成率、ストレージ使用率
conic-gradient하나의 @property링+숫자 동기

<main class="stage">
<div class="stat">
<div class="ring is-demo">
<span class="ring__num" aria-hidden="true"></span>
<span class="ring__sr">76%</span>
</div>
<span class="stat__label">達成率</span>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
// ── 변수 3개 ──────────────────────────────────────────
$duration: $dur-loop;
$easing: $ease-out;
$color: $subject-cream;
@include stage($stage-ink);
.stat {
display: flex;
flex-direction: column;
align-items: center;
gap: clamp(8px, 2.4vw, 12px);
}
// 정수 하나(--p)가 링의 채움 각도와 숫자 텍스트를 동시에 구동한다
@property --p {
syntax: '<integer>';
initial-value: 0;
inherits: true; // 자식 .ring__num 이 같은 값을 counter-reset 으로 읽는다
}
.ring {
--p: 0;
position: relative;
width: clamp(84px, 22vw, 108px);
aspect-ratio: 1;
border-radius: 50%;
display: grid;
place-items: center;
background: conic-gradient($color calc(var(--p) * 1%), rgba(255, 255, 255, .16) 0);
&::before { // 도넛 구멍 — 무대 색과 같아 링처럼 보인다
content: "";
position: absolute;
inset: 15%;
border-radius: 50%;
background: $stage-ink;
}
&__num {
position: relative;
counter-reset: p var(--p);
font-weight: 800; font-size: clamp(16px, 5vw, 22px); line-height: 1; font-family: inherit;
font-variant-numeric: tabular-nums;
color: $color;
&::before { content: counter(p) "%"; }
}
&__sr {
position: absolute;
width: 1px; height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
}
.stat__label {
font-weight: 600; font-size: clamp(12px, 3.4vw, 15px); line-height: 1; font-family: inherit;
color: rgba(255, 255, 255, .6);
}
.ring.is-demo {
animation: percent-up $duration $easing infinite;
}
@keyframes percent-up {
0% { --p: 0; }
65% { --p: 76; }
100% { --p: 76; }
}
@media (prefers-reduced-motion: reduce) {
.ring.is-demo { animation: none; --p: 76; }
}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);
}
.stat {
display: flex;
flex-direction: column;
align-items: center;
gap: clamp(8px, 2.4vw, 12px);
}
@property --p {
syntax: "<integer>";
initial-value: 0;
inherits: true;
}
.ring {
--p: 0;
position: relative;
width: clamp(84px, 22vw, 108px);
aspect-ratio: 1;
border-radius: 50%;
display: grid;
place-items: center;
background: conic-gradient(#fff7e6 calc(var(--p) * 1%), rgba(255, 255, 255, 0.16) 0);
}
.ring::before {
content: "";
position: absolute;
inset: 15%;
border-radius: 50%;
background: #17141a;
}
.ring__num {
position: relative;
counter-reset: p var(--p);
font-weight: 800;
font-size: clamp(16px, 5vw, 22px);
line-height: 1;
font-family: inherit;
font-variant-numeric: tabular-nums;
color: #fff7e6;
}
.ring__num::before {
content: counter(p) "%";
}
.ring__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.stat__label {
font-weight: 600;
font-size: clamp(12px, 3.4vw, 15px);
line-height: 1;
font-family: inherit;
color: rgba(255, 255, 255, 0.6);
}
.ring.is-demo {
animation: percent-up 2s ease-out infinite;
}
@keyframes percent-up {
0% {
--p: 0;
}
65% {
--p: 76;
}
100% {
--p: 76;
}
}
@media (prefers-reduced-motion: reduce) {
.ring.is-demo {
animation: none;
--p: 76;
}
}import type { CSSProperties } from "react";
import styles from "./PercentRingCounter.module.scss";
export type PercentRingCounterProps = {
/** 0~100 */
percent: number;
label: string;
duration?: number;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string; "--p-target"?: number };
export default function PercentRingCounter({
percent, label, duration = 2000, easing = "ease-out", color = "#fff7e6",
}: PercentRingCounterProps) {
const vars: Vars = {
"--duration": `${duration}ms`,
"--easing": easing,
"--color": color,
"--p-target": percent,
};
return (
<div className={styles.stat}>
<div className={styles.ring} style={vars}>
<span className={styles.num} aria-hidden="true" />
<span className={styles.sr}>{percent}%</span>
</div>
<span className={styles.label}>{label}</span>
</div>
);
}05 パーセントリングと数字の同期 — 計測 累積面積 2.993% · 動いたフレーム 15/23GODRICH オリジナル · SCSS と React は zip に同梱 · CSS 数字 カウントアップ アニメーション9選 — 一行でコピペOK
このデモが属する記事
CSS 数字 カウントアップ アニメーション9選 — 一行でコピペOKcss 数字 カウントアップは、0や開始値から目標の数字まで上がっていくテキストを、JavaScriptなしでCSSのカスタムプロパティだけで数える手法です。9つのうち1つは逆に0へ向かって減っていき、別の1つはスクロールして画面に入るまで この記事のデモをすべて見る


