I don't understand how to do this!
The better way to emphasize text nowadays is using the <em>
tag:
<em>My Text</em>
But if you just need to show something italicized that is not semantically an "emphasis", it is perfectly fine to use the <i>
tag, which is ancient but still alive:
<i>My Text</i>
Or if you have a particular element.class combination you want to show italicized:
<span class='author'>Paolo Bergantino</span>
With the style:
span.author { font-style: italic; }
More: HTML - Italic(s)
Both <em>
and <i>
work, but <em>
is considered the "correct" way, as the <i>
tag just means "italic", but the <em>
tag means "emphasis" - which refers to the meaning of the content, not just how to display it. So screen reading software, for example, knows how to pronounce "emphasis" but not "italics".
So, do something like this:
<p>This is normal text. <em>This is in italics.</em> This is back to normal. </p>
(Of course, you can still use <i>
if you really just mean italic.)
(Or, you can really go crazy and add "font-style:italic"
to the css class of the particular piece of text in question)
There are a couple of ways to do this, depending on why you're doing it:
For emphasis
When emphasizing something, you should use the <em>
tag as this will be correctly interpreted as emphasis by screen readers etc.
Fore style purposes only
If you only want italic text for style purposes, for example on a whole paragraph or the entire page, you're not really looking for emphasis so the <em>
tag is wrong. Instead, you could do one of two:
- Style with css (better): add a
font-style: italic;
to the css class of the element you want to style - Style with html (not so good, but it works and it's easy): encapsulate the italic text in an
<i>
tag.