HTML Buttons & Links Tutorial
Buttons and links are the most used interactive elements in websites. This guide explains how to create, style, and use <button> and <a> tags with real examples.
1. HTML Links (<a> Tag)
The <a> tag is used to create hyperlinks on a webpage.
<a href="https://example.com">Visit Website</a>
Common Attributes for Links
- href → The URL of the page
- target="_blank" → Opens link in new tab
- title → Tooltip when hovering
<a href="https://google.com" target="_blank" title="Open Google">Google</a>
2. HTML Buttons (<button> Tag)
Buttons are used to perform actions such as submitting forms or running JavaScript.
<button>Click Me</button>
Types of Buttons
- button → Normal button
- submit → Submit a form
- reset → Reset form values
<button type="submit">Submit</button>
<button type="reset">Reset</button>
3. Buttons with JavaScript
You can add functionality to buttons using JavaScript's onclick attribute.
<button onclick="changeText()">Change Text</button>
<p id="sample">Original Text</p>
<script>
function changeText() {
document.getElementById("sample").innerText = "Text Changed!";
}
</script>
Original Text
4. Convert Button into a Link
You can also style links like buttons.
<a href="https://youtube.com" class="btn">Go to YouTube</a>
<style>
.btn {
background: #ff0000;
color: white;
padding: 10px 20px;
border-radius: 5px;
text-decoration: none;
}
.btn:hover {
background: #cc0000;
}
</style>
5. Disable Buttons
<button disabled>Disabled Button</button>
Conclusion
HTML buttons and links are simple but powerful elements that help users interact with your website. You can style them, add JavaScript actions, and use them for navigation.

Comments
Post a Comment