3 ms·
In XML terminology (where XHTML derives from), "tags" are the delimiters of "elements". So we have "start-tags", "end-tags", and "empty-element-tags".[1] "Eleme
by Archelaos 3y ago
In XML terminology (where XHTML derives from), "tags" are the delimiters of "elements". So we have "start-tags", "end-tags", and "empty-element-tags".[1] "Element" refers to the composition of the delimiting tags and all of their (nested) content.[2]
[1] https://www.w3.org/TR/xml/#sec-starttags https://www.w3.org/TR/xml/#sec-starttags
[2] https://www.w3.org/TR/xml/#sec-logical-struct https://www.w3.org/TR/xml/#sec-logical-struct
- ChrisMarshallNY 3y agoThat makes great sense. I never used "tag" properly, then. But for complete elements, like <br /> or <hr />, would it be proper to refer to them as "tags"?
- d1sxeyes 3y agoDepends on what you’re talking about, to be honest. The “element” is the “thing”. The “tag” is how you tell the browser what you want. This is why you have DOM functions like “getElementsByTagName”, which allows you to say “I know the tag name is “hr” (and the tag is <hr />), but I want to get references to all the elements which are defined by that tag. As a general rule, if you’re thinking about a “thing” on a webpage, you’re think about an element. If you’re thinking about what you need to write to get that element to appear on the webpage, you’re thinking about a tag. Most of the time, folks will understand what you mean even if you use the wrong one though.
- Archelaos 3y agoIn XML, they are referred to as "empty-element tags" and are functionally equivalent to a start tag immediately followed by an end tag, such as <br></br> or <hr></hr>. If a tag has no content, it can in principle also be written as an empty-element tag, for example: </p>. However, such use is not recommended: "For interoperability, the empty-element tag SHOULD be used, and SHOULD only be used, for elements which are declared EMPTY."[1] "For interoperability" is defined as: "Marks a sentence describing a non-binding recommendation included to increase the chances that XML documents can be processed by the existing installed base of SGML processors which predate the WebSGML Adaptations Annex to ISO 8879."[2a] "SHOULD" is explicitly[2b] used as defined in RFC 2119: "This word [...] mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course."[3] [1] https://www.w3.org/TR/xml/#NT-EmptyElemTag https://www.w3.org/TR/xml/#NT-EmptyElemTag [2a][2b] https://www.w3.org/TR/xml/#sec-terminology https://www.w3.org/TR/xml/#sec-terminology [3] https://www.ietf.org/rfc/rfc2119.txt https://www.ietf.org/rfc/rfc2119.txt