Home > OS >  Can A Div be in a form in HTML5
Can A Div be in a form in HTML5

Time:12-31

<form >
  <label for="username" > Username:</label>
  <input 
    type="text"
    name="username"
    placeholder="eg Herny Hart"
    id="name-input"
    required>
  <label for="email" > Enter your Email: </label>
  <input
    type="email"
    name="email"
    placeholder="[email protected]"
    id="email-input"
    required>
  <label for="number">2fa Verification If required:</label>
  <input 
    type="text"
    name="number"
    placeholder="239578"
    id="2fa-input">  
<label>
    <div>
      <input id="submit" type="submit" value="Login">
      <input id="submit2" type="submit" value="Sign-up">
    </div>


</form>

I don't know if it is ok to put a div container inside a HTML5 form container or is it wrong.
Am new to coding i need help to complete my animation project

CodePudding user response:

Use MDN for questions like this. For this case, see here, and find the "Permitted content" section:

Permitted content: Flow content, but not containing <form> elements.

If you then click "Flow content" and read through the list, you'll see that div is listed as "Flow content":

. . .
<dfn>
<div>
<dl>
. . .

So yes, divs are allowed inside of forms.

CodePudding user response:

It is completely fine to put a DIV inside of a form.

CodePudding user response:

You can validate your HTML code by uploading it in W3C validator, keep the link, and it will be helpful for future, run every time if you are hesitating. https://validator.w3.org/#validate_by_upload

CodePudding user response:

Yes div can a part in a form also. for ex:

<html>
<head>
    <title> div</title>
    <style>
        body{
            background-color:lightgreen;
        }
    </style></em>
</head>
<body>
    <form action="">
        <div><label for=" abc">name
            <input type="text" placeholder="Enter your name" value="">
        </label></div>
    </form>
</body>
[enter image description here][1]
  •  Tags:  
  • html
  • Related