Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: open

Good practices: order of tags ?

     
11:49 pm on Oct 17, 2019 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Aug 30, 2019
posts:147
votes: 30


Hello-

This question has certainly already been asked, but I couldn't find it, using the site search function.

<i><a href="...">blah blah</a></i>

or
<a href="..."><i>blah blah</i></a>


To me, this is the first, which is the right one. Isn't it?
12:05 am on Oct 18, 2019 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4562
votes: 364


Or there's
a.ital{font-style:italic;}

<a class="ital" href="...">blah blah</a>


2:08 am on Oct 18, 2019 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:15937
votes: 889


Or there's ... class="ital"
For a total of 13 bytes (15 if you're generous with spaces, as I am), while <i></i> is seven :)

Between <a><i> and <i><a> there's no absolute right and wrong, though it's worth nothing that <a> can now be block-level (in HTML <= 4 it wasn't supposed to be, though browsers didn't mind) while <i> is strictly inline. Generally you'd want to put inline elements inside of block-level elements.

Use whichever one seems right to you. I, personally, have done both, as the occasion warrants--often within the same document--and also plenty of variations on not2easy's approach. The only absolute no-no is interlocking tags, like <a blahblah><i>blahblah</a></i>; that will make any validator kick up a fuss.