Search code examples
htmltwitter-bootstraphref

Is this html valid (button link)


I require a button to be a link to a new window.

My code works in all desktop browsers I have tried so far, however when I run it through the W3C validator I get the error below;

The element button must not appear as a descendant of the a element.

<a href="http://www.example.com"><button type="button" class="btn btn-success">contact</button></a>

If somebody could tell me how it should look in order to be sematically correct I would be very grateful.

Note I am using the bootstrap framework hence the btn class.


Solution

  • You already answered your question. The HTML is invalid.

    Just give the a element the classes that the button element had:

    <a class="btn btn-success" href="http://www.example.com">contact</a>
    

    Example Here - the appearance is the same.