2 Easy Ways to Underline Text in CSS and HTML
2 Easy Ways to Underline Text in CSS and HTML
Do you want to use the underline tag in HTML? In the past, the HTML code for underlining text was the simple tag. However, this method has been abandoned in favor of the much more versatile CSS "text-decoration" style property. Using CSS ensures your code stays future-proof. This wikiHow will show you how to underline text in CSS using the current "text-decoration" method, as well as the past deprecated method of HTML.
Things You Should Know
  • The <u> tag is deprecated, meaning it technically works, but it's not recommended to use.
  • When using CSS, use the "text-decoration" CSS style property to underline text.
  • While underlining takes only a few steps, consider other methods for emphasizing text. Underlining may confuse your readers.

Using CSS

Use the "text-decoration" CSS style property. The Text-decoration property sets the appearance of decorative lines on text in CSS. Text-decoration is shorthand for text-decoration-line, text-decoration-color, text-decoration-style, and text-decoration-thickness. In older versions of HTML, this element used to be known as the "Underline" element. Using the tag is deprecated, meaning it is still allowed but not recommended to use. Using the "text-decoration" property is a newer, better alternative to underlining. You can use Windows Notepad to create a simple CSS stylesheet.

Use the tag when you want to underline a certain piece of text. Place the opening tag along with the "text-decoration" property where you want to start underlining. Place the closing where you want it to stop. This will be underlined.

Declare HTML elements in the

This header will be underlined

Define a CSS Class Style. You'll be able to quickly underline at any time. In your style sheet or You can use this class to

quickly underline
different parts
of your content

Consider other methods for highlighting text. Underlining should be avoided to keep from confusing your reader. One popular method is to use the tag, which italicizes text. You can use CSS to further define this tag for unique emphasis. Anything that uses the em element will be italicized (because of the default settings), as well as red because of the additional style settings added above.

Using HTML (Deprecated)

Avoid using the old tags. This has been "deprecated", which means it works but is no longer in use or recommended. This is because HTML is not designed to style content. The tag will still work, but it is now supposed to represent text that is different than the other text, such as misspelled words.

Use the tags to underline (demonstration only). There is virtually no case where you should be using this method anymore. However, it can be good to know how it was used in the event you have to update an old website. The old underline tag in HTML allowed you to underline things quickly, but it made things a mess when other style elements got involved. This is why modern underlining is accomplished using the "text-decoration" CSS element.

What's your reaction?

Comments

https://filka.info/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!