Fixing the mysterious “Element script is missing required attribute src” error

Suppose you're using the W3C validator to validate HTML5. Here's a sample document:

<!doctype html>
<html lang="en" xml:lang="en">
<head>
<meta charset="utf-8" />
<title>Hello</title>
<script type="text/javascript" charset="utf-8">
//<![CDATA[
var foo = 1;
//]]>
</script>
</head>
<body>
</body>
</html>

Everything looks right, but you get this mysterious error:

Line 6, Column 48: Element script is missing required attribute src.
<script type="text/javascript" charset="utf-8">

But you don't want or need an src attribute, because your JavaScript is inline. The solution is not to add the src attribute, but to remove the charset attribute.

(Note: a bug has been filed and this will be fixed in a future release.)

Join the Conversation

1 Comment

  1. We are a group of volunteers and opening a new scheme in our community. Your website provided us with useful information to work on. You have done a formidable job and our whole group will be grateful to you.

Leave a comment

Your email address will not be published. Required fields are marked *