For example. here is simple form (that I often use):
<form class="login">
<input class="login_username" type="text" value="username"/>
<input class="login_password" type="text" value="password"/>
<input type="submit" value="Login"/>
</form>
But I read some books, and see some of my friends often do:
<form class="login">
<div class="login_username">
<input class="login_input" type="text" value="username"/>
</div>
<div class="login_password">
<input class="login_password" type="text" value="password"/>
</div>
<input type="submit" value="Login"/>
</form>
The difference is: they often wrap all components inside a div tag, and then assign its a class name (although inside div tag has only one component). I don't know which advantages when they do this.
Thanks :)
Div tag has both open(<div>) and closing (</div>) tag and it is mandatory to close the tag. The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages.
The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!
It is totally fine . The form will submit only its input type controls ( *also Textarea , Select , etc...). You have nothing to worry about a div within a form .
Using this as a example. Yes, putting an anchor around a block is valid in HTML5 specs. Try cutting and pasting the script into the free online validator or pasting the link to your web page.
WHATWG: 4.10.1.1 Writing a form's user interface
Any form starts with a
form
element, inside which are placed the controls. Most controls are represented by theinput
element, which by default provides a text control. To label a control, thelabel
element is used; the label text and the control itself go inside thelabel
element. Each part of a form is considered a paragraph, and is typically separated from other parts usingp
elements. Putting this together, here is how one might ask for the customer's name:
<form>
<p><label>Customer name: <input></label></p>
</form>
WAI: Forms > Grouping Controls
Grouping related form controls makes forms more understandable for all users, as related controls are easier to identify... In this example, the
div
element hasrole=group
to indicate that the contained elements are members of a group and thearia-labelledby
attribute references the id for text that will serve as the label for the group...
<div role="group" aria-labelledby="shipping_head">
<div id="shipping_head">Shipping Address:</div>
<div>
<label for="shipping_name">
<span class="visuallyhidden">Shipping </span>Name:
</label><br>
<input type="text" name="shipping_name" id="shipping_name">
</div>
[…]
</div>
<div role="group" aria-labelledby="billing_head">
<div id="billing_head">Billing Address:</div>
<div>
<label for="billing_name">
<span class="visuallyhidden">Billing </span>Name:
</label><br>
<input type="text" name="billing_name" id="billing_name">
</div>
[…]
</div>
It also recommends to use <fieldset>
and <legend>
elements. <fieldset>
element provides a container for related form controls, and the <legend>
element acts as a heading to identify the group.
Other than those, Styling and Manipulating are the main reasons for lots of developers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With