This property has three values that are overline, underline, or line-through. So, the value underline is used to underline the text in CSS.
- Text-decoration-line Sets the kind of decoration used, such as underline or line-through.
- Examples might be simplified to improve reading and learning.
- The text-decoration CSS property is used to decorate the content of the text.
So Chrome, for most intents and purposes, does NOT support this feature yet. I would love to be able to use this, because using border-bottom can be quirky – and I can’t believe this wasn’t addressed in CSS2 much less CSS3. Chrome also needs the -webkit prefix and experimental web platform features enabled in Chrome flags. Portions of this content are ©1998–2022 by individual mozilla.org contributors.
By using inline-table and table-caption, we can force the proper positioning of a pseudo-element that allows proper scaling. Auto The browser chooses the appropriate offset for underlines. The text-underline-offset property is specified as a single value from the list below. The text-decoration property is specified as one or more space-separated values representing the various longhand text-decoration properties. Same story for Opera, IE, Safari, Android, iOS, Dolphin, UC Browser, BlackBerry, WP8. Basically all browsers except (desktop?) Firefox don’t support text-decoration-style. Be careful when removing the text decoration on anchors since users often depend on the underline to denote hyperlinks.
To make the underline only set to the width of the text . We can set the display property of para to inline block. By setting that the width of the para becomes the width of the content. The text-decoration property adds an underline, overline, line-through, or a combination of lines to selected text. The individual text-decoration properties are text-decoration-line, text-decoration-color, text-decoration-style, and text-decoration-thickness. The property text-decoration-line is used to underline the text.
All browsers support the CSS2.1 “longhand” property text-decoration. Chrome will also recognize those values with the -webkit prefix and Experimental Web Platforms flag enabled. By default, the line or lines inherit the color of the text as set by its color property. You can change this in browsers that support the text-decoration-color property or the three-value shorthand property. There is no CSS property to apply an underline only to individual words in a sentence or an element with multiple words.
- Text-decoration-thickness Sets the thickness of the line used for the decoration.
- Text-decoration-color Sets the color of the decoration.
- This text has a really thick purple underline in supporting browsers.
- Text-decoration-style Sets the style of the line used for the decoration, such as solid, wavy, or dashed.
- It is the shorthand for text-decoration-line, text-decoration-color, and text-decoration-style.
- The text-underline-offset property is specified as a single value from the list below.
- Portions of this content are ©1998–2022 by individual mozilla.org contributors.
How to Underline in Html
So, the best way to achieve it is by wrapping the underlined words in a span element and then applies the underline to those spans. Text-underline-offset is not part of the text-decoration shorthand.
It is the shorthand for text-decoration-line, text-decoration-color, and text-decoration-style. The text-decoration-skip-ink, text-underline-offset, and text-underline-position properties also affect text-decoration, but are not included in the shorthand.
HTML and CSS
Text-decoration-thickness Sets the thickness of the line used for the decoration. Text-decoration-style Sets the style of the line used for the decoration, such as solid, wavy, or dashed. Text-decoration-color Sets the color of the decoration. Text-decoration-line Sets the kind of decoration used, such as underline or line-through. Let’s see how to underline some selected words by using the following example.
What is the use of * in CSS?
The asterisk (*) is known as the CSS universal selectors. It can be used to select any and all types of elements in an HTML page. The asterisk can also be followed by a selector while using to select a child object. This selector is useful when we want to select all the elements on the page.