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

Are button HTML tags valid outside a form?

PHPz
Release: 2023-09-23 09:05:02
forward
763 people have browsed it

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>
Copy after login

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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template