テキストアウトライン(中抜き文字)

-webkit-text-stroke で塗りのない輪郭文字を作り、塗りレイヤーと重ねてホバーで色が流れ込みます。バナーやポップな見出しに使えます。

#css#stroke#hover

ライブデモ

使用例(お題: アイドルグループ Sakura)

この技法を「アイドルグループ Sakura」というテーマのダミーサイトで実際に使った例です。

HTML
<div class="page">
  <header class="nav">
    <div class="brand"><span class="petal"></span>Sakura</div>
    <nav class="links"><a>MEMBER</a><a>LIVE</a><a>NEWS</a></nav>
  </header>

  <section class="hero">
    <p class="eyebrow">2nd ANNIVERSARY TOUR</p>
    <h1 class="outline" data-text="満開、いこう。">
      <span class="fill">満開、いこう。</span>
    </h1>
    <p class="lead">桜が贈る、春のワンマンツアー開幕。<br>全国5都市をめぐる、最高のステージへ。</p>
    <a class="btn">チケット先行受付中</a>
  </section>
</div>
CSS
/* Sakura:中抜き文字バナーが主役 */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Yu Gothic", "Hiragino Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(600px 320px at 50% -10%, #ffe3ec 0%, transparent 60%),
    linear-gradient(165deg, #fff5f8 0%, #ffe9f0 100%);
  color: #5a3a46;
  min-height: 400px;
  overflow: hidden;
}
.page { padding: 16px 26px; }

.nav { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; color: #e8638c; letter-spacing: 0.04em; }
.petal {
  width: 15px; height: 15px;
  background: #ffd1e0;
  border-radius: 50% 0 50% 50%;
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(232,99,140,0.4);
}
.links { display: flex; gap: 16px; }
.links a { font-size: 12px; font-weight: 700; color: #c97a93; cursor: pointer; letter-spacing: 0.08em; }
.links a:hover { color: #e8638c; }

.hero { text-align: center; padding: 30px 6px 0; }
.eyebrow { font-size: 11px; letter-spacing: 0.26em; color: #e8638c; font-weight: 700; }

/* 中抜き文字バナー本体 */
.outline {
  position: relative;
  margin-top: 16px;
  font-size: clamp(36px, 8.5vw, 64px);
  font-weight: 900; line-height: 1.1; letter-spacing: 0.02em;
  /* 輪郭のみ(塗りなし) */
  color: transparent;
  -webkit-text-stroke: 2px #e8638c;
}
/* ホバーで色が流れ込む塗りレイヤー */
.outline .fill {
  position: absolute; inset: 0;
  color: #e8638c;
  -webkit-text-stroke: 0;
  /* 下から塗りつぶしていく */
  clip-path: inset(100% 0 0 0);
  transition: clip-path 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  background: linear-gradient(180deg, #ffd1e0, #e8638c);
  -webkit-background-clip: text;
  background-clip: text;
}
.outline:hover .fill { clip-path: inset(0 0 0 0); }

.lead { margin-top: 18px; font-size: 13.5px; line-height: 1.8; color: #8a6573; }
.btn {
  display: inline-block; margin-top: 22px;
  background: #e8638c; color: #fff;
  padding: 11px 26px; border-radius: 24px;
  font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 10px 24px rgba(232,99,140,0.35);
}
.btn:hover { background: #f178a0; }

@media (prefers-reduced-motion: reduce) {
  .outline .fill { transition: none; }
}
JavaScript
// タップ端末向け:見出しタップでも塗りを流し込む
(function () {
  const title = document.querySelector('.outline');
  const fill = document.querySelector('.outline .fill');
  if (!title || !fill) return; // null安全

  let on = false;
  title.addEventListener('click', () => {
    // ホバーできない端末でもトグルで体験できるように
    on = !on;
    fill.style.clipPath = on ? 'inset(0 0 0 0)' : 'inset(100% 0 0 0)';
  });
})();

コード

HTML
<main class="stage">
  <div class="stack">
    <!-- 同じ文字を重ねて、塗り→アウトラインの抜けを演出 -->
    <h1 class="outline-word filled">BOLD</h1>
    <h1 class="outline-word hollow" aria-hidden="true">BOLD</h1>
  </div>
  <p class="caption">text-stroke で中抜き文字</p>
</main>
CSS
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  min-height: 360px;
  display: grid;
  place-items: center;
  font-family: "Arial Black", "Segoe UI", system-ui, sans-serif;
  /* 斜めストライプの効いたポップな背景 */
  background:
    repeating-linear-gradient(45deg, #ffd84d 0 22px, #ffcf2e 22px 44px);
  overflow: hidden;
}

.stage { text-align: center; }

/* 2枚の文字を同位置に重ねるためのレイヤー */
.stack {
  position: relative;
  display: inline-grid;
}
.stack .outline-word {
  grid-area: 1 / 1; /* 完全に重ねる */
}

.outline-word {
  font-size: clamp(64px, 18vw, 150px);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1;
}

/* 下層: 黒塗り+少しズラした影で厚みを出す */
.filled {
  color: #16161a;
  transform: translate(6px, 6px);
}

/* 上層: 塗りなしの中抜き(アウトライン) */
.hollow {
  color: transparent;
  -webkit-text-stroke: 3px #16161a;
  text-stroke: 3px #16161a;
  /* 待機時は背景塗りを出さず、純粋なアウトラインだけを見せる。
     クリップ用の塗りはホバー時に流し込む */
  background-image: none;
  background-size: 200% 100%;
  background-position: 100% 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  transition: background-position .55s ease, -webkit-text-stroke-color .35s ease;
}
/* ホバーで塗りが左から流れ込み、輪郭が消えてベタ塗りに */
.stack:hover .hollow {
  background-image: linear-gradient(120deg, #ff5470, #ff8c42);
  background-position: 0% 0;
  -webkit-text-stroke-color: transparent;
  text-stroke-color: transparent;
}

.caption {
  margin-top: 26px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: #16161a;
}

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

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

# 追加してほしい効果
テキストアウトライン(中抜き文字)(タイポグラフィ)
-webkit-text-stroke で塗りのない輪郭文字を作り、塗りレイヤーと重ねてホバーで色が流れ込みます。バナーやポップな見出しに使えます。

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

# 参考実装(この見た目・挙動を再現してください)
【HTML】
<main class="stage">
  <div class="stack">
    <!-- 同じ文字を重ねて、塗り→アウトラインの抜けを演出 -->
    <h1 class="outline-word filled">BOLD</h1>
    <h1 class="outline-word hollow" aria-hidden="true">BOLD</h1>
  </div>
  <p class="caption">text-stroke で中抜き文字</p>
</main>

【CSS】
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  min-height: 360px;
  display: grid;
  place-items: center;
  font-family: "Arial Black", "Segoe UI", system-ui, sans-serif;
  /* 斜めストライプの効いたポップな背景 */
  background:
    repeating-linear-gradient(45deg, #ffd84d 0 22px, #ffcf2e 22px 44px);
  overflow: hidden;
}

.stage { text-align: center; }

/* 2枚の文字を同位置に重ねるためのレイヤー */
.stack {
  position: relative;
  display: inline-grid;
}
.stack .outline-word {
  grid-area: 1 / 1; /* 完全に重ねる */
}

.outline-word {
  font-size: clamp(64px, 18vw, 150px);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1;
}

/* 下層: 黒塗り+少しズラした影で厚みを出す */
.filled {
  color: #16161a;
  transform: translate(6px, 6px);
}

/* 上層: 塗りなしの中抜き(アウトライン) */
.hollow {
  color: transparent;
  -webkit-text-stroke: 3px #16161a;
  text-stroke: 3px #16161a;
  /* 待機時は背景塗りを出さず、純粋なアウトラインだけを見せる。
     クリップ用の塗りはホバー時に流し込む */
  background-image: none;
  background-size: 200% 100%;
  background-position: 100% 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  transition: background-position .55s ease, -webkit-text-stroke-color .35s ease;
}
/* ホバーで塗りが左から流れ込み、輪郭が消えてベタ塗りに */
.stack:hover .hollow {
  background-image: linear-gradient(120deg, #ff5470, #ff8c42);
  background-position: 0% 0;
  -webkit-text-stroke-color: transparent;
  text-stroke-color: transparent;
}

.caption {
  margin-top: 26px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3em;
  color: #16161a;
}

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

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