統計カード

指標名と大きな数値、前期比バッジ、簡易スパークラインを備えたダッシュボード用の統計カード。読み込み時に数値がカウントアップし、折れ線が滑らかに描画されます。

#css#js#card#dashboard

ライブデモ

コード

HTML
<!-- 統計カード: 指標+カウントアップ+前期比バッジ+簡易スパークライン -->
<div class="stage">
  <article class="st-card">
    <div class="st-card__head">
      <p class="st-card__label">月間アクティブユーザー</p>
      <span class="st-card__live"><i aria-hidden="true"></i>LIVE</span>
    </div>

    <div class="st-card__value-row">
      <span class="st-card__value" data-target="84210">0</span>
      <span class="st-card__badge st-card__badge--up">▲ 12.4%</span>
    </div>
    <p class="st-card__sub">前月比 ・ 先月 74,930</p>

    <svg class="st-card__spark" viewBox="0 0 240 64" preserveAspectRatio="none" aria-hidden="true">
      <defs>
        <linearGradient id="stFill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stop-color="#34d399" stop-opacity=".45"></stop>
          <stop offset="100%" stop-color="#34d399" stop-opacity="0"></stop>
        </linearGradient>
      </defs>
      <path class="st-card__spark-fill" d="M0,46 L20,42 L40,44 L60,34 L80,38 L100,26 L120,30 L140,20 L160,24 L180,14 L200,18 L220,8 L240,10 L240,64 L0,64 Z" fill="url(#stFill)"></path>
      <path class="st-card__spark-line" d="M0,46 L20,42 L40,44 L60,34 L80,38 L100,26 L120,30 L140,20 L160,24 L180,14 L200,18 L220,8 L240,10" fill="none" stroke="#34d399" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"></path>
    </svg>

    <div class="st-card__mini">
      <div><span>新規登録</span><b>1,204</b></div>
      <div><span>継続率</span><b>92.6%</b></div>
    </div>
  </article>
</div>
CSS
/* 統計カード */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 20px;
  display: grid;
  place-items: center;
  font-family: "Hiragino Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 18% 18%, #1c2a5e 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, #3b1f57 0%, transparent 55%),
    #0a0e1c;
  color: #eef0fb;
}

.stage { display: grid; place-items: center; }

.st-card {
  width: min(320px, 88vw);
  padding: 24px 24px 22px;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .02));
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
  backdrop-filter: blur(6px);
  transition: transform .3s cubic-bezier(.22,1,.36,1), box-shadow .3s ease, border-color .3s ease;
}
.st-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .5);
  border-color: rgba(255, 255, 255, .16);
}

.st-card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.st-card__label { margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: .03em; color: #9aa3c7; }
.st-card__live { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 800; letter-spacing: .08em; color: #6ee7b7; white-space: nowrap; }
.st-card__live i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
  animation: st-pulse 1.6s ease-in-out infinite;
}
@keyframes st-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52, 211, 153, .5); }
  50% { opacity: .5; box-shadow: 0 0 0 4px rgba(52, 211, 153, 0); }
}

.st-card__value-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.st-card__value { font-size: 38px; font-weight: 900; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.st-card__badge { font-size: 11.5px; font-weight: 800; padding: 4px 9px; border-radius: 999px; }
.st-card__badge--up { color: #34d399; background: rgba(52, 211, 153, .14); }

.st-card__sub { margin: 6px 0 16px; font-size: 11.5px; color: #7a83a8; }

.st-card__spark { width: 100%; height: 64px; display: block; margin-bottom: 16px; }
.st-card__spark-line {
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: st-draw 1.6s .4s cubic-bezier(.22,1,.36,1) forwards;
}
.st-card__spark-fill {
  opacity: 0;
  animation: st-fade .8s .9s ease forwards;
}
@keyframes st-draw { to { stroke-dashoffset: 0; } }
@keyframes st-fade { to { opacity: 1; } }

.st-card__mini { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }
.st-card__mini div { display: flex; flex-direction: column; gap: 3px; }
.st-card__mini span { font-size: 10.5px; color: #7a83a8; }
.st-card__mini b { font-size: 15px; font-weight: 800; color: #eef0fb; }

@media (prefers-reduced-motion: reduce) {
  .st-card { transition: none; }
  .st-card__live i { animation: none; }
  .st-card__spark-line, .st-card__spark-fill { animation: none; stroke-dashoffset: 0; opacity: 1; }
}
JavaScript
// 数値のカウントアップ演出(前期比バッジ・スパークラインは読み込み時にCSSで自動再生)
(() => {
  const el = document.querySelector('.st-card__value');
  if (!el) return;

  const target = Number(el.dataset.target || '0');
  if (!Number.isFinite(target) || target <= 0) { el.textContent = String(target); return; }

  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  if (reduce) { el.textContent = target.toLocaleString('ja-JP'); return; }

  const DURATION = 1600;
  let start = null;

  const tick = (ts) => {
    if (start === null) start = ts;
    const p = Math.min(1, (ts - start) / DURATION);
    const eased = 1 - Math.pow(1 - p, 3); // easeOutCubic
    el.textContent = Math.round(target * eased).toLocaleString('ja-JP');
    if (p < 1) requestAnimationFrame(tick);
  };
  requestAnimationFrame(tick);
})();

🤖 AIエージェント用プロンプト

このままコピーしてAIに貼り付け「追加する場所」だけ書き換えればOK
あなたは熟練のフロントエンドエンジニアです。私のWebサイトに「統計カード」の効果を追加してください。

# 追加してほしい効果
統計カード(カード & テーブル)
指標名と大きな数値、前期比バッジ、簡易スパークラインを備えたダッシュボード用の統計カード。読み込み時に数値がカウントアップし、折れ線が滑らかに描画されます。

# 追加する場所
👉【ここに対象箇所を記入:例「トップのヒーローセクション」「お問い合わせボタン」「記事カードの一覧」など】

# 参考実装(この見た目・挙動を再現してください)
【HTML】
<!-- 統計カード: 指標+カウントアップ+前期比バッジ+簡易スパークライン -->
<div class="stage">
  <article class="st-card">
    <div class="st-card__head">
      <p class="st-card__label">月間アクティブユーザー</p>
      <span class="st-card__live"><i aria-hidden="true"></i>LIVE</span>
    </div>

    <div class="st-card__value-row">
      <span class="st-card__value" data-target="84210">0</span>
      <span class="st-card__badge st-card__badge--up">▲ 12.4%</span>
    </div>
    <p class="st-card__sub">前月比 ・ 先月 74,930</p>

    <svg class="st-card__spark" viewBox="0 0 240 64" preserveAspectRatio="none" aria-hidden="true">
      <defs>
        <linearGradient id="stFill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stop-color="#34d399" stop-opacity=".45"></stop>
          <stop offset="100%" stop-color="#34d399" stop-opacity="0"></stop>
        </linearGradient>
      </defs>
      <path class="st-card__spark-fill" d="M0,46 L20,42 L40,44 L60,34 L80,38 L100,26 L120,30 L140,20 L160,24 L180,14 L200,18 L220,8 L240,10 L240,64 L0,64 Z" fill="url(#stFill)"></path>
      <path class="st-card__spark-line" d="M0,46 L20,42 L40,44 L60,34 L80,38 L100,26 L120,30 L140,20 L160,24 L180,14 L200,18 L220,8 L240,10" fill="none" stroke="#34d399" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"></path>
    </svg>

    <div class="st-card__mini">
      <div><span>新規登録</span><b>1,204</b></div>
      <div><span>継続率</span><b>92.6%</b></div>
    </div>
  </article>
</div>

【CSS】
/* 統計カード */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 20px;
  display: grid;
  place-items: center;
  font-family: "Hiragino Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 18% 18%, #1c2a5e 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, #3b1f57 0%, transparent 55%),
    #0a0e1c;
  color: #eef0fb;
}

.stage { display: grid; place-items: center; }

.st-card {
  width: min(320px, 88vw);
  padding: 24px 24px 22px;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .02));
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .4);
  backdrop-filter: blur(6px);
  transition: transform .3s cubic-bezier(.22,1,.36,1), box-shadow .3s ease, border-color .3s ease;
}
.st-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .5);
  border-color: rgba(255, 255, 255, .16);
}

.st-card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.st-card__label { margin: 0; font-size: 12.5px; font-weight: 600; letter-spacing: .03em; color: #9aa3c7; }
.st-card__live { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 800; letter-spacing: .08em; color: #6ee7b7; white-space: nowrap; }
.st-card__live i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
  animation: st-pulse 1.6s ease-in-out infinite;
}
@keyframes st-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52, 211, 153, .5); }
  50% { opacity: .5; box-shadow: 0 0 0 4px rgba(52, 211, 153, 0); }
}

.st-card__value-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.st-card__value { font-size: 38px; font-weight: 900; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.st-card__badge { font-size: 11.5px; font-weight: 800; padding: 4px 9px; border-radius: 999px; }
.st-card__badge--up { color: #34d399; background: rgba(52, 211, 153, .14); }

.st-card__sub { margin: 6px 0 16px; font-size: 11.5px; color: #7a83a8; }

.st-card__spark { width: 100%; height: 64px; display: block; margin-bottom: 16px; }
.st-card__spark-line {
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: st-draw 1.6s .4s cubic-bezier(.22,1,.36,1) forwards;
}
.st-card__spark-fill {
  opacity: 0;
  animation: st-fade .8s .9s ease forwards;
}
@keyframes st-draw { to { stroke-dashoffset: 0; } }
@keyframes st-fade { to { opacity: 1; } }

.st-card__mini { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }
.st-card__mini div { display: flex; flex-direction: column; gap: 3px; }
.st-card__mini span { font-size: 10.5px; color: #7a83a8; }
.st-card__mini b { font-size: 15px; font-weight: 800; color: #eef0fb; }

@media (prefers-reduced-motion: reduce) {
  .st-card { transition: none; }
  .st-card__live i { animation: none; }
  .st-card__spark-line, .st-card__spark-fill { animation: none; stroke-dashoffset: 0; opacity: 1; }
}

【JavaScript】
// 数値のカウントアップ演出(前期比バッジ・スパークラインは読み込み時にCSSで自動再生)
(() => {
  const el = document.querySelector('.st-card__value');
  if (!el) return;

  const target = Number(el.dataset.target || '0');
  if (!Number.isFinite(target) || target <= 0) { el.textContent = String(target); return; }

  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  if (reduce) { el.textContent = target.toLocaleString('ja-JP'); return; }

  const DURATION = 1600;
  let start = null;

  const tick = (ts) => {
    if (start === null) start = ts;
    const p = Math.min(1, (ts - start) / DURATION);
    const eased = 1 - Math.pow(1 - p, 3); // easeOutCubic
    el.textContent = Math.round(target * eased).toLocaleString('ja-JP');
    if (p < 1) requestAnimationFrame(tick);
  };
  requestAnimationFrame(tick);
})();

# 外部ライブラリ
なし(追加ライブラリ不要)

# 守ってほしいこと
- 既存のHTML構造・レイアウト・デザインを壊さないこと。必要に応じてクラス名・色・サイズを私のサイトに合わせて調整してよい。
- クラス名やidが既存と衝突しないよう、必要なら接頭辞で名前空間を分けること。
- レスポンシブ対応と prefers-reduced-motion への配慮を入れること。
- 私のサイトのフレームワーク(React / Vue / 素のHTML など)に合わせて実装すること。不明な場合は素のHTML/CSS/JSで提示し、組み込み手順も説明すること。
- 変更後の確認手順も簡潔に教えてください。