0

On the bootstrap CSS guide, there are numerous examples like this:

  <div class="checkbox">
    <label>
      <input type="checkbox"> Check me out
    </label>
  </div>

Is it just me or is that input tag not closed? It's definitely not a typo - they seemingly never close input tags. What would be the reason to consistently do this?

eye_mew
  • 7,741
  • 7
  • 28
  • 42
  • Possible duplicate of [Are self-closing tags valid in HTML5?](http://stackoverflow.com/questions/3558119/are-self-closing-tags-valid-in-html5) – vanburen Jan 03 '17 at 09:42
  • I'd recommend to self-close void elements, though, as XML compatibility is so easy to achieve that way. – connexo Jan 03 '17 at 09:53

5 Answers5

3

The input tag is what is called a void element, and void elements do not require an end tag.

Here is a complete list of all void elements within HTML:

  • area
  • base
  • br
  • col
  • command
  • embed
  • hr
  • img
  • input
  • keygen
  • link meta
  • param
  • source
  • track
  • wbr

More about information void elements can be found here: Void Elements in HTML

GROVER.
  • 3,082
  • 1
  • 11
  • 48
2

The <input> element is defined as being a void element. The end tag for void elements is forbidden.

From the specification:

Tag omission in text/html: No end tag

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
  • OP didn't ask about end tags, he asked about *unclosed* input tags. – connexo Jan 03 '17 at 09:54
  • @connexo — End tags are how you close elements. – Quentin Jan 03 '17 at 09:55
  • On void elements you use self-closing syntax. I wouldn't exactly call that *end tag*. – connexo Jan 03 '17 at 09:57
  • 2
    @connexo — Self-closing syntax is an XML feature. It isn't part of HTML. – Quentin Jan 03 '17 at 09:58
  • I don't see OP's question being tagged HTML 5, but even if they did, they still didn't ask about end tags. They were obviously talking about self-closing syntax which is not mandatory, but perfectly valid HTML 5. – connexo Jan 03 '17 at 10:00
  • 1
    @connexo — "They were obviously" — No. It is not obvious that that is what they meant. – Quentin Jan 03 '17 at 10:02
  • Why would anyone consider invalid `` here? I disagree on your interpretation. Being a guy that comes from XHTML I strongly dislike HTML5 allowing for unclosed tags. Well-formedness is non-damaging, easy to achieve, and allows for validation by XML parsers. – connexo Jan 03 '17 at 10:11
  • @connexo — I disagree with pretty much everything in your last comment, but this really is not the right place to have a discussion about the merits and flaws of XHTML. – Quentin Jan 03 '17 at 10:16
0

According to w3schools.com, in HTML you do not need to close input tags at all. But, in XHTML, the <input> tag must be properly closed, like this <input/>.

Aneesh bhat
  • 3
  • 2
  • 7
0

Actually, is a void element which means it's goal is not to contain text or whatever and it has a start tag but you shouldn't add an end tag.

This would not be W3C valid. On the other end, non-void elements MUST have an end tag.

(List of void elements : area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr)

-1

The input tag doesn't need a closed tag.

Just in xHTML the tag must be closed properly: <input />

Yossi Aharon
  • 111
  • 1
  • 10