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?
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.
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With