Home 〉 HTML Tutorials 〉 HTML '<button>' Tag - Syntax, Attributes, Examples & Styling
HTML '<button>' Tag - Syntax, Attributes, Examples & Styling !
What is the purpose of the HTML '<button>' tag, and how do you use it effectively in web design?
This blog post explained the '<button>' tag, its syntax, whether it's a block-level element, and detailed attributes with examples. We also showed how to apply inline CSS for a visually pleasing button and discussed interlinking strategies and external references to improve SEO. From simple form buttons to dynamic interface elements, the HTML '<button>' tag plays a key role in web interaction. The details blog post on HTML button tag is as follows.
The HTML '<button>' tag is used to create interactive buttons in a web page. These buttons can submit forms, reset form data, or trigger JavaScript functions. The '<button>' tag is a flexible element and is widely used in forms, UI designs, and navigation actions.
Syntax ✍
<button type="submit">Click Me</button>
The '<button>' tag is a block-level element, but its behavior can be styled using CSS to act inline as well.
Here are common attributes supported by the '<button>' tag:
Specifies the button type.
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
This button resets all form inputs to their default values.
Defines the name for the button, used when submitting form data.
<!DOCTYPE html>
<html>
<body>
<button type="submit" name="submitBtn">Submit</button>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The form will send "submitBtn" as the key in form data.
Sets the value sent to the server when the form is submitted.
<!DOCTYPE html>
<html>
<body>
<button type="submit" name="submitBtn" value="Send">Send</button>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Sends the value "Send" to the server.
Disables the button, making it non-clickable.
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
This button cannot be clicked or submitted.
Automatically focuses the button when the page loads.
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The button gets focus when the page loads.
Associates the button with a specific form using the form's 'id'.
<!DOCTYPE html>
<html>
<body>
<form id="myForm"></form>
<button form="myForm" type="submit">Submit</button>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The button is linked to '#myForm' and submits it.
<!DOCTYPE html>
<html>
<body>
<button style="font-size:16px; padding:10px 20px; background-color:#28a745; color:white; border:none; border-radius:5px;">
Styled Button
</button>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
This button looks clean and professional using CSS properties like 'font-size', 'padding', 'background-color', and 'border-radius'.
The '<button>' tag in HTML is a versatile element used to create clickable actions. With attributes like 'type', 'name', 'value', and 'disabled', it plays a crucial role in forms and UI interactions. Styling buttons with inline CSS makes them visually appealing. Whether you're creating a simple form or an interactive webpage, understanding the '<button>' tag is essential for modern web development.
The default is 'submit'. Others include 'reset' and 'button'.
Yes, you can place images or even icons (like from Font Awesome) inside a '<button>'.
'<button>' can contain HTML (text, images), while '<input>' is self-closing and cannot.
No, you must use the 'disabled' attribute.
Yes, but ensure each has the correct 'type' to avoid unintended form submissions.