A button element is accepted anywhere in the document body where text-level tags are allowed. Such elements need not be related to form elements. Although the button element has a unique default rendering, it is best to use buttons only for items that are designed to perform a specific action when clicked. Button elements outside the form have type=button as their"/> A button element is accepted anywhere in the document body where text-level tags are allowed. Such elements need not be related to form elements. Although the button element has a unique default rendering, it is best to use buttons only for items that are designed to perform a specific action when clicked. Button elements outside the form have type=button as their">

Home  >  Article  >  Web Front-end  >  Are button HTML tags valid outside a form?

Are button HTML tags valid outside a form?

PHPz
PHPzforward
2023-09-23 09:05:02737browse

Are button HTML tags valid outside a form?

This article will tell us that button HTML tags outside the form are valid. Before we begin, let’s talk about the HTML

HTML

HTML

grammar

The following is the syntax of HTML

<button type= “..”></button>

Button elements are accepted anywhere in the document body where text-level markup is allowed. Such elements need not be related to form elements. Although the button element has a unique default rendering, it is best to use buttons only for items that are designed to perform a specific action when clicked.

Button elements outside the form will have type=button as their default value. This suggests that JavaScript is the only way it works. However, you might consider creating such buttons using JavaScript instead of having them as static HTML text.

The following is an example of valid HTML button tags outside a form.

Example

In the example below, we use formid and div to create buttons outside the form.

<!DOCTYPE html> 
<html> 
<body> 
   <div> 
      <form id="my tutorial" action="https://www.tutorialspoint.com/index.htm"> 
         <label for="fname">NAME:</label> 
         <input type="text" name="fname"></input> 
      </form> 
      <button type="submit" form="my tutorial">SUBMIT</button>
   </div> 
</body> 
</html>

When the script executes, it will generate an output consisting of a name input field and a submit button. When you click the submit button, the form will submit to the mentioned form action.

The above is the detailed content of Are button HTML tags valid outside a form?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete