No `.../>` needed for input tags?

Could someone explain this html matter:

Using the inspector tool to study the input fields, e.g the title field, I note that there is no closing tag (e.g </input>) - this is expected as I find info that none is needed.

But it does seem to need a closing .../> which is not seen in the TW code - !?

Thanx.

<input .../> is a void element.

Input is one of the so called void-elements like eg: <br> which cannot have child elements in the body.

In short: Early 2000 there was an attempt to make browsers use the XHTML spec, which was closer to XML with much stricter rules. It was an attempt to make web pages a native data interchange format.

But the rules where way to strict. The internet needs to work even if the page syntax is full of errors. XTHML is not flexible with that point.

The self-closing syntax eg: <br/> is a remnant of these days, which is still allowed in HTML, but does not make a difference for void elements.

1 Like

OK, so my conclusion is that input can therefore optionally end with > or />.

Thanks guys.

Seemingly. MDN always uses /> while the HTML spec rarely does.

Spec example:


https://html.spec.whatwg.org/multipage/input.html#the-input-element

I personally like it. For me it’s a bit more readable. As a programmer I know that I do not need to search for an end-tag. Since there is none.