The origin is in the concept of empty elements in SGML, and the idea was that some elements act as content placeholders that will be inserted from an external source or from the environment. This is why img and input , for example, were declared empty in HTML or, more precisely, with declared EMPTY content (i.e. Without content, as opposed to elements that simply accidentally have empty content). For a more detailed explanation, see My page Empty Elements in SGML, HTML, XML, and XHTML .
The implication is that the start tag for such an element is also a closing tag. It is expected that software that processes SGML or HMTL documents will know from the document type definition (DTD) that those tags have this property. In practice, such information is embedded in web browsers. Using an end tag such as </input> is incorrect, but browsers simply skip an unrecognized or false end tag.
In XML, therefore, in XHTML, everything is different, because XML is a very simplified version of SGML, designed to simplify processing. XML processing software should be able to do all the parsing without any DTD, so XML requires closing tags for all elements, although you can (and, for compatibility, in most cases) use special syntax like <input /> as a shorthand for <input></input> , but XHTML still does not support content between tags.
Thus, you cannot specify a label for the input element inside the element itself, since it cannot have any content. You can use the title , value or (in HTML5) placeholder attributes to associate texts with it, in different senses, but in order to have normal visible content as a label, it must be in another element. As described in other answers, it is recommended that you put it in the label element and define the relationship with the id and for attributes.
Jukka K. Korpela Nov 05 2018-12-12T00: 00Z
source share