Saturday, January 11, 2025
HomeTechHow do I create an HTML button that acts like a link?

How do I create an HTML button that acts like a link?

To make an HTML button act like a link, use a <button> element with JavaScript or style an <a> tag as a button. For the <button>, set an onclick attribute like this:

html
<button onclick="location.href='https://example.com';">Go to Example</button>

Alternatively, style an <a> tag using CSS to mimic a button:

html
<a href="https://example.com" class="button">Go to Example</a>
<style>
.button {
display: inline-block;
padding: 10px 20px;
background: #007bff;
color: #fff;
text-decoration: none;
border-radius: 5px;
}
</style>

Both approaches are widely used and effective.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x