开发者

What are some advantages to using <span style="font-weight:bold"> rather than <b>?

开发者 https://www.devze.com 2023-03-21 17:18 出处:网络
I\'ve been learning about semantic HTML, and I keep reading how tags like 开发者_如何学JAVA<i> and <b> should be avoided. But if I don\'t want to emphasize something, but just bold it visu

I've been learning about semantic HTML, and I keep reading how tags like 开发者_如何学JAVA<i> and <b> should be avoided. But if I don't want to emphasize something, but just bold it visually, why would <b> be any worse than <span class="bold">? What are some advantages to using the more verbose <span class="bold"> syntax?


The issue with b and i elements is that they are not semantic, that is, they are about how things should look, not what they mean.

<span class="bold"> is actually no better, as it is also all about how something should look and is embedded in the page (a class name "bold" is not semantic either). It is better to use meaningful class names.

There are semantic tags, such as strong that are better.

As for class names - using a descriptive name is preferred - so <span class="sub-header"> is better than <span class="bold">, as it has meaning.


It's about the nature of markup. Take away presentation, and what you're left with should still convey your message.

The <b> and <i> tags are deprecated, which is why you shouldn't use them, but if you want to add emphasis to otherwise normal text you should use <strong> and <em> over a CSS solution. Having this in your HTML means that users who are disabled and using alternative browsing technologies like screen readers will still know that you intended emphasis. Adding CSS rules for bold and italic looks pretty but is not accessible.

Also bear in mind that you can then use CSS to apply style to your <strong> and <em> tags.


Why?

From http://www.w3.org/International/questions/qa-b-and-i-tags :

You should always bear in mind that the content of a b element may not always be bold, and that of an i element may not always be italic. The actual style is dependent on the CSS style definitions.


<b> means "put some text in bold" -- which is a presentation-related information, and should be in a CSS, instead of the HTML code.


<span class="bold"> just has no meaning at all by itself ; I think this solution should be avoided : with this, your HTML itself doesn't mean anything, and need the CSS so your text is seen as important...

This will work for graphical browsers... but what about other ways of consulting your page ?
Like speach-synthesis or braille-tablets ?


Finally, <strong>, on the other hand, means "this text is important" -- which is probably what you meant in the first place ;-)


span class bold is bad, I've seen too many CSS Rules in the style of

.blue-40 {
     // 2011-06-08 Change for Bug 12343
     color: #800000;
     width: 45%;
}

Semantic HTML is something like

.article-head {
}

.article-body {
}

I personally see no issue with <b> and <i>, although people made arguments to use <strong> and <em> instead because they are more meaningful. At that point, pragmatism kicks in: The only reason I ever would create a class solely for bold text is if I don't control the HTML that gets written to a container that I control.

One argument is always accessibility: If you are reading a document with a screen reader or text-to-speech engine, the concept of bold doesn't exist, but the concept of strong/emphasis does. In practice however, b/string and i/em and synonyms and unlikely to ever change, as much as the purists would like it to.


I personally think the Mozilla Developer Network has a great write up on the <b> tag (as well as the <strong> & <em> tags) and how to use it/them.

The important thing to remember is that the markup up is just as much about styling information as it is language. Keep in mind differences such as styling versus semantic differences (i.e. using bold instead of emphasis [<em>]).

0

精彩评论

暂无评论...
验证码 换一张
取 消