I'm overly simplifying here, but it's about the concepts.
In HTML, every tag has a meaning and a function. Sometimes it's purely aesthetics (<b>
, bold text), sometimes it's semantics (<span>
, a new chunk of inline text), sometimes both (<h1>
, a header starts here). The point is to mark portions of text with semantics.
The <a>
tag is a hyperlink. Almost everything between <a>
and </a>
is supposed to behave like this: if clicked, jump to certain URL. Now that URL is a property of the <a>
tag and you specify it via href
.
This href
does not make any sense outside of the <a>
tag since back when HTML was born, CSS and JavaScript didn't exist so you couldn't do things like making a <span>
clickable like we can today. But even today, it doesn't make sense to allow elements to adopt functionality of other elements as it taints their semantics.
In your second example you have completely removed the <a>
tag, so it isn't a link any more. Even if the parser allows href
on the div
, it'd be wrong to suddenly make it behave like an a
tag since it isn't.
a
around the whole div. If you're making a link, you can just do this:<p><a href="cake">This is not a lie.</a></p>
. – Hildegarda
tag and it'shref
property do? They create a hyperlink and you'd throw it away. – Issue<element>
and allow every attribute and property on it? – Melletaa
elements, i.e. hyperlinks, are interpreted by browsers as being links. – Hildegard