215

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.

  1. 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.

  2. 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?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Rupert Madden-Abbott
  • 12,899
  • 14
  • 59
  • 74

12 Answers12

220

You should use different methods for different use cases:

  1. If you want to emphasise a phrase, use <em>.
  2. 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).
  3. If the italicised text is part of a larger context, say an introductory paragraph, you should attach the CSS style to the larger element, i.e. p.intro { font-style: italic; }
DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290
  • 2
    +1, seems like sound advice to me. I think point 3 is a good example of changing text style purely for aesthetic reasons, with no real semantic intent. – GrahamS Jan 21 '10 at 14:14
  • 1
    Case 2 does not correspond to what HTML5 drafts actually say – which is obscure and varies by version, but no version suggests using `i` for book, song, album, or movie names (which would, debatably, be candidates for using `cite`). – Jukka K. Korpela Sep 01 '14 at 13:04
  • @Jukka I'm sure it was in there at some point. Nonetheless it's not there now so I've updated my answer. – DisgruntledGoat Sep 01 '14 at 22:14
  • As mentioned in: http://www.w3.org/TR/html5/text-level-semantics.html#the-em-element If you want to use an element to make your text italics you should use . The em element isn't a generic "italics" element. Sometimes, text is intended to stand out from the rest of the paragraph, as if it was in a different mood or voice. For this, the i element is more appropriate. – Dimitris Zorbas Dec 07 '15 at 11:31
22

<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.

YakovL
  • 7,557
  • 12
  • 62
  • 102
Alohci
  • 78,296
  • 16
  • 112
  • 156
10

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/

Guillaume Flandre
  • 8,936
  • 8
  • 46
  • 54
  • 2
    +1 for pointing out there is a difference between implied or inherited semantics (the cheap and easy but weak form) and explicit sementics where the developer must make a bit of extra effort to add value to his content (expensive and labour intensive but can yield good quality content). – logout Jan 21 '10 at 10:48
7

TLDR

The correct way to make text italic is to ignore the problem until you get to the CSS, then style according to presentational semantics. The first two options you provided could be right depending on the circumstances. The last two are wrong.

Longer Explanation

Don't worry about presentation when writing the markup. Don't think in terms of italics. Think in terms of semantics. If it requires stress emphasis, then it's an em. If it's tangential to the main content, then it's an aside. Maybe it'll be bold, maybe it'll be italic, maybe it'll be fluorescent green. It doesn't matter when you're writing markup.

When you do get to the CSS, you might already have a semantic element that makes sense to put italics for all its occurrences in your site. em is a good example. But maybe you want all aside > ul > li on your site in italics. You have to separate thinking about the markup from thinking about the presentation.

As mentioned by DisgruntledGoat, i is semantic in HTML5. The semantics seem kind of narrow to me, though. Use will probably be rare.

The semantics of em have changed in HTML5 to stress emphasis. strong can be used to show importance as well. strong can be italic rather than bold if that's how you want to style it. Don't let the browser's stylesheet limit you. You can even use a reset stylesheet to help you stop thinking within the defaults. (Though there are some caveats.)

class="italic" is bad. Don't use it. It is not semantic and is not flexible at all. Presentation still has semantics, just a different kind from markup.

class="footnote" is emulating markup semantics and is incorrect as well. Your CSS for the footnote should not be completely unique to your footnote. Your site will look too messy if every part is styled differently. You should have some visual patterns scattered through your pages that you can turn into CSS classes. If your style for your footnotes and your blockquotes are very similar, then you should put the similarities into one class rather than repeat yourself over and over again. You might consider adopting the practices of OOCSS (links below).

Separation of concerns and semantics are big in HTML5. People often don't realize that the markup isn't the only place where semantics is important. There is content semantics (HTML), but there is also presentational semantics (CSS) and behavioral semantics (JavaScript) as well. They all have their own separate semantics that are important to pay attention to for maintainability and staying DRY.

OOCSS Resources

Community
  • 1
  • 1
Eva
  • 4,397
  • 5
  • 43
  • 65
5

Perhaps it has no special meaning and only needs to be rendered in italics to separate it presentationally from the text preceding it.

If it has no special meaning, why does it need to be separated presentationally from the text preceding it? This run of text looks a bit weird, because I’ve italicised it for no reason.

I do take your point though. It’s not uncommon for designers to produce designs that vary visually, without varying meaningfully. I’ve seen this most often with boxes: designers will give us designs including boxes with various combinations of colours, corners, gradients and drop-shadows, with no relation between the styles, and the meaning of the content.

Because these are reasonably complex styles (with associated Internet Explorer issues) re-used in different places, we create classes like box-1, box-2, so that we can re-use the styles.

The specific example of making some text italic is too trivial to worry about though. Best leave minutiae like that for the Semantic Nutters to argue about.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
  • 1
    I tend to agree. If you can't come up with a justification for certain markup to be presented differently then you're not thinking about it in the right way. If you can't explain why [this text] should be italic, how would you recognise when [other text] should also be italic on a different page/part of the page? And similarly, if you *do* know why, you should be able to come up with a useful name for that reason – Gareth Jan 21 '10 at 10:42
  • 1
    Absolutely. Sometimes there's no way to use CSS to turn purely semantic markup into what a designer wants (x-browser) - you have to be flexible. – Skilldrick Jan 21 '10 at 10:50
  • 1
    There are *aesthetic* reasons to style text. For example, there is a (purely aesthetic) convention to style the first few words of each paragraph in small caps. It has no semantic meaning. It must be possible in HTML to mark up text for non-semantic reasons. –  May 23 '16 at 10:14
3

HTML italic text displays the text in italic format.

<i>HTML italic text example</i>

The emphasis and strong elements can both be used to increase the importance of certain words or sentences.

<p>This is <em>emphasized </em> text format <em>example</em></p>

The emphasis tag should be used when you want to emphasize a point in your text and not necessarily when you want to italicize that text.

See this guide for more: HTML Text Formatting

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prabhakar
  • 6,458
  • 2
  • 40
  • 51
2

The i element is non-semantic, so for the screen readers, Googlebot, etc., it should be some kind of transparent (just like span or div elements). But it's not a good choice for the developer, because it joins the presentation layer with the structure layer - and that's a bad practice.

em element (strong as well) should be always used in a semantic context, not a presentation one. It has to be used whenever some word or sentence is important. Just for an example in the previous sentence, I should use em to put more emphasis on the 'should be always used' part. Browsers provides some default CSS properties for these elements, but you can and you're supposed to override the default values if your design requires this to keep the correct semantic meaning of these elements.

<span class="italic">Italic Text</span> is the most wrong way. First of all, it's inconvenient in use. Secondly, it suggest that the text should be italic. And the structure layer (HTML, XML, etc.) shouldn't ever do it. Presentation should be always kept separated from the structure.

<span class="footnote">Italic Text</span> seems to be the best way for a footnote. It doesn't suggest any presentation and just describes the markup. You can't predict what will happen in the feature. If a footnote will grow up in the feature, you might be forced to change its class name (to keep some logic in your code).

So whenever you've some important text, use em or strong to emphasis it. But remember that these elements are inline elements and shouldn't be used to emphasis large blocks of text.

Use CSS if you care only about how something looks like and always try to avoid any extra markup.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Crozin
  • 43,890
  • 13
  • 88
  • 135
1

I think the answer is to use <em> when you intend emphasis.

If when reading the text to yourself, you find that you use a slightly different voice to emphasise a point, then it should use <em> because you would want a screen reader to do the same thing.

If it is purely a style thing, such as your designer has decided that all your <h2> headings would look better in italic Garamond, then there is no semantic reason to include it in the HTML and you should just alter the CSS for the appropriate elements.

I can't see any reason to use <i>, unless you specifically need to support some legacy browser with no CSS.

GrahamS
  • 9,980
  • 9
  • 49
  • 63
  • As pointed out in comments it looks like they have slightly changed the intent in HTML5 and confused the issue. So if you're using HTML5 already then I guess `` is now semantically useful too. – GrahamS Jan 21 '10 at 12:45
0

OK, the first thing to note is that <i> has been deprecated, and shouldn't be used <i> has not been deprecated, but I still do not recommend using it—see the comments for details. This is because it goes entirely against keeping presentation in the presentation layer, which you've pointed out. Similarly, <span class="italic"> seems to break the mold too.

So now we have two real ways of doing things: <em> and <span class="footnote">. Remember that em stands for emphasis. When you wish to apply emphasis to a word, phrase or sentence, stick it in <em> tags regardless of whether you want italics or not. If you want to change the styling in some other way, use CSS: em { font-weight: bold; font-style: normal; }. Of course, you can also apply a class to the <em> tag: if you decide you want certain emphasised phrases to show up in red, give them a class and add it to the CSS:

Fancy some <em class="special">shiny</em> text?

em { font-weight: bold; font-style: normal; }
em.special { color: red; }

If you're applying italics for some other reason, go with the other method and give the section a class. That way, you can change its styling whenever you want without adjusting the HTML. In your example, footnotes should not be emphasised—in fact, they should be de-emphasised, as the point of a footnote is to show unimportant but interesting or useful information. In this case, you're much better off applying a class to the footnote and making it look like one in the presentation layer—the CSS.

Samir Talwar
  • 14,220
  • 3
  • 41
  • 65
  • 6
    `` has not been deprecated. – Quentin Jan 21 '10 at 10:39
  • @DavidDorward: correct, `` has not been deprecated, but the HTML4 spec says "Although they are not all deprecated, their use is discouraged in favor of style sheets" – GrahamS Jan 21 '10 at 10:56
  • @Graham: check the HTML5 spec, `` is used to represent "a span of text in an alternate voice or mood". – DisgruntledGoat Jan 21 '10 at 12:34
  • @DisgruntledGoat: I have to admit I haven't been following the development of the HTML5 spec too closely, but you're right it looks like they have now attempted to retrofit `` with some semantic meaning. Personally I think they've now muddled the issue, but they do still say "authors are encouraged to consider whether other elements might be more applicable than the `i` element, for instance the `em` element for marking up stress emphasis". – GrahamS Jan 21 '10 at 12:49
  • 1
    Apologies—seems I missed the part referring to HTML5. It seems to me that the specification is unclear on when to use `` and when to use ``… they seem to imply you should use `` for a single specific case where semantics are further desired, which seems off to me—you're still adding presentation code to the semantic layer. So you're right: it's not deprecated, but based on what I've read, I can't honestly recommend it either. – Samir Talwar Jan 22 '10 at 00:54
0

I'd say use <em> to emphasize inline elements. Use a class for block elements like blocks of text. CSS or not, the text still has to be tagged. Whether its for semantics or for visual aid, I'm assuming you'd be using it for something meaningful...

If you're emphasizing text for ANY reason, you could use <em>, or a class that italicizes your text.

It's OK to break the rules sometimes!

tahdhaze09
  • 2,220
  • 1
  • 21
  • 36
-1

Use <em> if you need some words/characters in italic in content without other styles. It also helps make content semantic.

text-style is better suited for multiple styles and no semantic need.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
aryan
  • 15
  • 1
  • 2
  • 6
-3

DO

  1. Give the class attribute a value indicating the nature of the data (i.e. class="footnote" is good)

  2. Create a CSS style sheet for the page

  3. Define a CSS style that is attached to the class that you assign to the element

    .footnote { font-style:italic; }

DO NOT

  1. Don't use <i> or <em> elements - they're unsupported and ties the data and presentation too close.
  2. Don't give the class a value that indicates the presentation rules (i.e. don't use class="italic").
carefulnow1
  • 803
  • 12
  • 30
Ninju Bohra
  • 460
  • 1
  • 5
  • 11
  • 1
    As cited in another answer, `` and `` are in HTML5. Your number 2 under "Do Not" is correct, but your #1 under "Do" is askewed -- it is not good to label a whole class "footnote" if other items that won't be footnotes will also be italicized with that class, though having a class that indicates the nature of the data is good. A class and style sheet is not always necessary, however, especially if only a couple of items will be italicized. – vapcguy May 06 '15 at 23:24