Spec-Zone.ru › CSS

Свойство CSS `text-decoration`

Базовая поддержка Широко доступно

Эта возможность хорошо зарекомендовала себя и работает на многих устройствах и в разных версиях браузеров. Она доступна во всех браузерах с июля 2015 года.

text-decoration — CSS-свойство сокращённой записи, которое задаёт внешний вид декоративных линий текста. Это сокращённая запись свойств text-decoration-line, text-decoration-color, text-decoration-style и более нового свойства text-decoration-thickness.

Текстовые декорации отображаются поверх текста дочерних элементов. Это означает, что если для элемента задана текстовая декорация, дочерний элемент не может её убрать. Например, в разметке <p>This text has <em>some emphasized words</em> in it.</p> правило стиля p { text-decoration: underline; } подчёркивает весь абзац. Правило стиля em { text-decoration: none; } ничего не изменит: весь абзац по-прежнему будет подчёркнут. Однако правило em { text-decoration: overline; } добавит ещё одну декорацию к фразе «некоторых выделенных слов».

Попробуйте

text-decoration: underline;
text-decoration: underline dotted;
text-decoration: underline dotted red;
text-decoration: green wavy underline;
text-decoration: underline overline #ff3028;
<section id="default-example">
  <p>
    I'd far rather be
    <span class="transition-all" id="example-element">happy than right</span>
    any day.
  </p>
</section>
p {
  font: 1.5em sans-serif;
}

Составные свойства

Это свойство является сокращённой записью следующих свойств CSS:

  • text-decoration-color
  • text-decoration-line
  • text-decoration-style
  • text-decoration-thickness

Синтаксис

text-decoration: underline;
text-decoration: overline red;
text-decoration: none;

/* Global values */
text-decoration: inherit;
text-decoration: initial;
text-decoration: revert;
text-decoration: revert-layer;
text-decoration: unset;

Свойство text-decoration задаётся одним или несколькими значениями, разделёнными пробелами и представляющими различные свойства text-decoration с полными именами.

Значения

text-decoration-line
Задаёт тип используемой декорации, например underline или line-through.
text-decoration-color
Задаёт цвет декорации.
text-decoration-style
Задаёт стиль линии декорации, например solid, wavy или dashed.
text-decoration-thickness
Задаёт толщину линии декорации.

Формальное определение

Исходное значение как у каждого из свойств сокращённой записи:
  • text-decoration-color
  • text-decoration-style
  • text-decoration-line
Применяется к всем элементам
Наследуется нет
Вычисленное значение как у каждого из свойств сокращённой записи:
  • text-decoration-line
  • text-decoration-style
  • text-decoration-color
  • text-decoration-thickness
Тип анимации как у каждого из свойств сокращённой записи:
  • text-decoration-color
  • text-decoration-style
  • text-decoration-line
  • text-decoration-thickness

Формальный синтаксис

text-decoration = 
  <'text-decoration-line'> ||
  <'text-decoration-style'> ||
  <'text-decoration-color'> ||
  <'text-decoration-thickness'>

Примеры

Демонстрация значений text-decoration

.under {
  text-decoration: underline red;
}

.over {
  text-decoration: wavy overline lime;
}

.line {
  text-decoration: line-through;
}

.plain {
  text-decoration: none;
}

.underover {
  text-decoration: dashed underline overline;
}

.thick {
  text-decoration: solid underline purple 4px;
}

.blink {
  text-decoration: blink;
}
<p class="under">This text has a line underneath it.</p>
<p class="over">This text has a line over it.</p>
<p class="line">This text has a line going through it.</p>
<p>
  This <a class="plain" href="#">link will not be underlined</a>, as links
  generally are by default. Be careful when removing the text decoration on
  anchors since users often depend on the underline to denote hyperlinks.
</p>
<p class="underover">This text has lines above <em>and</em> below it.</p>
<p class="thick">
  This text has a really thick purple underline in supporting browsers.
</p>
<p class="blink">
  This text might blink for you, depending on the browser you use.
</p>

Результат

Спецификации

Спецификация
Модуль CSS Text Decoration, уровень 4
# text-decoration-property
Масштабируемая векторная графика (SVG) 2
# TextDecorationProperties

Совместимость с браузерами

Компьютеры Мобильные устройства
Chrome Edge Firefox Opera Safari Chrome для Android Firefox для Android Opera для Android Safari на iOS Samsung Internet WebView для Android WebView на iOS
text-decoration
1
12
1
3.5
1
18
4
10.1
1
1.0
4.4
1
auto
87
87
70
73
26.2
87
79
62
26.2
14.0
87
26.2
blink
≤31Значение blink не оказывает никакого эффекта.
12
3Значение blink не оказывает никакого эффекта.
≤18Значение blink не оказывает никакого эффекта.
1Значение blink не оказывает никакого эффекта.
≤31Значение blink не оказывает никакого эффекта.
4Значение blink не оказывает никакого эффекта.
≤18Значение blink не оказывает никакого эффекта.
1Значение blink не оказывает никакого эффекта.
≤2.0Значение blink не оказывает никакого эффекта.
≤4.4.3Значение blink не оказывает никакого эффекта.
1Значение blink не оказывает никакого эффекта.
currentColor
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2
dashed
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2
dotted
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2
double
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2
from-font
87
87
70
73
26.2
87
79
62
26.2
14.0
87
26.2
grammar-error
121
121
137
107
26.2
121
137
81
26.2
25.0
121
26.2
includes_color-and-style
57
79
6
44
26.2
8
57
6
43
26.2
8
7.0
57
26.2
8
includes_thickness
87
87
70
73
26.2
87
79
62
26.2
14.0
87
26.2
line-through
1
12
3
15
1
18
4
14
1
1.0
4.4
1
none
1
12
3
15
1
18
4
14
1
1.0
4.4
1
overline
1
12
3
15
1
18
4
14
1
1.0
4.4
1
solid
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2
spelling-error
121
121
137
107
26.2
121
137
81
26.2
25.0
121
26.2
transparent
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2
underline
1
12
3
15
1
18
4
14
1
1.0
4.4
1
wavy
57
79
≤50
44
26.2
57
≤50
43
26.2
7.0
57
26.2

См. также

  • Отдельные свойства text-decoration: text-decoration-line, text-decoration-color, text-decoration-style и text-decoration-thickness.
  • Свойства text-decoration-skip-ink, text-underline-offset и text-underline-position также влияют на text-decoration, но не входят в сокращённую запись.
  • Свойство list-style управляет внешним видом элементов в HTML-списках <ol> и <ul>.
  • Атрибут SVG text-decoration

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/text-decoration

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API