Typography

CSS Text Decoration

Styling Text Decorations

CSS text decorations add underline or overline, with color control.

Introduction to CSS Text Decoration

CSS text decoration is a property that allows you to add styling elements such as underlines, overlines, or line-throughs to text. It provides control over the appearance of these decorations and can also alter their color, making it a versatile tool for enhancing typography on your web pages.

Basic Text Decoration Properties

The text-decoration property in CSS can take several values, which dictate the style of the decoration:

  • underline: Adds a line beneath the text.
  • overline: Adds a line above the text.
  • line-through: Adds a line through the middle of the text, often used to signify deleted or discounted content.
  • none: Removes any existing decoration from the text.

Controlling Text Decoration Color

The text-decoration-color property allows you to specify the color of the text decoration separately from the text color. This can be particularly useful for adding emphasis or maintaining a consistent color scheme.

Combining Text Decoration Properties

CSS also allows you to combine multiple text decoration properties into a single declaration using the text-decoration shorthand. This can include style, color, and line properties.

Practical Examples

Consider a scenario where you want to style different headings and paragraphs to make them stand out. Using the text-decoration property, you can achieve a wide range of effects:

Conclusion

By mastering CSS text decoration properties, you can significantly enhance the visual appeal of your web typography. Whether you want to underline links, highlight headers, or strike through outdated information, these properties provide you with the flexibility to style text to your liking.

Previous
Line Height