{"id":2322,"date":"2012-06-25T10:30:39","date_gmt":"2012-06-25T10:30:39","guid":{"rendered":"http:\/\/sunpig.com\/mt-entry-2322.html"},"modified":"2012-06-25T10:30:39","modified_gmt":"2012-06-25T10:30:39","slug":"nested-tags-for-italicized-hyperlinks","status":"publish","type":"post","link":"https:\/\/sunpig.com\/martin\/2012\/06\/25\/nested-tags-for-italicized-hyperlinks\/","title":{"rendered":"Nested tags for italicized hyperlinks"},"content":{"rendered":"<p>I tweeted a question the other day about nesting <code>&lt;em&gt;<\/code> and <code>&lt;a&gt;<\/code> tags, to figure out which is better:<\/p>\n<pre class=\"code\"><code class=\"html\" data-language=\"html\">&lt;em&gt;&lt;a href=\"#\"&gt;blah&lt;\/a&gt;&lt;\/em&gt;<\/code><\/pre>\n<p>or<\/p>\n<pre class=\"code\"><code class=\"html\" data-language=\"html\">&lt;a href=\"#\"&gt;&lt;em&gt;blah&lt;\/em&gt;&lt;\/a&gt;<\/code><\/pre>\n<blockquote>\n<p><a href=\"#\"><em>blah<\/em><\/a> or <em><a href=\"#\">blah<\/a><\/em><\/p>\n<\/blockquote>\n<p>Both are valid HTML, and browsers render them the same way. I&#8217;m also pretty sure that I&#8217;ve used them interchangeably in the past, and that I&#8217;ve asked myself the &#8220;which way is right?&#8221; question many times before. But enough! It&#8217;s time for me to have a definitive answer based on solid reasoning, not just an arbitrary decision, so that if I ever forget, I can retrace the logical steps and come to the same answer every time.<\/p>\n<p>For me, the primary use case for nesting tags like this is to hyperlink book, film, or album titles. I wrap these titles in an <code>&lt;i&gt;<\/code> tag rather than an <code>&lt;em&gt;<\/code> tag. (See <a href=\"http:\/\/html5doctor.com\/i-b-em-strong-element\/\">Oli Studholme&#8217;s article at HTML5 Doctor<\/a> for an in-depth look at the semantic differences between the two.) Like so:<\/p>\n<pre class=\"code\"><code class=\"html\" data-language=\"html\">&lt;a href=\"http:\/\/www.allmusic.com\/album\/clockwork-angels-mw0002332023\"&gt;&lt;i&gt;Clockwork Angels&lt;\/i&gt;&lt;\/a&gt;<\/code><\/pre>\n<blockquote>\n<p><a href=\"http:\/\/www.allmusic.com\/album\/clockwork-angels-mw0002332023\"><i>Clockwork Angels<\/i><\/a><\/p>\n<\/blockquote>\n<p>It was <a href=\"https:\/\/twitter.com\/vasilis\/status\/216479324939878400\">Vasilis who pointed out<\/a> that the correct order of the nesting becomes immediately apparent if you add more text, only <em>some<\/em> of which belongs inside the inner tag:<\/p>\n<pre class=\"code\"><code class=\"html\" data-language=\"html\">&lt;a href=\"http:\/\/us.macmillan.com\/redshirts\/JohnScalzi\"&gt;&lt;i&gt;Redshirts&lt;\/i&gt; by John Scalzi&lt;\/a&gt;<\/code><\/pre>\n<blockquote>\n<p><a href=\"http:\/\/us.macmillan.com\/redshirts\/JohnScalzi\"><i>Redshirts<\/i> by John Scalzi<\/a><\/p>\n<\/blockquote>\n<p>So that&#8217;s the answer: for linked titles (<a href=\"http:\/\/dev.w3.org\/html5\/spec-LC\/text-level-semantics.html#the-i-element\">or ship names, or taxonomic designations<\/a>), the link always goes on the <em>outside<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I tweeted a question the other day about nesting &lt;em&gt; and &lt;a&gt; tags, to figure out which is better: &lt;em&gt;&lt;a href=&#8221;#&#8221;&gt;blah&lt;\/a&gt;&lt;\/em&gt; or &lt;a href=&#8221;#&#8221;&gt;&lt;em&gt;blah&lt;\/em&gt;&lt;\/a&gt; blah or blah Both are valid HTML, and browsers render them the same way. I&#8217;m also pretty sure that I&#8217;ve used them interchangeably in the past, and that I&#8217;ve asked myself &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sunpig.com\/martin\/2012\/06\/25\/nested-tags-for-italicized-hyperlinks\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Nested tags for italicized hyperlinks&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2322","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/posts\/2322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/comments?post=2322"}],"version-history":[{"count":0,"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/posts\/2322\/revisions"}],"wp:attachment":[{"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/media?parent=2322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/categories?post=2322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunpig.com\/martin\/wp-json\/wp\/v2\/tags?post=2322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}