タイトル: sup要素で上付き文字を表示する
SEOタイトル: HTML sup要素の使い方(脚注 / 数式 / 商標 / 序数)と sub / CSS vertical-align との関係
この本文には実行可能なタグ等が含まれるため、安全のためHTMLソースとして表示しています。本文データは変更していません。
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;background:#fffbea;border:1px solid #f4c430;margin:1em 0;width:100%"><tr><td style="background:#f4c430;color:#000;font-weight:bold;padding:8px">この記事の要点</td></tr><tr><td style="padding:10px"><ul><li><strong><code><sup></code></strong> は上付き文字、対になる <strong><code><sub></code></strong> は下付き文字を表す HTML 要素</li><li>典型用途: <strong>脚注番号</strong> [1] / <strong>累乗</strong> E=mc<sup>2</sup> / <strong>商標</strong> TM / <strong>序数</strong> 1st / <strong>化学式</strong> H₂O(こちらは sub)</li><li>見た目だけが目的なら CSS <code>vertical-align: super</code> で十分。<strong>意味があるとき</strong> sup 要素を使う</li><li>sup の中の文字はフォントサイズが約 0.75 倍に縮む → 累乗が読みにくい時は <strong>MathML / KaTeX</strong> を検討</li><li>脚注パターンは <code><sup><a href="#fn1">[1]</a></sup></code> のように<strong>クリック可能</strong>にする</li></ul></td></tr></table>
<h2>sup の基本</h2>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-html"><!-- 累乗(指数) -->
<p>E = mc<sup>2</sup></p>
<p>2<sup>10</sup> = 1024</p>
<!-- 商標 -->
<p>Coca-Cola<sup>®</sup></p>
<p>iPhone<sup>™</sup></p>
<!-- 序数 -->
<p>The 1<sup>st</sup> place winner</p>
<p>21<sup>st</sup> century</p>
<!-- 脚注 -->
<p>これは重要な事実である<sup><a href="#fn1">[1]</a></sup>。</p></code></pre>
<h2>sub との対</h2>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-html"><!-- 化学式 -->
<p>H<sub>2</sub>O は水、CO<sub>2</sub> は二酸化炭素。</p>
<!-- 数学の添え字 -->
<p>x<sub>1</sub>, x<sub>2</sub>, ..., x<sub>n</sub></p>
<!-- 上下を組み合わせ -->
<p>a<sub>i</sub><sup>2</sup> ← i 番目の要素の二乗</p></code></pre>
<h2>典型用途の早見表</h2>
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;width:100%">
<thead><tr style="background:#e3f2fd"><th>用途</th><th>例</th><th>マークアップ</th></tr></thead>
<tbody>
<tr><td>累乗</td><td>2¹⁰</td><td><code>2<sup>10</sup></code></td></tr>
<tr><td>添え字</td><td>x₁</td><td><code>x<sub>1</sub></code></td></tr>
<tr><td>分数の分子</td><td>½</td><td>独自実装または ½(Unicode 文字)</td></tr>
<tr><td>商標®</td><td>X®</td><td><code>X<sup>®</sup></code></td></tr>
<tr><td>登録商標™</td><td>X™</td><td><code>X<sup>™</sup></code></td></tr>
<tr><td>序数</td><td>1st, 2nd, 3rd</td><td><code>1<sup>st</sup></code></td></tr>
<tr><td>脚注</td><td>本文[1]</td><td><code><sup><a href="#fn1">[1]</a></sup></code></td></tr>
<tr><td>同位体</td><td>¹⁴C</td><td><code><sup>14</sup>C</code></td></tr>
</tbody>
</table>
<h2>脚注パターンの実装</h2>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-html"><article>
<p>
JavaScript は世界で最も人気のあるプログラミング言語である
<sup><a href="#fn1" id="ref1">[1]</a></sup>。
</p>
<p>
一方、HTML5 は 2014 年に W3C で勧告された
<sup><a href="#fn2" id="ref2">[2]</a></sup>。
</p>
<footer>
<h2>脚注</h2>
<ol>
<li id="fn1">
Stack Overflow Developer Survey 2024
<a href="#ref1" aria-label="戻る">↩</a>
</li>
<li id="fn2">
W3C HTML5 Recommendation (2014-10-28)
<a href="#ref2" aria-label="戻る">↩</a>
</li>
</ol>
</footer>
</article></code></pre>
<h2>CSS vertical-align との違い</h2>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-css">/* 見た目だけ上付きにする(意味は変えない) */
.super-look {
vertical-align: super;
font-size: .75em;
}
/* sup 要素のデフォルトスタイルは実質これ */
sup {
vertical-align: super;
font-size: smaller;
line-height: 0; /* ★ 行間を増やさないテクニック */
}</code></pre>
<p><strong>意味の有無</strong>で使い分けます:</p>
<ul>
<li><strong>累乗 / 化学式 / 脚注 / 商標 / 同位体</strong> → 意味があるので <code><sup></code> / <code><sub></code></li>
<li><strong>デザイン的に文字をちょっと上に動かしたいだけ</strong> → CSS の <code>vertical-align</code></li>
</ul>
<h2>sup が行間を広げる問題</h2>
<p>そのまま <code><sup></code> を使うと、その行だけ<strong>行の高さが広がる</strong>ことがあります。<code>line-height: 0</code> で抑えるテクニック:</p>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-css">sup, sub {
font-size: .75em;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup { top: -0.5em; }
sub { bottom: -0.25em; }</code></pre>
<h2>MathML / KaTeX との比較</h2>
<p>累乗や添え字が複雑になる本格的な数式は <code><sup></code> / <code><sub></code> ではすぐ限界が来ます。専用技術を検討:</p>
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;width:100%">
<thead><tr style="background:#e3f2fd"><th>技術</th><th>特徴</th></tr></thead>
<tbody>
<tr><td><code><sup></code> / <code><sub></code></td><td>シンプル。1〜2 段の累乗 / 添え字向け。CSS で見た目調整</td></tr>
<tr><td>MathML</td><td>W3C 標準の数式マークアップ。Chrome 109+ / Safari / Firefox 対応</td></tr>
<tr><td>KaTeX / MathJax</td><td>LaTeX 風記法を JS でレンダリング。複雑な数式に対応</td></tr>
<tr><td>画像</td><td>最終手段。検索や選択不可</td></tr>
</tbody>
</table>
<h3>MathML 例</h3>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-html"><math>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<msup>
<mi>y</mi>
<mn>2</mn>
</msup>
<mo>=</mo>
<msup>
<mi>r</mi>
<mn>2</mn>
</msup>
</math></code></pre>
<h2>アクセシビリティ</h2>
<ul>
<li>スクリーンリーダーは sup の中身を<strong>そのまま読み上げる</strong>(「2 の 10 乗」とは読まれない)</li>
<li>「2<sup>10</sup>」は「2 10」と読まれる → 必要なら <code>aria-label="2 の 10 乗"</code></li>
<li>脚注リンクは <code>aria-describedby</code> で説明を関連付けるとより親切</li>
</ul>
<pre style="background:#1e293b;color:#e2e8f0;padding:1em;border-radius:6px;overflow-x:auto;line-height:1.5"><code class="language-html"><p>
これは事実だ<sup><a href="#fn1" aria-describedby="fn1-text">[1]</a></sup>
</p>
<p id="fn1-text" hidden>脚注 1: 出典 ABC 2024</p></code></pre>
<h2>Unicode の上付き文字との比較</h2>
<p>Unicode には上付き専用文字(U+00B2 ² など)も存在しますが、<strong>使える数字や文字が限られる</strong>ため、自由な内容には <code><sup></code> を使うほうが汎用的です。</p>
<table border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;width:100%">
<thead><tr style="background:#e3f2fd"><th>方式</th><th>例</th><th>使い分け</th></tr></thead>
<tbody>
<tr><td>Unicode 文字</td><td>m² / m³ / x⁰ ⁺ ⁻ ⁼ ⁽ ⁾</td><td>単純な数値・記号で十分なとき</td></tr>
<tr><td><code><sup></code></td><td>x<sup>n</sup> / 1<sup>st</sup></td><td>任意の文字・数式が必要なとき</td></tr>
</tbody>
</table>
<h2>FAQ</h2>
<p><strong>Q: SEO に <code><sup></code> は影響する?</strong><br />
A: ほぼ無し。中身のテキストは普通に検索対象になります。</p>
<p><strong>Q: <code><sup></code> をネストできる?</strong><br />
A: 可能だが、二段累乗(2 の 2 の 10 乗)は読みづらくなるので MathML / KaTeX 推奨。</p>
<p><strong>Q: 脚注を勝手にスクロールアニメで戻りたい</strong><br />
A: CSS だけで <code>html { scroll-behavior: smooth; }</code> を入れれば、リンクジャンプがアニメ化されます。</p>