HTML中添加下划线有两种方法:使用 <u> 标签:在需要添加下划线的文本周围添加 <u> 标签。使用 CSS text-decoration 属性:在指定的文本元素中设置 text-decoration:underline; 或 text-decoration-line:underline;。选择方法取决于需求:快速添加下划线使用 <u> 标签,精细控制或结合其他样式使用 CSS text-decoration 属性。

HTML 中添加下划线的两种方法
方法 1:使用 <u> 标签
最简单的方法是在要添加下划线的文本周围添加 <u> 标签。例如:
<code class="html"><u>此文本将有下划线</u></code>
方法 2:使用 CSS text-decoration 属性
立即学习“前端免费学习笔记(深入)”;
也可以使用 CSS text-decoration 属性来添加下划线。该属性可以应用于任何文本元素:
<code class="html"><p style="text-decoration: underline;">此文本将有下划线</p></code>
也可以使用更具体的 text-decoration-line 属性:
<code class="html"><p style="text-decoration-line: underline;">此文本将有下划线</p></code>
选择方法的建议
选择哪种方法取决于您的具体需要:
- 如果您只想快速轻松地添加下划线,请使用
u标签。 - 如果您需要更精细的控制或与其他样式结合使用,请使用 CSS
text-decoration属性。











