<button> : Button element

Introduction

The ‘<button>‘ element used to create clickable buttons on a web page. It is part of the HTML forms and is commonly used in conjunction with JavaScript to create interactive user interfaces. The ‘<button>‘ element can contain text, images, or other HTML elements, and it can trigger actions or events when clicked.

Here’s a basic example of a <button> element:

Output :

Buttons can also be styled using CSS to enhance their appearance and match the overall design of a webpage.

Uses of <button> tag :

The ‘<button>‘ element is a versatile element that can be used for various purposes on a web page. Here are some common uses of the ‘<button>‘ element:

1. Form Submission : Used as a submit button within HTML forms to submit form data to a server.

Syntax : ‘<button type=”submit”>‘.

Example :

Output :

2. Form Reset : Used as a reset button within HTML forms to reset the form fields to their initial values.

Syntax : ‘<button type=”reset”>‘.

Example :

Output :

3. Custom JavaScript Actions : Used to create buttons that trigger custom JavaScript functions or actions without submitting a form.

Syntax : ‘<button type=”button”>‘.

Example :

Output :

When we click on the button alert message is given.

4. Navigation : <button>‘ elements can be used to create navigation buttons that take users to different pages or sections of a website.

Example :

Output :

And when we click on the button we go to home page of the website.

5. Modal Windows/Dialogs : <button>‘ elements are often used to trigger the display of modal windows or dialogs.

Example :

Output :

And when we click on the button a modal window is open. and when we click on the ‘x‘ modal window is close.

And when we click on the ‘x‘ modal window is close.

6. Toggle Buttons :<button> elements can be used to create toggle buttons that switch between different states.

Example:

Output :

And when we click on the toggle button it will change.

7. Interactive Features : Used to create interactive features on a webpage, such as interactive quizzes, games, or any functionality that requires user interaction.

Example :

Output :

And when we click on the button it will change the color.

and

8. Styling and UI Design : <button>‘ elements can be styled using CSS to enhance their appearance and match the overall design of the website.

Example :

Output :

Leave a Comment