24

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!

datasn.io
  • 12,564
  • 28
  • 113
  • 154
  • 2
    Nice answer [here](http://stackoverflow.com/questions/9812898/is-it-wrong-to-use-the-fieldset-tag-without-form-tag) – Déjà vu Nov 11 '12 at 16:24
  • 1
    Unfortunately, five years later, the linked page is gone. Perhaps someone would like to create a minimal example showing what was meant? – Tom Zych Jul 09 '14 at 23:07
  • Given that simulating the `fieldset` appearance requires [quite complex solutions](https://stackoverflow.com/q/2213881/1026), I think the practical solution is to just use it (while keeping in mind [it requires resetting min-width](https://stackoverflow.com/q/1716183/1026) to behave as a drop-in replacement for a `div`). – Nickolay May 11 '18 at 12:34

9 Answers9

32

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

David Smith
  • 38,044
  • 11
  • 44
  • 61
  • 3
    Example correct usage: Imagine you want to have one form per each input and submit those forms on input change. If you want to group those inputs, you got to put `form` elements inside fieldsets. – skalee Feb 04 '12 at 17:11
  • 6
    There is nothing in the spec AFAI can see that indicates using fieldset for grouping information together is incorrect usage, both in terms of syntax and semantics. For example, if you need to display both a shipping and billing address, it's a great way to place a border around each and inset a "Shipping" or "Billing" into the border to distinguish the context of each. – AaronLS Feb 25 '14 at 18:44
  • 3
    Would it be semantically acceptable to have a form inside a fieldset? – Cameron Martin Apr 14 '14 at 15:06
  • 1
    Surely, a set of fields on a form is just as valid as the same set of fields being shown on a corresponding confirmation/summary page? – ban-geoengineering Apr 29 '22 at 22:48
10

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).

phorgan1
  • 1,664
  • 18
  • 18
  • This is what I'm using it for. I wrote a calculator that doesn't actually submit to a server. It outputs to some text fields. I decorate the fieldset to make the fields stand out. I use text fields instead of regular text so they can easily be selected on mobile. – Dex Oct 18 '17 at 08:23
8

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).

Gumbo
  • 643,351
  • 109
  • 780
  • 844
5

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.

alexmeia
  • 5,241
  • 4
  • 24
  • 24
2

HTML5 has added new attributes for fieldset:

form_id - specifies one or more forms the fieldset belongs to

http://www.w3schools.com/tags/tag_fieldset.asp

RandyDaddis
  • 1,020
  • 10
  • 19
2

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.

lucian
  • 623
  • 10
  • 21
2

No, you don't need a fieldset in a form.

Peter Turner
  • 11,199
  • 10
  • 68
  • 109
1

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Jason Thurston
  • 347
  • 5
  • 7
1

Yes, because the fieldset element is used to group related form fields.

John Topley
  • 113,588
  • 46
  • 195
  • 237