2

Is there a difference in how the browser would display between:

<i>test</i>

<span style="font-style:italic">test</span>

Is one preferable over the other? Are there different scenarios for each?

A quick jsfiddle doesn't show any visual difference.

Barry
  • 60
  • 1
  • 9

5 Answers5

10

Pre-HTML5, there was no difference, neither in visuals nor semantics; i, like b, s and u, was a presentational element. This is in contrast to em, strong, del and ins respectively.

In HTML5, the i element has a specific meaning that happens to be represented visually as italicized text. It should not be used to represent just any text that happens to be in italics. In particular, it distinguishes itself from the em element, which represents stress emphasis (and, unlike i, doesn't necessarily have to be represented with italics). span remains a generic phrasing element that carries no meaning whatsoever.

Normally I would quote the spec here but I think MDN's summary is easier to understand:

The HTML <i> element represents a range of text that is set off from the normal text for some reason. Some examples include technical terms, foreign language phrases, or fictional character thoughts. It is typically displayed in italic type.

The spec still offers better examples though:

The examples below show uses of the i element:

<p>The <i class="taxonomy">Felis silvestris catus</i> is cute.</p>
<p>The term <i>prose content</i> is defined above.</p>
<p>There is a certain <i lang="fr">je ne sais quoi</i> in the air.</p>

In the following example, a dream sequence is marked up using i elements.

<p>Raymond tried to sleep.</p>
<p><i>The ship sailed away on Thursday</i>, he
dreamt. <i>The ship had many people aboard, including a beautiful
princess called Carey. He watched her, day-in, day-out, hoping she
would notice him, but she never did.</i></p>
<p><i>Finally one night he picked up the courage to speak with
her—</i></p>
<p>Raymond woke with a start as the fire alarm rang out.</p>
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • I appreciate the answer - but it doesn't really address the difference (if there is one) in use of an HTML or CSS-based application. Additionally, while I understand that the HTML spec and MDN may recommend the proper use of the element, italics are a linguistic effect and I don't think a spec should be deferred to for determining where in text italics are used - this is the author's discretion. – Barry Nov 01 '18 at 13:50
  • @Barry: How does it not? You use in any of the listed examples, and you use if you simply want to apply italics to arbitrary text that doesn't have any special meaning, or CSS for aesthetic purposes. Linguistic italics can carry one of several different meanings, which is why there are different semantic HTML elements each representing a different meaning for you to choose from (, , , to name a few) that all happen to share the same typographical appearance. – BoltClock Nov 01 '18 at 13:54
0

The paragraph is taken from https://html.com/tags/i/#ixzz5VZbm6JhB

The HTML <i> element is used to differentiate words from the surrounding text by styling the marked text in italics without implying any added emphasis to the italicized words.

an Example here, here I want the word world to be in italic, so you can have an <i> tag surrounded.

<h1>Hello <i>World</i></h1>

When using CSS font-style:italic you need to be specific where the style be done.

like in the example.

h2{
    font-style:italic;
}
<h2>Hello World</h2>

So, what if you want to achieve the word world to be italic, you have to surround it in between span tag and make it italic using the CSS.

span{
    font-style:italic;
}
<h2>Hello <span>World</span></h2>

So, rather than doing it in CSS, HTML had given an option of <i> tag.

The i tag can be used to indicate a technical term, a phrase from another language, a thought, or a ship name, etc.

chintuyadavsara
  • 1,509
  • 1
  • 12
  • 23
  • Please follow the rules in https://stackoverflow.com/help/referencing and ensure you are properly citing text that you did not write. (Hint: the first paragraph was not written by you.) – BoltClock Nov 01 '18 at 04:32
  • @BoltClock Thank you sir, I have included the `Read more` in the bottom of the post, that is the source of the paragraph. – chintuyadavsara Nov 01 '18 at 04:38
  • May I know why you format it as "Read more" and include it at the bottom? I ask because this is something I see a lot. Most people are used to seeing quotations with their citations clearly appearing alongside them so they know exactly where which text is being copied from. "Read more" makes it appear like a supplementary link and doesn't clearly indicate which portions of the text you did not write, so it looks as if everything was your original writing, which it isn't and that bothers a lot of people. There's a reason I linked to the rules and asked you to follow them. – BoltClock Nov 01 '18 at 04:42
  • @BoltClock sir, It's my mistake, I should have included in the post itself saying `source taken from`. I am sorry for violating the rules. I will edit it. – chintuyadavsara Nov 01 '18 at 04:44
  • So other than implementation, and time to load the CSS document, the effect is exactly the same? – Barry Nov 01 '18 at 13:54
0

<i> content </i> is a markup tag to show content in web browser, font-style is a property to style your content (headings, paragraphs, list etc). In font-style: italic, italic is a value of font-style property to show content/text in italic style at browser. Normally, Ui/Ux designer use this <i></i> tag to show fonty icons (icons in font/text format, not images like jpeg,png,jpeg etc). But you can use this tag for any purpose as you need.

Billu
  • 2,733
  • 26
  • 47
-2

From w3schools:

In HTML 4.01, the tag was used to render text in italics. However, this is not necessarily the case with HTML5. Style sheets can be used to format the text inside the element.

Maarti
  • 3,600
  • 4
  • 17
  • 34
-3

both are same in properties. Both do the same thing. The only difference is that the one is using the HTML tag to apply italic property and other is using CSS property to apply the italic style.

Amir shah
  • 317
  • 2
  • 7