CSS CSS Tutorial CSS Advanced CSS Responsive Web Design(RWD) CSS Grid CSS Properties Sass Tutorial Sass Functions



text-decoration

The text-decoration property is used to add decorative effects to text. It is a shorthand property that allows you to set the following individual properties:

  • text-decoration-line: specifies the type of decoration to be used (e.g. underline, overline, line-through, etc.)
  • text-decoration-color: specifies the color of the decoration
  • text-decoration-style: specifies the style of the decoration (e.g. solid, dotted, dashed, double, etc.)
  • text-decoration-thickness: specifies the thickness of the decoration

The text-decoration property can be applied to any text element, including headings, paragraphs, links, and spans. It is commonly used to add emphasis to text or to indicate a link.

Examples

Here are some examples of how to use the text-decoration property:

Underline

To underline text, use the text-decoration-line property with a value of underline:

  <p style="text-decoration-line: underline;">This text is underlined.</p>

This text is underlined.

Overline

To add an overline to text, use the text-decoration-line property with a value of overline:

  <p style="text-decoration-line: overline;">This text has an overline.</p>

This text has an overline.

Line-Through

To add a line-through effect to text, use the text-decoration-line property with a value of line-through:

  <p style="text-decoration-line: line-through;">This text has a line-through effect.</p>

This text has a line-through effect.

Color

You can also specify the color of the text decoration using the text-decoration-color property:

  <p style="text-decoration-line: underline; text-decoration-color: red;">This text is underlined and red.</p>

This text is underlined and red.

Style

The text-decoration-style property allows you to specify the style of the text decoration. Here are some examples:

  <p style="text-decoration-line: underline; text-decoration-style: dotted;">This text is underlined with a dotted line.</p>
  <p style="text-decoration-line: underline; text-decoration-style: dashed;">This text is underlined with a dashed line.</p>
  <p style="text-decoration-line: underline; text-decoration-style: double;">This text is underlined with a double line.</p>

This text is underlined with a dotted line.

This text is underlined with a dashed line.

This text is underlined with a double line.

Thickness

The text-decoration-thickness property allows you to specify the thickness of the text decoration. Here are some examples:

  <p style="text-decoration-line: underline; text-decoration-thickness: 1px;">This text is underlined with a 1px thick line.</p>
  <p style="text-decoration-line: underline; text-decoration-thickness: 2px;">This text is underlined with a 2px thick line.</p>
  <p style="text-decoration-line: underline; text-decoration-thickness: 3px;">This text is underlined with a 3px thick line.</p>

This text is underlined with a 1px thick line.

This text is underlined with a 2px thick line.

This text is underlined with a 3px thick line.

Conclusion

The text-decoration property is a versatile way to add decorative effects to text. By using the individual properties that make up the shorthand property, you can customize the type, color, style, and thickness of the text decoration to suit your needs.

References

Activity