Greg Domjan
Greg Domjan

Reputation: 14105

Is <input> well formed without a <form>?

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

I have a process for marking up some fields in pages and just found a page with input fields that were not being marked up as I expected.

It's taken me a while, but I 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 element.

Upvotes: 286

Views: 136730

Answers (7)

Abdulla Ababakre
Abdulla Ababakre

Reputation: 61

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.

Upvotes: 4

G-Man
G-Man

Reputation: 1435

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.

Upvotes: 13

Adnan Faradhi
Adnan Faradhi

Reputation: 181

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.

Upvotes: 16

David
David

Reputation: 7285

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.

Upvotes: 22

Wai Yip Tung
Wai Yip Tung

Reputation: 18754

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>

Upvotes: 98

ChristopheD
ChristopheD

Reputation: 116157

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

Upvotes: 242

heisenberg
heisenberg

Reputation: 9759

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

Upvotes: 1

Related Questions