开发者

What is the optimal element to use for marking 'keywords' in an article?

Obviously, this is a bit of a "it depends" question, but what HTML element makes the most sense to provide the clearest meaning of "Hey, you, I think this is an important word!"?

I realize I could just use <b> tags, but that simply provides visual emphasis (unless, of course, I use Eric Meyer's reset.css. Then you get nothing...). I am curious what would provide a better sema开发者_C百科ntic meaning. So far my searches lead me to believe mark could make sense, especially if I wanted to query the page content later to extract keywords, but it feels like I'd be using the element incorrectly.

EDIT:

Per @Paul D. Waite's suggestion, let me try to explain what I mean by "keyword."

Let's say I wrote a blog post or tutorial about how to, say, write a simple WPF application. When I reference language constructs, namespaces, classes, etc. I tend to use the <code> or <samp> tags (along with some monospace fonts to reinforce visually that I am making technical references). Now, if I wanted to emphasize a word or phrase, say "visual tree", as a way of making sure the reader knows I think that was a term they should get used to hearing (or look for more information about), is a simple <strong> or <em> element really the best way to mark this up?

Hope this makes sense.


As per the spec, it looks like you want <strong>:

The strong element represents strong importance for its contents.

http://dev.w3.org/html5/spec-author-view/the-strong-element.html#the-strong-element

The section of the spec for <mark> even has an example of how <mark> and <strong> differ.

It really depends what you mean by “keyword”. Could you provide an example of the content you’re trying to mark up?

Edit: if you’re emphasising a word because it’s the defining instance of a term (i.e. you’re defining it in the same paragraph), then you can use the <dfn> tag.


<mark> is a fairly good choice for HTML 5, but it does carry the connotation of being marked to be referenced from elsewhere.

If you are just considering "importance" then you can consider

<span class="important">hello</span>

Span may not be that special element you are looking for, but it is not uncommon to use the class attribute to add semantics. The reason for this is that the element set of HTML can't grow arbitrarily large -- we can't have 1000's of tags for every kind of document markup you can think of. HTML already has var, kbd, samp, mark, and a few others, but this list needs to be finite and small. This is, I think, where span comes to the rescue. So you end up using CSS which is supposedly presentational, but you do so because there are limits on the number of actual HTML elements. So in a way, I would say span is an acceptable pragmatic choice.

However, if mark meets your needs exactly, you can use it. For the case you mentions, I think it would be an acceptable and proper use of the element.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜