button Tag in HTML

1
117

The <button> tag in HTML is used to create a clickable button on a web page. The button can be used to perform an action when it is clicked, such as submitting a form, opening a new page, or triggering a JavaScript function.

Syntax:

The basic syntax for the <button> tag is as follows:

<button>Button Text</button>

Attributes:

The <button> tag can have several attributes that can be used to customize its appearance and behavior. Here are some of the most commonly used attributes:

  • type: This attribute specifies the type of button. It can be set to “submit” to submit a form, “reset” to reset a form, or “button” to create a regular button that doesn’t perform any action by default.

<button type=”submit”>Submit</button>

name: This attribute specifies the name of the button. It is useful when submitting a form, as it allows the server to identify which button was clicked.

Also Read:  Code Tag in HTML

<button type=”submit” name=”submit-btn”>Submit</button>

value: This attribute specifies the value of the button. It is also useful when submitting a form, as it allows the server to determine which value was selected.

<button type=”submit” value=”1″>Yes</button>
<button type=”submit” value=”0″>No</button>

disabled: This attribute disables the button and prevents it from being clicked.

<button type=”submit” disabled>Submit</button>

onclick: This attribute specifies a JavaScript function to be executed when the button is clicked.

<button onclick=”myFunction()”>Click me</button>

Example:

Here is an example of a <button> tag with some of the attributes mentioned above:

<button type=”submit” name=”submit-btn” value=”1″ onclick=”myFunction()”>Submit</button>

In this example, the button will submit a form with the name “submit-btn” and value “1” when clicked, and will also execute the “myFunction()” JavaScript function.

Previous articlebr Tag in HTML
Next articleCanvas Tag in HTML
Namaskaar, Friends main Kapil byteshastra.com ka Founder hu. Mere kai English blog bhi hai ,par mera motive yahan par easy language mein Technology se related Gyan ko aap tak pahunchane ka hai .taki aap kuch naya shikh sake. meri koshish hai ki bilkul simple tarike se aap ko nyi updates deta rahu taki aap bhi technology ke is yug mein peeche na rahe aur shikte rahe.Mujhse judne ke liye app mujhe Social Media par follow kar sakte hai.

1 COMMENT

Leave a Reply