Can we include an anchor tag inside a button or vice-versa in HTML?
Hello, say I need to style a link that will direct me to another web page. My question is can we have a button and inside that button have an anchor tag? Or we need the anchor tag to stand alone and style it?
4 Replies
Like doing something as follows:
or a button nested into an anchor tag
This is absolutely not allowed. No "interactive content" is allowed to be a child of a button. That prohibits links and other buttons. Aside from the fact that this is expressly prohibited in the HTML Standard, it would be very confusing, since you would not know which interaction you are doing when you click.
https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element
Also, you can use an HTML validator to determine if this kind of thing is allowed.

Yep I see , thanks !