SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
HTML

HTML static code analysis

Unique rules to find Bugs, Security Hotspots, and Code Smells in your HTML code

  • All rules 83
  • Bug23
  • Security Hotspot3
  • Code Smell57
Filtered: 37 rules found
accessibility
    Impact
      Clean code attribute
        1. Label elements should have a text label and an associated control

           Code Smell
        2. Elements with an interactive role should support focus

           Code Smell
        3. Images should have a non-redundant alternate description

           Code Smell
        4. Heading elements should have accessible content

           Code Smell
        5. Non-interactive DOM elements should not have an interactive handler

           Code Smell
        6. Non-interactive elements shouldn't have event handlers

           Code Smell
        7. DOM elements should not use the "accesskey" property

           Code Smell
        8. Non-interactive DOM elements should not have the `tabIndex` property

           Code Smell
        9. Anchor tags should not be used as buttons

           Code Smell
        10. Interactive DOM elements should not have non-interactive ARIA roles

           Code Smell
        11. Non-interactive DOM elements should not have interactive ARIA roles

           Code Smell
        12. "tabIndex" values should be 0 or -1

           Code Smell
        13. DOM elements should use the "autocomplete" attribute correctly

           Code Smell
        14. Anchors should contain accessible content

           Code Smell
        15. Focusable elements should not have "aria-hidden" attribute

           Code Smell
        16. DOM elements with the `aria-activedescendant` property should be accessible via the tab key

           Code Smell
        17. ARIA properties in DOM elements should have valid values

           Code Smell
        18. "<object>" tags should provide an alternative content

           Code Smell
        19. Table cells should reference their headers

           Bug
        20. Tables used for layout should not include semantic markup

           Bug
        21. HTML "<table>" should not be used for layout purposes

           Code Smell
        22. Tables should have headers

           Bug
        23. "aria-label" or "aria-labelledby" attributes should be used to differentiate similar elements

           Code Smell
        24. "<html>" element should have a language attribute

           Bug
        25. Videos should have subtitles

           Code Smell
        26. "<th>" tags should have "id" or "scope" attributes

           Bug
        27. Links with identical texts should have identical targets

           Code Smell
        28. "input", "select" and "textarea" tags should be labeled

           Bug
        29. Links should not directly target images

           Code Smell
        30. Server-side image maps ("ismap" attribute) should not be used

           Bug
        31. "<frames>" should have a "title" attribute

           Bug
        32. "<fieldset>" tags should contain a "<legend>"

           Bug
        33. Flash animations should be embedded using the window mode

           Bug
        34. Heading tags should be used consecutively from "H1" to "H6"

           Code Smell
        35. "<table>" tags should have a description

           Bug
        36. Mouse events should have corresponding keyboard events

           Bug
        37. Image, area and button with image elements should have an "alt" attribute

           Code Smell

        "<th>" tags should have "id" or "scope" attributes

        Bug
        • accessibility
        • wcag2-a

        Why is this an issue?

        More Info

        Associating <table> headers, i.e. <th> elements, with their <td> cells enables screen readers to announce the header prior to the data. This considerably increases the accessibility of tables to visually impaired users.

        There are two ways of doing it:

        • Adding a scope attribute to <th> headers.
        • Adding an id attribute to <th> headers and a headers attribute to every <td> element.

        It is recommended to add scope attributes to <th> headers whenever possible. Use <th id="..."> and <td headers="..."> only when <th scope="..."> is not capable of associating cells to their headers. This happens for very complex tables which have headers splitting the data in multiple subtables. See W3C WAI Web Accessibility Tutorials for more information.

        Note that complex tables can often be split into multiple smaller tables, which improves the user experience.

        This rule raises an issue when a <th> element has neither id nor scope attributes set.

        Noncompliant code example

        <table border="1">
          <caption>Contact Information</caption>
          <tr>
            <td></td>
            <th>Name</th>                                          <!-- Non-Compliant -->
            <th>Phone#</th>                                        <!-- Non-Compliant -->
            <th>City</th>                                          <!-- Non-Compliant -->
          </tr>
          <tr>
            <td>1.</td>
            <th>Joel Garner</th>                                   <!-- Non-Compliant -->
            <td>412-212-5421</td>
            <td>Pittsburgh</td>
          </tr>
          <tr>
            <td>2.</td>
            <th>Clive Lloyd</th>                                   <!-- Non-Compliant -->
            <td>410-306-1420</td>
            <td>Baltimore</td>
          </tr>
        </table>
        

        Compliant solution

        <table border="1">
          <caption>Contact Information</caption>
          <tr>
            <td></td>
            <th scope="col">Name</th>                              <!-- Compliant -->
            <th scope="col">Phone#</th>                            <!-- Compliant -->
            <th scope="col">City</th>                              <!-- Compliant -->
          </tr>
          <tr>
            <td>1.</td>
            <th scope="row">Joel Garner</th>                       <!-- Compliant -->
            <td>412-212-5421</td>
            <td>Pittsburgh</td>
          </tr>
          <tr>
            <td>2.</td>
            <th scope="row">Clive Lloyd</th>                       <!-- Compliant -->
            <td>410-306-1420</td>
            <td>Baltimore</td>
          </tr>
        </table>
        

        or:

        <table border="1">
          <caption>Contact Information</caption>
          <tr>
            <td></td>
            <th id="name">Name</th>                                <!-- Compliant -->
            <th id="phone">Phone#</th>                             <!-- Compliant -->
            <th id="city">City</th>                                <!-- Compliant -->
          </tr>
          <tr>
            <td>1.</td>
            <th id="person1" headers="name">Joel Garner</th>       <!-- Compliant -->
            <td headers="phone person1">412-212-5421</td>
            <td headers="city person1">Pittsburgh</td>
          </tr>
          <tr>
            <td>2.</td>
            <th id="person2" headers="name">Clive Lloyd</th>       <!-- Compliant -->
            <td headers="phone person2">410-306-1420</td>
            <td headers="city person2">Baltimore</td>
          </tr>
        </table>
        

        Exceptions

        This rule is not applied in case of simple tables.

        Tables are considered as such when the headers are either all in the first row, or all in the first column. The two conditions must not apply together.

        Simple table example:

        <table border="1">
            <caption>Simple Table 1</caption>
            <tr>
                <th>Name</th>
                <th>Surname</th>
            </tr>
            <tr>
                <td>John</td>
                <td>Doe</td>
            </tr>
        </table>
        <table border="1">
            <caption>Simple Table 2</caption>
            <tr>
                <th>Name</th>
                <td>John</td>
            </tr>
            <tr>
                <th>Surname</th>
                <td>Doe</td>
            </tr>
        </table>
        
          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube Community BuildAnalyze code in your
          on-premise CI
          Available Since
          9.1
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use