When is the best time to use and in lieu o

2019-07-17 02:48发布

问题:

Semantically speaking, is there an appropriate place in today's websites (late 2008+) where using the bold <b> and italic <i> tags are more useful than the more widely used <strong> and <em> tags?

回答1:

While in general I would stay away from non-semantic tags like b and i, strong and em are not direct replacements for b and i.

I would use b or i when it's only presentation you're going for, and what you're marking up has no semantic meaning. For example, a logo like stackoverflow could be marked up with stack<b>overflow</b>. The "overflow" portion has no semantic meaning over "stack", yet stack<span class="overflow-logo">overflow</span> doesn't offer anything either.

Hope this helps.


Not sure how to comment (edit: need moar karma!), but this is in reply to Erik's comment.

Please read the HTML5 working draft. It gives a good explanation on when to use b.

The b element represents a span of text to be stylistically offset from the normal prose without conveying any extra importance, such as key words in a document abstract, product names in a review, or other spans of text whose typical typographic presentation is boldened.

"overflow" does not have emphasis over "stack" in the logo, therefore wrapping "overflow" with em is semantically incorrect.



回答2:

Never. They are removed in XHTML 2.0 as they are presentational tags. CSS should be used to bold/italicise content.

edit: If you're looking for a purely presentational tag, that's what the SPAN tag with a class and a little CSS is for.



回答3:

According to the HTML 5 spec, <b> and <i> should be used when appropriate.

On the i:

[A] span of text in an alternate voice or mood, or otherwise offset from the normal prose, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, a thought, a ship name, or some other prose whose typical typographic presentation is italicized.

On the b:

[A] span of text to be stylistically offset from the normal prose without conveying any extra importance, such as key words in a document abstract, product names in a review, or other spans of text whose typical typographic presentation is boldened.

Generally speaking, "when appropriate" is deemed to be as a last resort, when all other semantic options have been exhausted. "Presentational" though they may be, it would certainly be a disservice to their semantic cousins <em> and <strong> to consider them always italic or bolded, respectively.



回答4:

On http://www.webmasterworld.com/forum21/7095-1-15.htm there's a good comment:

"If page readers really read every <strong> tag in a strong voice, or really emphasize every <em> section on a page, then the poor user gets a page shouting at her or him on a regular basis.

I think this issue is really a no-brainer. If I am setting a bold or italic font for purposes of typography only, then I use <b> and <i>. If there's a word or phrase that I want to emphasize as I would in speaking, then - and only then - do I use <strong> or <em>."



回答5:

For markup generated by a WYSIWYG editor.



回答6:

The <b> and <i> tags don't have semantic meaning, whereas <strong> and <em> do. If a reader read the block of text aloud it would react to the <strong> and <em> tags, whereas the <i> and <b> tags would be ignored, and treated and purely visual elements. I tend to regard <i> and <b> as deprecated.



回答7:

Whenever you want to do things incorrectly ... just kidding.

The real answer is never, these tags have been deprecated by the W3C



回答8:

Neither <b> nor <i> are semantic tags, so purists would say they should not be used. Where I've seen their use justified are in things like putting online content in print where text was bolded or italicized as a matter of convention, but not as a manner of strengthening or emphasizing content.

The easy example is if you're putting online a magazine article that references a book by its title: you may want to put the book title in italics, but the italics are not for emphasis, so the <em> tag would be inappropriate. You could use <i> here, but the semantic thing to do would be to use something like <span class="booktitle"> and then use CSS to make booktitles italics. You are referencing a title, not putting emphasis, and you wouldn't want a screen reader to put verbal emphasis on the title.

My personal opinion is to not use either <b> or <i> today, but using <strong> or <em> as their substitutes when you aren't really looking to do anything besides bold or italicize the text is equally incorrect.



回答9:

I think when you're trying to make your markup meaningful, these are rarely useful.

There are, however, new tags that produce some of the same results, but which provide even more semantic value. I like to use the <cite> tag when I'm referring to the name of a book, for example, as it still gets italicised, but the HTML now carries meaning about why.

There are a variety of other semantic tags that can also affect formatting listed here:

http://www.w3.org/TR/xhtml2/mod-text.html



回答10:

I've been using <b> for years to indicate key words on my web site. I wrote a small utility that crawls the site looking for <b> tags and adds them to an index. I use <strong> when I want to bold a word without adding it to the index. I have used this convention for years -- too late to quit now.



回答11:

It could be argued that there is still a use for the <i> tag: when expressing the scientific name (aka the Latin name) of a species. The scientific name of a species is, by convention, usually presented in italics. Example. It is semantically incorrect to use <em> in this situation because one is not trying to emphasise the name but rather merely distinguish it visually. It may be more appropriate to use something like <span class="sci-name">, but when one considers that most scientific names are composed of words of the italic languages, mainly Latin, the <i> tag becomes a rather sematically rich and convenient solution.



回答12:

There are technical rules, but here are my two rules of thumb:

1) If you are writing something where, if spoken, you would emphasize a word, < strong > and < em > are appropriate. (E.g., "You have got to be sh*tting me, Pyle!")

2) If you are emphasizing a word for a technical reason, but would not emphasize the word in spoken conversation, < b > and < i > are appropriate. (E.g., "He boarded the RMS Titanic and sailed away, never to be seen again.")

Don't leave out other tags like < cite >, though!



回答13:

Officially, <i /> and <b /> are "presentational" and shouldn't be used. While many developers think that <em /> and <strong /> are presentational, they are not. They are generally italicized and bolded resopectively, but the CSS can (and should, when appropriate) change how the emphasis and strongness could be displayed.

Similar things could be done with css on a <span /> tag, and many consider that the preferred method, but it isn't substantiatable with the specification.



回答14:

Some years have passed …

In HTML5 (W3C Recommendation), none of these four elements are deprecated/obsolete.

The (non-normative!) usage summary lists their purposes:

  • strong: importance

  • b: keywords

  • em: stress emphasis

  • i: alternative voice

Of course, if you want to use them, always refer to their normative definitions (which you can find by clicking on the element names) and verify that they are appropriate for your case.

Examples

The b element could be used for keywords in a text, where the other three elements would not be appropriate: such keywords are not stressed (em), nor are they offset (i), and there is also no need for distinguishing them from boilerplate etc. (strong).

The i element could be used for scientific names in Latin, where strong and em are not appropriate. While b seems to be appropriate, too, its definition explicitly excludes the cases handled by i.

There can of course be cases where you’d use several of these elements. For example, a scientific name could also be a keyword in a document (<b><i>…</i></b>).



回答15:

When writing websites for mobile devices. They don't always support the 'latest and greatest' standards, are depreciated but not deleted from all modern browsers, and simply take up less space and bandwidth (though in theory the streams are compressed by either the websites or the wireless browser, it can't be counted on).

-Adam