I'm working with the html5 video tag, <video>, and noticed something that was coming up as an error in Brackets Validator.
What's concerning my is the <source> tag inside in the video tag. How I've normally written this is
<source src="somecoolvideo.mp4" type="video/mp4">
But this is coming up as an error, stating that it needs a closing </source>
<source src="somecoolvideo.mp4" type="video/mp4"></source>
Now both ways do work in a browser and I haven't read anything about using the </source> so I'm a bit confused on what is the correct practice. Anyone know whats the correct practice?
No, the <source> element must not have a close tag and must not close itself, the validator you're using is incorrect.
Here is the W3 spec:
The source element is a void element. A source element must have a start tag but must not have an end tag.
A void element is an element whose content model never allows it to have contents under any circumstances (void elements can have attributes however).
A proper example:
<video controls>
<source src="http://media.w3.org/2010/05/sintel/trailer.mp4"
type='video/mp4; codecs="avc1, mp4a"'>
<source src="http://media.w3.org/2010/05/sintel/trailer.ogv"
type='video/ogg; codecs="theora, vorbis"'>
<p>Your user agent does not support the HTML5 Video element.</p>
</video>
That's interesting, because the spec doesn't say it's required and none of its examples have the closing tag.
Sounds like whatever "Brackets Validator" is doesn't correctly validate HTML5. What does the W3C Validator say about it? If I enter this into the W3C validator, it validates just fine:
<!DOCTYPE html>
<html>
<head><title>test</title></head>
<body>
<video>
<source src="somecoolvideo.mp4" type="video/mp4">
</video>
</body>
</html>
Additionally, if I do add a closing </source> tag, W3C gives an error:
Line 6, Column 66: Stray end tag source.
<source src="somecoolvideo.mp4" type="video/mp4"></source>
So it would appear not only that not having a closing tag in this case is valid, but additionally that actually having one is explicitly invalid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With