Class – 14 | HTML Buttons | HTML Tutorial

HTML Buttons - Class - 14
HTML Buttons – Class – 14

HTML buttons are used to create interactive elements on web pages. They allow users to interact with the page by clicking, which can trigger specific actions or events. Here’s how to create a button in HTML:

<button type="button">Click me!</button>

The <button> element is used to create the button and the type attribute specifies the type of button, which in this case is a standard button (type="button"). The text inside the button element, “Click me!” will be displayed on the button.

By default, buttons are submit buttons, which means they will offer a form when clicked. If you don’t want the button to submit a form, you can use the type="button" attribute, as shown above.

There are several other types of buttons in HTML, including reset buttons and buttons that trigger JavaScript actions. Here’s an example of a reset button:

<button type="reset">Reset</button>

Here’s an example of a button that triggers a JavaScript function:

<button type="button" onclick="myFunction()">Click me!</button>

<script>
function myFunction() {
  alert("Button was clicked!");
}
</script>

In this example, the onclick attribute is used to specify the JavaScript function that should be triggered when the button is clicked. The function myFunction() displays an alert saying, “Button was clicked!”.

You can also style buttons using CSS to change their appearance, such as the color, font, and size.

This is just a basic introduction to HTML buttons. I hope you find it helpful when creating interactive web pages!

Next Class

See also  Class – 18 | HTML Iframes | HTML Tutorial

Hamza Raja

Website Developer, Blogger, Digital Marketer & Search Engine Optimization SEO Expert.

Leave a Comment