2

In HTML5 it is possible to accept or not the inclusion/omission of the closing tags in <input> and in <p>.

How is it possible and why?

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
  • For the element, see https://stackoverflow.com/questions/13232121/closing-html-input-tag-issue/13232170#13232170 – BoltClock Oct 20 '18 at 13:14

2 Answers2

4

In HTML5 it is possible to accept or not the inclusion/omission of the closing tags in <input> and in <p>.

No. While the end tag for a <p> element is optional, the end tag for <input> is forbidden. It must not be included. (Although browsers are pretty good at error recovery).

How is it possible

HTML is designed that way.

Consequently, tools which parse HTML support it.

and why?

It has been that way since the earliest versions of HTML.

I've never seen an explanation for the decision-making process, but some of the benefits include:

  • Quicker to type
  • (Debatably) easier to read
  • Fewer bytes (which was more important when you consider Internet connection speeds in the 90s)
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    See https://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html and https://www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt which describe

    as a "paragraph marker".

    – BoltClock Oct 20 '18 at 13:08
-2

You can dismiss the closing tag almost everywhere, but it is not recommended, code shall not work properly. In some cases, like img, input, meta, link, etc. you don't need to add the closing tag, because you are not inputting any text in between tags (not in all cases).

Bukaj
  • 1
  • 2
    "it is not recommended " — No. The end tag for the input element is forbidden, it must be omitted. The end tag for the p element is optional. There is nothing wrong with omitting it. "code shall not work properly" — No. All browsers have consistent support for the HTML rules regarding optional and forbidden end tags. – Quentin Oct 20 '18 at 12:57
  • is a closing tag and is faster to interpret – Bukaj Oct 20 '18 at 13:28
  • 1
    It is not a closing tag. In HTML 5 it is a start tag with a pointless `/` on the end. In older versions of HTML it is a start tag followed by a `>` character which browsers are supposed to render (no current browser does because they are aligned to HTML 5 parsing rules). In XHTML it is a self-closing tag. It is not an end tag at all. – Quentin Oct 20 '18 at 13:29