Skip to main content
Practice

button Tag

The <button> tag is used to create interactive buttons in a web page that users can interact with.

For example, when a user clicks a button, it may trigger actions such as sending data to a server or navigating to another page.


Example of using the button tag
<button>Click Me!</button>

The code above creates a button with the text "Click Me!".


Adding functionality to a button

By itself, a button is just a clickable element. To make it perform a specific action, you need to use a scripting language like JavaScript.

For example, to display an alert message when the button is clicked, you can write the code as follows:

Display an alert message on click
<button onclick="alert('Button was clicked!')">Click Me!</button>

Follow the emphasized parts of the code to implement it.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.