scitools.com

← Metric catalog

Comment Lines (HTML) is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Comment Lines (HTML)

API ID: CountLineCommentHtml
Languages: Web
Targets: Architectures, Files, Project

Number of HTML lines containing a comment.

Only counts comments outside embedded sub-language blocks; a comment inside a <script> block counts towards Comment Lines (JavaScript) instead.

For example:


<!DOCTYPE html>
<html>
<head>
  <title>Welcome</title>

  <!-- Greeting script: tracks visits and confirms with the user -->
  <script>
    // Number of times the page has greeted someone
    var greetingCount = 0;

    function greetUser(name) {
      greetingCount++;
      return "Hello, " + name + "!";
    }

    let message = greetUser("Ada");
    console.log(message);

    if (greetingCount > 0) {
      confirm(message);
    }
  </script>
</head>
<body>
  <h1>Welcome to the site</h1>
  <p>Have a look around.</p>
</body>
</html>

The <!-- Greeting script: ... --> comment (line 6) is the only HTML comment. The // Number of times the page has greeted someone comment inside the <script> block (line 8) counts towards Comment Lines (JavaScript) instead, giving CountLineCommentHtml = 1.

See Comment Lines (JavaScript) for comments inside embedded scripts, and Comment Lines for the language-independent metric this breaks down.

Targets By Language: Configuration: