44

I was wondering if I can use the fieldset tag without being inside a form. Because I like the way it encloses the legend & the border stuff around the inner html. When I use it to enclose li element, it does behave like its actually there(visual) inside a form.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Clone
  • 919
  • 4
  • 11
  • 22

3 Answers3

49

It's valid HTML5. Paste the following HTML at the validator: http://validator.w3.org/check:

<!DOCTYPE html>
<html>
<head><title>Title</title></head>
<body>
    <fieldset> <legend>Test</legend> </fieldset>
</body>
</html>

It's also valid HTML4. Replace <!DOCTYPE html> with the following, and it still passes the validation:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Rob W
  • 341,306
  • 83
  • 791
  • 678
8

You can use any form elements outside of an actual form, since most of them can be used with JavaScript utilities outside the form. The form is only needed if you plan on allowing the user to submit the data with it.

animuson
  • 53,861
  • 28
  • 137
  • 147
7

One thing to keep in mind is that you should separate structure and design. Do you want a fieldset because it is a fieldset or because the fieldset looks nice?

See also:

Frank van Wijk
  • 3,234
  • 20
  • 41
  • I have flash graphs so I want them to be in some container which separates each graph. So Im using `fieldset` tag – Clone Mar 22 '12 at 01:50
  • 6
    If you want "some container", why don't you use a `div` - which is meant for that - and style it the way you want? – Frank van Wijk Mar 22 '12 at 09:33
  • 1
    For me, it did the job, instead of fieldsets. Caring about the logic of your programming/layouting-language is not a bad thing! – GGolem Apr 08 '15 at 16:51
  • 1
    I want it because it looks nice and reproducing it is [apparently hard](https://stackoverflow.com/q/2213881/1026). – Nickolay May 11 '18 at 12:36
  • 1
    @Nickolay that's a real real bad practice. Semantics matter. – ed1nh0 Jul 22 '20 at 18:19