The w3c validator doesen't like self-closing tags (those that end with "\>
"). Are they still valid in html5?
Some examples would be:
<br \>
<img src="" \>
<input type="text" name="username" \>
The w3c validator doesen't like self-closing tags (those that end with "\>
"). Are they still valid in html5?
Some examples would be:
<br \>
<img src="" \>
<input type="text" name="username" \>
You need to use forward slashes for the self-closing tags. My website uses self-closing tags in HTML5 content and the validators don't complain.
Yes, they are valid as this:
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title></title></head>
<body>
<hr />
</body>
</html>
Validates fine:
And as pointed out, use />
not \>
.
Not exactly.
If we get the syntax right (it is /
not \
) then:
In HTML 4, <foo /
means <foo>
(which leads to <br />
meaning <br>>
and <title/hello/
meaning <title>hello</title>
. Browsers did a very poor job of supporting this and the spec advised to avoid the syntax.
In XHTML, <foo />
means <foo></foo>
In HTML 5, <foo />
means <foo>
. The slash is just syntactic sugar for people who are addicted to XML. The syntax is valid, but it is not a "self-closing tag". The distinction is important since <div />
means <div>
in HTML 5 and not <div></div>
as it does in XHTML.
Self-closing tags are valid in HTML5, but not required.
<br>
and <br />
are both fine.