HTML5 validation error: Element source not allowed as a child element of audio in this context

断了今生、忘了曾经 提交于 2019-12-01 20:35:27

Maintainer of the W3C HTML Checker here. The problem is that you have a stray ` (backtick) character in your HTML, on the line after the <audio controls> start tag and before the <source src="/audio1/horse.ogg" type="audio/ogg"> start tag.

Remove that ` character and the error will disappear.


Explanation

The reason the validator is showing that error message in this case is that when it sees that ` character, it interprets it as text content (fallback content) to show to users in browsers that don’t support the audio element; that is, the same as the "Your browser does not support the audio element" text in the snippet in the question.

But if an audio element has such text content, then the rules in the HTML spec state that no elements are allowed to follow that text content. So when the checker sees the source element in this case, it emits an error message saying the source element is not allowed.

I’m sorry the checker doesn’t give a better error message here to help you pinpoint the problem; for example, it would be much better if it said something like:

The source element is not allowed here because this audio element already has text content (`); remove the text content or move it to follow the source element.

But the current design of the code for the checker makes it very difficult to have it produce a more-helpful detailed error message like that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!