HTML <button> Tag โ Clickable Button
๐ Introduction
The <button> tag is used to create a clickable button in HTML.
It can be used for:
- Submitting forms
- Running JavaScript actions
- Navigation (in some cases)
- Interactive UI elements
๐งฑ Syntax
<button>Click me</button>
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>Button Example</title>
</head>
<body>
<h2>Simple Button</h2>
<button>Click Me</button>
</body>
</html>
๐ฅ๏ธ Output Explanation
- A clickable button appears
- It can trigger actions (especially with JavaScript)
- Used inside forms or standalone
๐ฏ Button Types
1. Submit Button
<button type="submit">Submit</button>
โ Sends form data
2. Reset Button
<button type="reset">Reset</button>
โ Clears form inputs
3. Normal Button
<button type="button">Click</button>
โ Used for JavaScript actions
๐ง Important Concept
๐ <button> is more flexible than <input type="button">
| Element | Feature |
|---|---|
<button> |
Can contain text + icons + HTML |
<input> |
Only text value |
๐งฉ Example in Form
<form>
<input type="text" placeholder="Name" /><br /><br />
<button type="submit">Send</button>
</form>
โ๏ธ Button with JavaScript
<button onclick="alert('Hello!')">Click Me</button>
โ Triggers an action
๐จ Styling Example
<button style="padding:10px; background:blue; color:white;">Submit</button>
๐ซ Common Mistakes
- Forgetting
typein forms โ - Using button outside form without purpose โ
- Not distinguishing submit vs normal button โ
๐งช Mini Exercise
Create a page with:
- A form with inputs
- A submit button
- A reset button
- A normal button that shows an alert