Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

IIRC single HTML tags like input can be written as <input> or <input />. I'm just wondering which form is considered "proper" HTML.

share|improve this question

closed as off topic by slhck, Linker3000, ChrisF, Phoshi, nhinkle Sep 1 '11 at 21:25

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

These are called "self-closing tags". Questions about markup are off-topic for Super User, but you can read more about this by looking around on Stack Overflow, where they've been discussed before. – nhinkle Sep 1 '11 at 21:27
up vote 2 down vote accepted
  • HTML 4.0: Empty elements only have a start tag, as in SGML.


    Most browsers will accept XML-style self-closing tags.

  • XHTML, any version: Empty elements must be self-closing or have an end tag, as in XML. Self-closing tags are recommended.

    <input /> – recommended for compatibility

    <input></input> – valid XML but may be incompatible with HTML4-only browsers

  • HTML 5.0: Void elements only have a start tag, but a slash is allowed and ignored.


    <input />

share|improve this answer
Wow, the lack of standardization is terrible. I guess the best thing would be to use self-closing and hope no one uses HTML 4 only browsers. – darkfeline Sep 1 '11 at 21:34
@darkfeline Yep :) HTML was a mess, after all it became popular in the 90s hence all kinds of pages looking different in different browsers. If you wish to code toward standards take a look at w3schools. Including a type and making sure you adhere to standards is big help and will make your code more cross browser compatible. Microsoft is even building new browsers toward w3 standards (FINALLY!) but they are still a ways off. Use strict XHTML for best results though. – Jeff F. Sep 1 '11 at 21:37
@Jeff Noooooo w3schools! They're the last site I would suggest ... see w3fools why. – slhck Sep 2 '11 at 6:51

See the HTML 5 specification:

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

So if you are using one of the defined void elements of the HTML syntax, you can omit the / character. I usually put it for readability purposes, so you don't look for a corresponding closing tag. However, both versions are valid.

share|improve this answer

<input /> is considered proper, the reason is because input doesn't require multi line attributes.

<textarea> needs a </textarea> as it's basic body text is inside the tags, <input> has a value attribute so the tag can be be closed in one.

share|improve this answer
Depends on if you are coding in HTML or XHTML. <input> is considered proper for HTML but the web is moving to XHTML and thus <input /> is preferred. – Jeff F. Sep 1 '11 at 21:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.