- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS Text-Decoration-Style Enhance Text Visuals
Learn how to use this powerful CSS property to make your text more engaging and user-friendly.
CSS text-decoration-style
Property
Introduction
The text-decoration-style
property in CSS allows you to customize the appearance of text decorations such as underlines, overlines, and line-throughs. This property can help give specific meanings to your text, like showing deleted text with a line-through. However, for better accessibility and semantic meaning, it’s good to use HTML tags like <del>
or <s>
for such purposes.
Specification
The text-decoration-style
property is part of the CSS Text Decoration Module Level 3. This module defines properties for styling text decorations, including underlines, overlines, and line-throughs.
Syntax
The text-decoration-style
property is easy to use. It accepts various keyword values that define the style of the text decoration lines.
Where value
can be one of the following keywords:
solid
: Draws a single, solid line.double
: Draws two parallel solid lines.dotted
: Draws a dotted line.dashed
: Draws a dashed line.wavy
: Draws a wavy line.
Additionally, the property accepts global values:
inherit
: Inherits the property from its parent element.initial
: Sets the property to its default value.revert
: Reverts the property to the user agent’s default.revert-layer
: Reverts the property to the user agent’s default for the cascade layer.unset
: Resets the property to its natural value.
Values
The text-decoration-style
property accepts several keyword values that determine the style of the text decoration lines:
solid
: Draws a single, continuous line. This is the default value.double
: Draws two parallel solid lines.dotted
: Draws a line composed of dots.dashed
: Draws a line composed of dashes.wavy
: Draws a wavy line.
Global values include:
inherit
: Inherits the value from the parent element.initial
: Sets the value to its default (solid
).revert
: Reverts the value to the user agent’s default.revert-layer
: Reverts the value to the user agent’s default for the cascade layer.unset
: Resets the value to its natural value.
Formal Definition
- Initial Value:
solid
- Applies To: All elements and
::first-letter
and::first-line
pseudo-elements. - Inherited: no
- Computed Value: as specified
- Animation Type: discrete
Examples
Wavy Underline
Solid Line Example
Double Line Example
Dotted Line Example
Dashed Line Example
Initial Value Example
Inherited Value Example
Browser Compatibility
Ensuring your web designs work across different browsers is important. Here’s a quick summary of browser support for the text-decoration-style
property:
- Google Chrome: Full support since version 57.0.
- Mozilla Firefox: Full support since version 36.0.
- Microsoft Edge: Full support since version 12.
- Safari: Full support since version 5.0.
- Opera: Full support since version 44.0.
Note: Basic values like solid
, double
, dotted
, and dashed
are well-supported, but the wavy
value might not be supported consistently across all browsers. Always test your designs across multiple browsers.
Browser Compatibility Table
Browser | Version | Support |
---|---|---|
Google Chrome | 57.0 | Full support |
Mozilla Firefox | 36.0 | Full support |
Microsoft Edge | 12 | Full support |
Safari | 5.0 | Full support |
Opera | 44.0 | Full support |
Tips for Ensuring Browser Compatibility
- Test Across Browsers: Always check how your design looks in different browsers.
- Use Fallbacks: When using newer properties like
wavy
, have a fallback ready. - Check Documentation: Regularly check browser documentation for the latest updates on property support.
Example of Fallback
Here’s how you can provide a fallback for browsers that don’t support the wavy
value:
CSS
HTML
FAQs
What is the text-decoration-style
property in CSS?
The text-decoration-style
property in CSS sets the style of text decoration lines, like underlines, overlines, or line-throughs. It lets you choose styles such as solid, dotted, dashed, double, or wavy.
How can I make an underline appear wavy in CSS?
To make an underline wavy, use:
What are the possible values for text-decoration-style
?
solid
: A single, continuous line.double
: Two parallel solid lines.dotted
: A line composed of dots.dashed
: A line composed of dashes.wavy
: A wavy line.
Can text-decoration-style
be used with any element?
Yes, it can be applied to any element that supports text decorations, like <p>
, <span>
, or <a>
.
Does text-decoration-style
affect text color?
No, it only affects the style of the decoration line. Use text-decoration-color
to change the color of the line.
How can I ensure browser compatibility for text-decoration-style
?
- Use Feature Detection: Tools like Modernizr can check if the property is supported.
- Provide Fallbacks: Use fallback styles for unsupported values.
- Graceful Degradation: Design so that older browsers still work well.
- Test Across Browsers: Regularly test on different browsers and devices.
More Examples
Combining Multiple Decoration Styles
Combine different text decoration styles within the same paragraph.
CSS
HTML
Styling Links with Text Decoration
Make links more visually appealing with text decoration styles.
CSS
HTML
Customizing Text Decoration for Blockquotes
Make blockquotes stand out with text decoration styles.
CSS
HTML
These examples show how versatile the text-decoration-style
property is. Experiment with different styles and elements to create visually engaging and user-friendly web designs. Always test across different browsers for consistent appearance.
Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.