[HTML] How to Use a tag as a Button as button tag doesn’t support href
How to Use <a> as a Button as <button> doesn’t support href
No href in <button>
By HTML standards, <button> elements don’t have an href attribute. That’s why something like:
<button class="btn" href="/some-url">Click Me</button>
won’t navigate anywhere. It’s simply not recognized as a link.
Two Ways to Navigate or Submit
Anchor Tag Styled as a Button
If a clickable link that looks like a button is desired, use
<a> with Bootstrap classes:<a class="btn btn-primary" href="/somewhere">
Click Me
</a>
This navigates to
/somewhere on click.Form Submission
If a button to submit a form is desired:<form action="/blog/sign_up" method="post">
<!-- form inputs -->
<button type="submit" class="btn btn-primary"> Sign Up</button>
</form>
/blog/sign_up.
Comments
Post a Comment