-1

I've tried checking other answers, but I'm still confused--especially after seeing W3schools HTML 5 reference.

Note: The <input> element is empty, it contains attributes only.
In HTML, the <input> tag has no end tag.
In XHTML, the <input> tag must be properly closed, like this <input />.

Is it <input> or <input />?

alessandrio
  • 4,282
  • 2
  • 29
  • 40
  • 6
    You seem to have answered your own question with the question. – isherwood Sep 19 '14 at 20:04
  • 2
    1. Don't reference W3School. Ever. 2. Haven't you got your answer already? It depends if you're using HTML or XHTML. – BenM Sep 19 '14 at 20:05
  • 1
    @BenM why don't reference W3 Schools? – Vinz243 Sep 19 '14 at 20:06
  • For reasons too numerous to list here! Haha. http://www.w3fools.com/ – BenM Sep 19 '14 at 20:06
  • 1
    This is a duplicate already discussed [question]: http://stackoverflow.com/questions/3558119/are-self-closing-tags-valid-in-html5 – Norman Schleicher Sep 19 '14 at 20:15
  • While certainly not the best, W3Schools is a reasonably good resource for many topics. Folks like to put their noses up over it because of a few mistakes of the past. Apparently they don't make any themselves. I mention it because it was asked, not to debate the issue. – isherwood Sep 19 '14 at 20:42

3 Answers3

2

As you said, HTML uses <input> and there's no need for a closing tag </input>

However the XML language doesn't allow opening tags without closing tags. To specify a tag isn't expected to close, a " /" must be added

Hence XHTML (= XML + HTML) requires <input />

Or to be more precise XHTML is HTML made XML compliant

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164
  • You **can** use `` in "normal" HTML, but **must not** use ``. The latter syntax gets normalized to `` if there is any content/white spaces between `>` and ``. – Kijewski Sep 22 '14 at 10:58
0

The answer, which you've already alluded to in your question, is dependent on whether you are using HTML or XHTML. This is determined by a combination of your doctype and Content-Type HTTP header.

At this point, XHTML is effectively dead, and nearly everyone is using HTML. So for a practical answer: just use <input>. Even though HTML browsers typically understand both syntaxes, there are no compatibility gains to use the self-closing syntax and it's a whole extra character or two anyway.

Community
  • 1
  • 1
Stephen Booher
  • 6,522
  • 4
  • 34
  • 50
-1

The Some elements, however, are forbidden from containing any content at all. In HTML, the above syntax cannot be used for void elements. For such elements, the end tag must be omitted because the element is automatically closed by the parser. These are known as void elements. Such elements like: br, hr, img, link and meta (These are knowing as as unblocking tags).

Example:

In XHTML, the XML syntactic requirements dictate that this must be made explicit using either an explicit end tag, as above, or the empty element syntax. This is achieved by inserting a slash at the end of the start tag immediately before the right angle bracket (>).

Example:

Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well. Some authors also choose to include white space before the slash, however this is not necessary.

If you use Dreamweaver CS6, then it will autocomplete as
.

To validate your HTML file on W3C see : http://validator.w3.org/