Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use the span tag or the i tag for an icon? [duplicate]

Tags:

html

css

icons

tags

I'm just curious about which one is better to use in order to add a custom icon next to my links.

<ul>
    <li><a href=""><i class="home"></i> Home</a></li>
    <li><a href=""><i class="downloads"></i> Downloads</a></li>
</ul>

or

<ul>
    <li><a href=""><span class="home"></span> Home</a></li>
    <li><a href=""><span class="downloads"></span> Downloads</a></li>
</ul>

Thanks.

like image 332
user2152125 Avatar asked Mar 11 '13 01:03

user2152125


People also ask

What tag should I use for icons?

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons.

When would you use a span tag?

Span tags are used on small segments of text, links, images, and other HTML elements that appear inline with the surrounding content. To summarize, a div tag creates a block-level element while a <span> tag wraps around an inline element.

Can a tag contain span?

The span tag is a paired tag means it has both open(<) and closing (>) tags, and it is mandatory to close the tag.


2 Answers

<i> isn’t the icon tag, it’s the italic tag, and it doesn’t make much difference which you pick. <span> is more semantically correct, because it has no semantics.

like image 198
Ry- Avatar answered Oct 13 '22 01:10

Ry-


From the HTML5 spec:

The I element represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, a thought, a ship name, or some other prose whose typical typographic presentation is italicized.

Use the span tag if you want to be 'politically' correct.

However, Holly's answer puts up an argument for its use: Should I use <i> tag for icons instead of <span>?

like image 32
1321941 Avatar answered Oct 12 '22 23:10

1321941