For you to understand the right way to build a form mark-up, you need to read the specs: http://www.w3.org/TR/html401/ and interpret them according to content model definitions: http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.3.3.1.
For forms, you have this content model:
[INDENT][/INDENT]<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) – interactive form –>
which is to say:
- the element form has mandatory start and ends tags: <!ELEMENT FORM - -
- it must contain (it can have as direct descendents) at least one of the two elements from a group of elements: (%block;|SCRIPT)+
- it cannot contain another form: -(FORM)
Now, looking at the &block definition:
[INDENT]<!ENTITY % block
“P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS”>[/INDENT]
you will notice you can have both div and fieldset as direct descendants for the form element (div | fieldset). But since you are in a form, draw your own conclusion on which one is more suitable, looking at those two examples below, as they are, no CSS, no JS. Aside, we see why they needed to include the exception for other form elements to appear inside another form, since the form element is listed also there, as a block.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title></title></head><body>
<FORM action="http://somesite.com/prog/adduser" method="post">
<div>
First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
email: <INPUT type="text" name="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</div>
</FORM>
</body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title></title></head><body>
<FORM action="http://somesite.com/prog/adduser" method="post">
<fieldset>
<legend>Personal data</legend>
First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
email: <INPUT type="text" name="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</fieldset>
</FORM>
</body></html>
Finally, a mix-up of the two:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title></title></head><body>
<FORM action="http://somesite.com/prog/adduser" method="post">
<fieldset>
<legend>Personal data</legend>
First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
email: <INPUT type="text" name="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</fieldset>
<div>
First name: <INPUT type="text" name="firstname"><BR>
Last name: <INPUT type="text" name="lastname"><BR>
email: <INPUT type="text" name="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</div>
</FORM>
</body></html>
Let’s start with this and see if you need any more debate. We’ll proceed with deeper fieldset explanation after all is clear here.