I am currently making a website, and I would like to know if there is ever a space after <
. By this I mean is there anything like < html>
or is there no such thing as a "command" that has a space after <
?
2 Answers
By this I mean is there anything like
< html>
or is there no such thing as a "command" that has a space after<
?
No, you cannot have a space immediately after the <
(less-than sign) in an HTML element's opening start tag.
From the HTML spec:
Start tags must have the following format:
- The first character of a start tag must be a U+003C LESS-THAN SIGN character (<).
- The next few characters of a start tag must be the element's tag name.
- :
There is no room for a space in there.
If you try this in a browser then it will likely output the malformed opening start tag as literal text. For example:
<p>Foo < b>bar</b> baz</p>
...is output in the browser as:
Foo < b>bar baz
-
That quote is not enough to answer the question. By the rules you defined,
!
wouldn't be valid either, but we all know that<!--
is a valid comment opening tag, or that<!DOCTYPE
is a valid doctype opening tag and maybe less people know that even<?
will actually fallback to the bogus comment state.– KaiidoCommented Mar 23, 2020 at 1:43 -
2There are actual parser instructions in the HTML spec nowadays: html.spec.whatwg.org/multipage/parsing.html#tag-open-state But the principle of the answer remains the same.– BoldewynCommented Mar 23, 2020 at 8:11
No. There is not normally a space between the "<" and following characters. The HTML tag will not be parsed correctly by browsers and it appears that a space in that position is not allowed in the HTML standards.
-
2What does this add that isn't already covered by the existing answer? If you agree with an existing answer then why not show your support and upvote it, rather than writing a similar (but arguably inferior) answer?– MrWhiteCommented Mar 24, 2020 at 22:41
-
What does your comment contribute to the question and the community as a whole? Or was it designed to just give you a chance to downvote and be a critical voice in a conversation that you otherwise chose to not participate? The other answer goes off on unnecessary tangents. The HTML specification cited does not fully cover the situation and is not helpful.– gnickoCommented Mar 25, 2020 at 14:09
<html >
instead. (where a newline can be used as well)head
element is implied, even if there are no<head>
/</head>
tags. Also, there are empty elements, which only have one tag instead of a start and an end tag. And end tags can be implied. And that's just HTML5. Older versions of HTML were based on SGML which has such fun stuff as Null End Tags as well, e.g. in HTML 1.0–4.01,<span/Hello/
is equivalent to<span>Hello</span>
. See softwareengineering.stackexchange.com/a/116483/1352 for an extreme example I concocted.