The CSS text-decoration-line property is used to display and control decorative lines on text, such as underline, overline, or line-through.
text-decoration-line は、文字に施す装飾ライン(下線や上線、取り消し線など)をどのように描画するかを指定するためのCSSプロパティです。従来、文字の装飾ラインを指定するときは text-decoration プロパティをまとめて使用することが一般的でした。しかし、CSS Text Decoration Module Level 3 以降では、装飾に関わる各種プロパティ(text-decoration-line, text-decoration-color, text-decoration-styleなど)が分割され、より細かく制御できるようになりました。
text-decoration)text-decoration: underline wavy red;text-decoration-line, text-decoration-style, text-decoration-color)CSS
.element {
text-decoration-line: underline;
}
CSSで .element クラスに対して下線を引きたい場合は、このように指定します。
text-decoration-line で指定できる主な値は以下のとおりです。
※ blink について
過去の仕様で blink が存在したことがありますが、ほとんどのモダンブラウザで非対応・廃止されています。仕様上は存在していた経緯もあるため、古い資料には記載が残っていることがある点に注意しましょう。
CSS Text Decoration Level 3 から、複数の値を同時に指定することが可能です。例えば下線と上線を同時に引くには以下のように書きます。
CSS
.element {
text-decoration-line: underline overline;
}
このようにスペース区切りで複数のラインを指定すると、下線と上線が両方適用されます。
CSS
.element {
text-decoration: underline overline dotted red;
}
text-decoration-line にあたる部分:underline overlinetext-decoration-style にあたる部分:dottedtext-decoration-color にあたる部分:redショートハンドを使うメリットは、1行でまとめて書ける点です。逆に、個別プロパティを使うメリットは、必要なプロパティだけを詳細に制御できるため、可読性や保守性が高まることです。プロジェクトの規模や目的に合わせて使い分けると良いでしょう。
text-decoration-line を活用するときは、以下のプロパティと組み合わせるケースが多いです。
テキスト装飾ラインの色を指定します。例えば、下線だけ赤くしたい場合は以下のようにします。
CSS
.element {
text-decoration-line: underline;
text-decoration-color: red;
}
同様に、ショートハンドを使うと
CSS
.element {
text-decoration: underline red;
}
と書くこともできます。
テキスト装飾ラインのスタイル(線の種類)を指定します。指定可能な値には以下のものがあります。
solid : 実線(デフォルト)double : 二重線dotted : 点線dashed : 破線wavy : 波線例:
CSS
.element {
text-decoration-line: underline;
text-decoration-color: #ff6600;
text-decoration-style: wavy;
}
上記の例では、波線状のオレンジ色の下線が引かれます。
トレンド情報まとめ
HTML
<h2 class="highlighted-title">トレンド情報まとめ</h2>
CSS
.highlighted-title {
text-decoration-line: underline;
text-decoration-style: double;
text-decoration-color: #0000ff;
}
ポイント:
HTML
<a href="#" class="custom-link">詳細はこちら</a>
CSS
.custom-link {
text-decoration-line: underline overline;
text-decoration-style: wavy;
text-decoration-color: #ff0000;
}
ポイント:
underline + overline + line-through を全部重ねて指定することも技術的には可能ですが、過度に装飾しすぎるとテキストが読みにくくなるので注意が必要です。line-height)と組み合わせた場合、装飾ラインが他の行と重なってしまうことがあります。デザイン上、意図しない見た目にならないように、line-height を十分に確保したり、場合によっては要素のマージンやパディングで余白を調整する必要があります。CSS
@media (max-width: 600px) {
.custom-link {
text-decoration-line: underline; /* スマホでは上線を外すなど */
}
}
text-decoration-line はほぼ問題なくサポートされています。text-decoration-line がサポートされていない場合があります。IE11 などのレガシーブラウザサポートが必要な場合は、ショートハンドの text-decoration を併用するか、polyfill を検討してください。none, underline, overline, line-through を単独あるいは組み合わせて使います。text-decoration ショートハンドを使うと簡潔に書けますが、個別プロパティ(text-decoration-line, text-decoration-color, text-decoration-style)を使うと、より細かく制御できて、可読性も上がる場合があります。text-decoration-color や text-decoration-style と組み合わせることで、カラーや線の種類を自在にカスタマイズ可能です。text-decoration-line は、テキストにおける装飾ラインの種類を直接指定するプロパティであり、従来のショートハンドよりも細かい制御が可能です。初学者の方はまず「下線を引く」「取り消し線を引く」といったシンプルな用途から始め、徐々に複数ラインやカラー、波線スタイルなど応用範囲を広げてみましょう。中級者以上の方は、他のレイアウトプロパティやアクセシビリティ、ブラウザ互換性と組み合わせた最適な使い方を身につけると、より洗練されたUIデザインを実現できます。
Web制作において、「テキスト強調」はユーザーの視線誘導や可読性に深く関わります。text-decoration-line はその重要な要素の一つです。記事やサイトで文字を際立たせたいとき、あるいはユーザーに明確なシグナルを与えたいとき、ぜひ適切なライン装飾を検討してみてください。