Skip to main content

HTML Guide

Bad value “” for attribute “src” on element “script”: Must be non-empty.

Ensure the src attribute on the script element is non-empty and points to a valid resource.

The src attribute in a script element specifies the URL of an external script file. An empty src attribute is invalid because it tells the browser to fetch a resource from a URL that is not provided, leading to loading errors. Instead, ensure that the src attribute contains a valid file path or URL to an existing script file. If the script content is meant to be inline, you should omit the src attribute altogether and include the script content directly within the script element.

Example of a Valid External Script

Here is a valid example of a script element with a non-empty src attribute:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Valid Script Example</title>
</head>
<body>
  <script src="path/to/script.js"></script>
</body>
</html>

Example of a Valid Inline Script

If the script is to be written inline, exclude the src attribute and write the JavaScript code directly within the script tags:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Inline Script Example</title>
</head>
<body>
  <script>
    console.log('This is an inline script.');
  </script>
</body>
</html>

Troubleshooting

Double-check the script’s file path:

  • Ensure the file path you provide in the src is correct relative to the HTML file.
  • Make sure the script file exists in the location specified.
  • If using a network URL, verify that the URL is correct and accessible.

Learn more:

Related W3C validator issues