Is it possible or correct to put a div inside an anchor tag?


A webpage has anchor tag(<a>). You want to put a <div> element inside the <a> tag.

<a href=><div> this is a link </div></a>

But the problem is that <div> is a block element and <a> in an inline block element. Generally block element can’t sit inside inline block element. If you use “display: block” for the <a> tag, then is it possible to use <div> inside <a> tag?


Yes, it is possible in HTML5, because HTML5 allows <a> tag to be wrapped around a <div> element. So, <div> will be visible inside the anchor tag.

In HTML 4.0, inline elements aren’t allowed to be wrapped around block elements. But if you use “display:block” it will work fine. Because by doing so, <a> behaves like a block element.

N.B: It works fine but it won’t be validate. Because using block element inside inline element is discouraged. For that reason some browser doesn’t support this.