英文:
b, i, u, s tags: should we use CSS instead?
问题
<b>
, <i>
, <u>
和<s>
标签纯粹是“视觉”效果,没有传达任何语义意义。
I've <em>already</em> told you <em>four</em> times
that I do <em>not</em> like <i>The Lord of the Rings</i> movie.
Please, stop.
尽管如此,这些标签并没有被正式弃用,甚至在MDN Web Docs和W3Schools上也没有被标记为“不推荐使用”。
例如,这里是来自W3Schools的一则说明:
根据HTML5规范,
<b>
标签应该作为最后的选择,当没有其他标签更合适时才使用。规范指出,标题应该用<h1>
到<h6>
标签表示,强调文本应该用<em>
标签表示,重要文本应该用<strong>
标签表示,标记/高亮文本应该用<mark>
标签表示。您还可以使用以下CSS来设置粗体文本:
"font-weight: bold;"
。
正如您所看到的,尽管W3Schools的文章对使用<b>
标签有些不鼓励,但它并没有解释为什么<b>
标签没有被弃用。
因此,我来回答您的问题:
- 为什么这些标签没有被弃用?
- 我们是否应该用CSS替换它们,以更好地遵循“将内容与表现分离”的理念?
- 换句话说,CSS的
font-weight: bold
是否真的是<b>
的1对1替代?(对于<i>
、<u>
和<s>
是否也一样?)
Is there anything else you would like to know?
英文:
<b>
, <i>
, <u>
, and <s>
tags are purely "visual" and don't convey any semantic meaning.
I've <em>already</em> told you <em>four</em> times
that I do <em>not</em> like <i>The Lord of the Rings</i> movie.
Please, stop.
Nevertheless, these tags are not officially deprecated and not even marked as "not recommended" on MDN Web Docs and W3Schools.
For instance, here is a note from W3Schools:
> According to the HTML5 specification, the <b>
tag should be used as a LAST resort when no other tag is more appropriate. The specification states that headings should be denoted with the <h1>
to <h6>
tags, emphasized text should be denoted with the <em>
tag, important text should be denoted with the <strong>
tag, and marked/highlighted text should be denoted with the <mark>
tag.
>
> You can also use the following CSS to set bold text: "font-weight: bold;"
.
As you can see, though W3 article somewhat discourages to use <b>
, it says nothing about why it is not deprecated at all.
Hence my questions:
- Why these tags are not deprecated?
- Whether we should replace them with CSS to better follow "separate content from presentation" idea?
- In other words, is CSS
font-weight: bold
is really a 1-to-1 replacement for<b>
? (and the same for<i>
,<u>
,<s>
)
答案1
得分: 1
以下是翻译好的部分:
仍然有效的HTML元素
<b>
、<i>
、<s>
和 <u>
仍然是HTML Living Standards(截至2023年6月28日)- 文本级语义的一部分。
它们都已经在一定程度上被重新定义,不再是样式元素,而是更有语义的元素。
语义定义与它们旧的样式含义
<b>
以前表示加粗文本,但现在用于表示吸引注意力但没有传达额外重要性的文本,也没有替代语气或情绪的暗示,例如文档摘要中的关键词、评论中的产品名称、交互式文本驱动软件中的可操作词汇,或文章导语。MDN喜欢称其为引起注意的文本
<i>
以前表示斜体文本,但现在用于表示具有不同质量的文本,与正常散文不同,表明不同质量的文本,例如分类名称、技术术语、来自其他语言的习惯用语、音译、思想或西方文本中的船名。MDN喜欢称其为习惯用语文本
<s>
有时被解释为<s>删除线</s>文本,类似于 <strike>
。<strike>
已经被弃用,但 <s>
仍然存在,因为它具有语义含义:表示内容(单词、短语或陈述)不再准确或不再相关,但仍然显示以传达对文档的更改。MDN仍然称其为删除线文本,我更愿意称其为替代文本。
<u>
以前只表示下划线文本,但现在用于表示具有未表达的非文本注释的文本(例如拼写错误的文本)。MDN喜欢称其为未表达的注释。
因此,您不应该再使用这些标记来表示它们旧的样式含义。相反,如果它们的语义含义适用于您的内容,您应该使用它们。特别是对于 <u>
标记,最好添加CSS样式以使其与超链接区分开。例如:
<!-- 开始片段: js 隐藏: false 控制台: true Babel: false -->
<!-- 语言: lang-css -->
u {
text-decoration: underline wavy red;
}
<!-- 语言: lang-html -->
<p>您可以使用<code>&lt;u&gt;</code>标记来突出显示<u>拼写</u>错误,以便作者可以<u>更正</u>它们。</p>
<!-- 结束片段 -->
其他类似的HTML元素
还要注意,还有其他一些语义元素与 <b>
和 <i>
有些相似:<strong>
和 <em>
。您可以参考它们的相应定义以获取详细信息。
MDN还在这里提供了更好的区分 <strong>
和 <b>
(链接),以及 <em>
和 <i>
(链接)。
英文:
Still valid HTML elements
The <b>
, <i>
, <s>
and <u>
are still part of the HTML Living Standards (as at 28 June 2023) - Text-level semantics.
They have all been redefined to some degree to stop being style elements and instead be more semantic elements.
Semantic definitions vs their old style meaning
<b>
used to mean bolded text, but is now used to repesent text to which attention is being drawn for utilitarian purposes without conveying any extra importance and with no implication of an alternate voice or mood, such as key words in a document abstract, product names in a review, actionable words in interactive text-driven software, or an article lede. MDN likes to call it the Bring Attention Text
<i>
used to mean italicized text, but is now to bring alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts. MDN likes to call it the Idiomatic Text
<s>
has been somewhat interpreted as a <s>strikethrough</s> text, similar to <strike>
. <strike>
has been deprecated, but <s>
has stayed on because it has semantic meaning: it represents content (word, phrase or statement) that is no longer accurate or no longer relevant but is still shown to convey change to the document. MDN still likes to call it the Strikethrough Text which I think dilutes it semantic meaning. I'd rather call it the Substituted Text.
<u>
used to just mean underlined text, but is now used to represent span of text with an unarticulated non-textual annotation (e.g. text that is misspelt). MDN likes to call it the Unarticulated Annotation.
So you should not use these tags for their old styling meanings. Instead, you should use them if their semantic meanings apply to your content. Also, particularly for <u>
tag, you should ideally add CSS styling to differentiate it from hyperlinks. For example:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
u {
text-decoration: underline wavy red;
}
<!-- language: lang-html -->
<p>You could use the <code>&lt;u&gt;</code> tag to highlight <u>speling</u> mistakes, so the writer can <u>corect</u> them.</p>
<!-- end snippet -->
Other similar HTML elements
Also note there are other semantic elements which are somewhat similar to <b>
and <i>
: <strong>
and <em>
. You can refer to their corresponding definitions for details.
MDN also gives better differentiation between <strong>
and <b>
here as well as <em>
and <i>
here.
答案2
得分: 0
- 一个原因是为了支持未积极开发/维护的旧网站,所以它没有被弃用。
- 以我个人的看法,是的,它将内容与表示分开,并且鼓励/迫使我们提高CSS技能。但不是用来取代它,以某种方式它留下了结构痕迹。因为并不是所有的内容都会在浏览器中呈现,一些内容将被删除。我宁愿在容易且可能的情况下使用该标签,以满足您的需求。
- 不,只是在视觉上。
英文:
- One guest why it is not deprecated is to support old websites that are not actively developed/maintained.
- IMHO yes it separates the content from the representation, and it also encourages/forces us to enhance CSS skills. But not to replace it, somehow it leaves a structural trace. Since not all will be rendered browser, some content will be scrapped. I rather use that tag, when it is easy and possible, so suits your need.
- no, only visually.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论