275

Is it valid to have <input> without it being in a <form>?

Have a process for marking up some fields in pages and just found a page with input fields that where not being marked up as I expected.
It's taken me a while but worked out that the process of getting the form elements then getting the fields is what caused these to be missed because there is no form.

4

7 Answers 7

232

<input> without a <form> appears valid, yes (at least for html 4.01, look near the end of 17.2.1):

The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces. This is discussed in the section on intrinsic events. Note that controls outside a form cannot be successful controls.

8
  • 8
    To be able to submit form data to a server (Ajax aside). Sep 9, 2013 at 8:07
  • 5
    @PhilipSmith I know your comment was written a long time ago. But why do you think this is odd or pointless? Why would I want to create a form if the control is not communicating with a server?
    – adam-beck
    Mar 25, 2015 at 18:00
  • 22
    What's a "successful control"? Jul 11, 2015 at 12:14
  • 30
    When a form is submitted for processing, some controls have their name paired with their current value and these pairs are submitted with the form. Those controls for which name/value pairs are submitted are called successful controls. w3c Nov 12, 2015 at 10:08
  • 5
    @adam-beck For example, a certain AngularJS website handles inputs, manipulates data, and sends it to an api. HTML templates for forms may be written without any form tags and they communicate with the server just fine.
    – sr9yar
    Aug 1, 2016 at 20:39
93

I checked the following with the W3C validator and it confirms this is valid.

<!DOCTYPE html>
<html>
<head>
  <title>test</title>
</head>
<body>
  <input type='text' />
</body>
</html>
19

Reference to a more up-to-date specification:

HTML 5.2 - W3C Recommendation (14 December 2017)

A form-associated element can have a relationship with a <form> element, which is called the element’s form owner. If a form-associated element is not associated with a <form> element, its form owner is said to be null.

13

According to MDN it is possible:

Note that it's always possible to use a form widget outside of a element but if you do so, that form widget has nothing to do with any form. Such widgets can be used outside a form, but then you should have a special plan for such widgets, since they will do nothing on their own. You will have to customize their behavior with JavaScript.

HTML5 introduces the form attribute on HTML form elements. It should let you explicitly bind an element with a form even if it is not enclosed within a form tag. Unfortunately, for the time being, the implementation of this feature across browsers is not yet good enough to rely on it.

13

I know this question is quite old, however, I have successfully built many complex data entry pages without form tags. Although it isn't considered "standard" by many, it is NOT inappropriate to use inputs without a <form>. My projects were instances where I needed complete control over how the page behaved and the default form behavior was getting in the way. Was able to perform page and field level validation ( using JS ) and "submitted" the data with Ajax calls etc...in fact, this is my preferred way these days.

Lots of JS is required, but its not that difficult and is easily done as reusable code.

There are also other instances where I def do NOT use forms with inputs such as Login Pages.

Hope this testimonial helps someone.

4

in my point of view , we can use input outside the form and even send data to the server without put the input in the form ,but for SEO and website readability(for visually impaired people)(just the same reason for the some semantic content tags in HTML5 , like section ,footer, header something like that ), we have to use input in the form tag.It is important that we ensure the code we use is available to all people including the visually impaired people because it is not just about websites, it is about providing access to information for everyone.

1
  • how do you send data if the input field is outside of the form? is that possible. Nov 23, 2022 at 10:04
0

Yes, you can have a valid input without a form.

2
  • 23
    Well, you could have added some evidence behind the 'yes'. Or a clarification of which versions of HTML this is true for. Still, I wouldn't have downmodded you. Jul 21, 2010 at 12:59
  • 10
    So with your rationale why even have SO at all if the user can just go to W3 and look it up himself? I wouldn't have downvoted you either, but I'd have to agree that the one with more explanation in a clear and concise manner gets the upvote, because an explanation as well as the correct answer is what is most helpful here at SO.
    – Mattygabe
    Jan 19, 2011 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.