Search code examples
htmlbuttonhyperlinklinkbutton

Button as a Link


I want to know what is the difference between both codes , the first isn't working while the second is working properly , so what causes this .Help appreciated.

<a href="https://www.google.com" target="_blank">
  <button> Next </button>
</a>

<button>
  <a href="https://www.google.com" target="_blank"> 
    Next Page
  </a>
</button>


Solution

  • Both are invalid. HTML does not allow links to contain buttons or vice versa.

    The error handling routines in browsers are just different for the two cases.

    If you want a link that looks like a button then use a link and apply CSS.