Monday, January 6, 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 create an HTML button that acts like a link, you can use the <button> element and attach an onclick event to navigate to a URL.

Example:

html
<button onclick="window.location.href='https://www.example.com';">Go to Example</button>
  • Explanation: The window.location.href changes the page’s URL, effectively acting as a link when the button is clicked.
See also  Difference between Operating system and Application

Alternatively, use a styled <a> tag with button-like styling:

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

With CSS:

css
.button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
text-align: center;
text-decoration: none;
border-radius: 5px;
display: inline-block;
}
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