Friday, January 24, 2025
HomeProgrammingHow Do I Create an HTML Button That Acts Like a Link?

How Do I Create an HTML Button That Acts Like a Link?

To create an HTML button that acts like a link, you can use the <button> element and handle the redirection using JavaScript, or you can style an <a> (anchor) tag to look like a button.

  1. Using <button> with JavaScript:
html
<button onclick="window.location.href='https://www.example.com';">Go to Example</button>

This method uses JavaScript to navigate to the link when the button is clicked.

  1. Using <a> styled as a button:
html
<a href="https://www.example.com" class="button">Go to Example</a>

And add some CSS to make the link look like a button:

css
.button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
text-decoration: none;
border-radius: 5px;
}

This way, the link will appear as a button but behave as a hyperlink.

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