Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML validation - Incorrect wrap of button #42

Open
oricis opened this issue Aug 2, 2020 · 3 comments
Open

HTML validation - Incorrect wrap of button #42

oricis opened this issue Aug 2, 2020 · 3 comments

Comments

@oricis
Copy link

oricis commented Aug 2, 2020

From the demo page: https://newcss.net/usage/elements/

The instructions for a link button:

Click me!

A "button" can't be wrapped in an anchor element.
This use doesn't pass HTML validators.

@bhenbe
Copy link

bhenbe commented Aug 3, 2020

One way to avoid this problem would be to favor the use of strong instead of button.

Like this:

<a href="https://example.com">
  <strong>Click me!</strong>
</a>

The fact is that a link to which we assign a button visual is often the case in order to emphasize its importance in a page. The strong tag responds in this sense better than the button tag. In terms of design, this is justified.

@simevidas
Copy link

simevidas commented Aug 9, 2020

For the record, the code example on the website is

<a href="https://example.com">
  <button>Click me!</button>
</a>

The HTML Standard states this for the content model of <a>:

Transparent, but there must be no interactive content descendant, <a> element descendant, or descendant with the tabindex attribute specified.

https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element

<button> is interactive and therefore not allowed.

@remino
Copy link

remino commented Jul 27, 2024

Old issue, I know, but this always irritated me as well. I guess the proper way to do a “link button” would be to simply wrap the button in a <form>:

<form action="https://example.com" method="get">
  <button type="submit">Go to Example</button>
</form>

It’s not that much more verbose than having a <a> wrap a <button>, but note <form> is display: block by default while <a> is display: span.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants