Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

Lesson 2 - HTML Tags And Elements

2.4 Buttons

Buttons in HTML allow you to create interactive elements that users can click on. The <button> tag is used to define a button.

Simple Example

<button>Click Me!</button>

In the example above, <button> creates a clickable button labeled "Click Me!".

Interactive Example

<button onclick="alert('You clicked the button!')">Click Me!</button>

In the interactive example, <button> also creates a clickable button labeled "Click Me!". When clicked, it triggers an alert dialog that says "You clicked the button!".

Attributes such as type, name, and value can be added to <button> tags for different functionalities:

  • type: Specifies the type of button (submit, reset, or button).
  • name: Provides a name for the button, useful when submitting form data.
  • value: Assigns a value associated with the button.

Buttons can be styled using CSS to enhance their appearance and usability on webpages.