Problem Statement
Which tag is used to underline text in HTML5?
Explanation
The u tag is used to underline text in HTML5. However, it is important to note that the u tag should be used carefully. Underlined text often looks like a hyperlink, which can confuse users. In older HTML versions, the u tag was deprecated, but HTML5 brought it back with a specific semantic meaning. It should represent text that is stylistically different from normal text, such as misspelled words or proper names in Chinese text. For general underlining, it is better to use CSS text decoration property. In interviews, understanding when and when not to use the u tag shows good knowledge of modern HTML practices.
Code Solution
SolutionRead Only
<p>This word is <u>underlined</u>.</p>
<p>Marking a <u class="spelling-error">mispelled</u> word.</p>
<!-- Better approach with CSS -->
<style>
.underlined {
text-decoration: underline;
}
</style>
<p>This uses <span class="underlined">CSS</span> instead.</p>