CSS/HTML: What is the correct way to make text italic?

What is the correct way to make text italic? I have seen the following four approaches:

<i>Italic Text</i>

<em>Italic Text</em>

<span class="italic">Italic Text</span>

<span class="footnote">Italic Text</span>


<i>

This is the "old way". <i> has no semantic meaning and only conveys the presentational effect of making the text italic. As far as I can see, this is clearly wrong because this is non-semantic.


<em>

This uses semantic mark up for purely presentational purposes. It just happens that <em> by default renders text in italic and so it is often used by those who are aware that <i> should be avoided but who are unaware of its semantic meaning. Not all italic text is italic because it is emphasised. Sometimes, it can be the exact opposite, like a side note or a whisper.


<span class="italic">

This uses a CSS class to place presentation. This is often touted as the correct way but again, this seems wrong to me. This doesn't appear to convey any more semantic meaning that <i> . But, its proponents cry, it is much easier to change all your italic text later if you, say, wanted it bold. Yet this is not the case because I would then be left with a class called "italic" that rendered text bold. Furthermore, it is not clear why I would ever want to change all italic text on my website or at least we can think of cases in which this would not be desirable or necessary.


<span class="footnote">

This uses a CSS class for semantics. So far this appears to be the best way but it actually has two problems.

  • Not all text has sufficient meaning to warrant semantic markup. For example, is italicised text at the bottom of the page really a footnote? Or is it an aside? Or something else entirely. Perhaps it has no special meaning and only needs to be rendered in italics to separate it presentationally from the text preceding it.

  • Semantic meaning can change when it is not present in sufficient strength. Lets say I went along with "footnote" based upon nothing more than the text being at the bottom of the page. What happens when a few months later I want to add more text at the bottom? It is no longer a footnote. How can we choose a semantic class that is less generic than <em> but avoids these problems?


  • Summary

    It appears that the requirement of semantics seems to be overly burdensome in many instances where the desire to make something italic is not meant to carry semantic meaning.

    Furthermore, the desire to separate style from structure has led CSS to be touted as a replacement to <i> when there are occasions when this would actually be less useful. So this leaves me back with the humble <i> tag and wondering whether this train of thought is the reason why it is left in the HTML5 spec?

    Are there any good blog posts or articles on this subject as well? Perhaps by those involved in the decision to retain/create the <i> tag?


    You should use different methods for different use cases:

  • If you want to emphasise a phrase, use <em> .
  • The <i> tag has a new meaning in HTML5, representing "a span of text in an alternate voice or mood". So you should use this tag for things like thoughts/asides or idiomatic phrases. The spec also suggests ship names (but no longer suggests book/song/movie names; use <cite> for that instead).
  • If the italicised text is part of a larger context, say an introductory paragraph, you should attach the CSS style to the larger element, ie p.intro { font-style: italic; } p.intro { font-style: italic; }

  • <i> is not wrong because it is non-semantic. It's wrong (usually) because it's presentational. Separation of concern means that presentional information should be conveyed with CSS.

    Naming in general can be tricky to get right, and class names are no exception, but nevertheless it's what you have to do. If you're using italics to make a block stand out from the body text, then maybe a class name of "flow-distinctive" would be in order. Think about reuse: class names are for categorization - where else would you want to do the same thing? That should help you identify a suitable name.

    <i> is included in HTML5, but it is given specific semantics. If the reason why you are marking something up as italic meets one of the semantics identified in the spec, it would be appropriate to use <i>. Otherwise not.


    I'm no expert but I'd say that if you really want to be semantic, you should use vocabularies (RDFa).

    This should result in something like that:

    <em property="italic" href="http://url/to/a/definition_of_italic"> Your text </em>
    

    em is used for the presentation (humans will see it in italic) and the property and href attributes are linking to a definition of what italic is (for machines).

    You should check if there's a vocabulary for that kind of thing, maybe properties already exist.

    More info about RDFa here: http://www.alistapart.com/articles/introduction-to-rdfa/

    链接地址: http://www.djcxy.com/p/67376.html

    上一篇: 在Windows 8 Metro应用程序中将超链接绑定到richtextblock

    下一篇: CSS / HTML:什么是使文本斜体的正确方法?