Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantically, which is more correct: a in h2, or h2 in a?

I'm stuck deciding which to use as both seem to work.

Should I be placing links <a> inside of <h2> elements?

Or the other way around?

What is the correct standard?

like image 827
Only Bolivian Here Avatar asked Mar 18 '12 16:03

Only Bolivian Here


People also ask

Can I contain H2?

You can only place <h2> elements within <a> elements if you're working with HTML5, which allows any other elements within <a> elements. Previous specifications (or current ones however you want to look at them) never allowed this.

What does H2 mean in coding?

H2 heading tagIt defines the second-level headings on your webpage. Like an H1 tag, an H2 tag also appears larger than the rest of your main body text. However, H2 tags are always slightly smaller than your H1 tag, so that it does not compete with your main heading. Keep in mind that heading tags don't stop at H2.

Can I use H2 before H1?

H1 should come before H2 in a document. H2 is a sub element of H1. The way I approach a page is to code it in HTML first so that it makes sense to a user without JavaScript and CSS enabledProgressive Enhancement .

What is H2 H2?

Description. The HTML <h2> tag defines the second level heading in the HTML document. This tag is also commonly referred to as the <h2> element.


1 Answers

You can only place <h2> elements within <a> elements if you're working with HTML5, which allows any other elements within <a> elements. Previous specifications (or current ones however you want to look at them) never allowed this.

The usual way of doing this is to place <a> within <h2>. This works, has always worked, and has been the only valid way to do it before HTML5, for heading links, as the link refers to the text in that heading. You rarely need to place <h2> within <a> unless that <h2> is part of some more complex structure which functions as a hyperlink as a whole.

like image 73
BoltClock Avatar answered Sep 21 '22 07:09

BoltClock