I dont know anything about DTD.
http://www.bls.gov/oco/ocos292.htm
See how fieldset is used outside of form on this page and it's cool! I love the style!
I dont know anything about DTD.
http://www.bls.gov/oco/ocos292.htm
See how fieldset is used outside of form on this page and it's cool! I love the style!
I think the question and chosen answer in this question are misleading. Whether or not a form
has to have a fieldset
, and whether or not a fieldset
has to be in a form
are two different questions with two different answers.
According to the HTML4.01 spec, a fieldset is a valid element inside of a form, but as it is a standard block-level element, it is also acceptable elsewhere: http://www.w3.org/TR/html401/interact/forms.html#h-17.10 http://www.w3.org/TR/html401/sgml/dtd.html#block
I can not, however, imagine a use case where this would be done, unless you are using the fieldset for decorating, which would be incorrect usage.
A form however, does not require a fieldset: http://www.w3.org/TR/html401/interact/forms.html#h-17.3
Bumping because no one gave a valid use case for a fieldset sans form. A valid reason to use a fieldset without a form is when you are using the inputs to gather information for a dynamic display. Each change of an input makes a difference in the displayed information. There is no sense of filling out a form and clicking submit. You could put a form around the fieldset, but it would be useless. The fieldset, however, visually groups the inputs used to control the display, (or game or whatever).
FIELDSET
is a regular block level element and can be used in any place where block level elements are allowed (except in a BUTTON
element).
If you put a fieldset outside a form, the page validates, but I don't see any good reason to do it, and if you read the xhtml 1.0 DTD you find this comment in the fieldset section:
The fieldset element is used to group form fields. Only one legend element should occur in the content and if present should only be preceded by whitespace.
HTML5 has added new attributes for fieldset:
form_id - specifies one or more forms the fieldset belongs to
It needn't be inside a form but it better be at least related to a form with form="[form_ID]"
.
A valid use case is when you have multiple sets of controls that are spread throughout pieces of non-form content. In this case you'd normally have to either put everything, related or not, inside the form (bad) or repeat the same form over and over (weird).
Whereas just linking all fieldsets to the single form is so much easier.
Example: a test or poll or whatnot that requires a bit of feedback after each section.
No, you don't need a fieldset in a form.
I used a fieldset outside of a form to group together custom jquery datatable filters. I had several "select" dropdown elements in the fieldset, each for a different category of filtering. I had onchange events attached to each dropdown so that when something was selected the rows in the data table would be filtered accordingly. Actual form tags really don't seem necessary nowadays with javascript/jquery.
Yes, because the fieldset element is used to group related form fields.