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: 10 rules found
wcag2-a
    Impact
      Clean code attribute
        1. "<object>" tags should provide an alternative content

           Code Smell
        2. Table cells should reference their headers

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

           Bug
        4. Tables should have headers

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

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

           Bug
        7. "<th>" tags should have "id" or "scope" attributes

           Bug
        8. "input", "select" and "textarea" tags should be labeled

           Bug
        9. "<table>" tags should have a description

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

           Code Smell

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

        intentionality - complete
        reliability
        Code Smell
        • accessibility
        • wcag2-a

        Why is this an issue?

        How can I fix it?

        More Info

        The alt attribute provides a textual alternative to an image.

        It is used whenever the actual image cannot be rendered.

        Common reasons for that include:

        • The image can no longer be found
        • Visually impaired users using a screen reader software
        • Image loading is disabled, to reduce data consumption on mobile phones

        It is also very important not to set an alt attribute to a non-informative value. For example, <img ... alt="logo"> is useless as it doesn’t give any information to the user. In this case, as for any other decorative image, it is better to use a CSS background image instead of an <img> tag. If using CSS background-image is not possible, an empty alt="" is tolerated. See Exceptions below.

        This rule raises an issue when:

        • An <input type="image"> or <area> element has no alt attribute or it holds an empty string value.
        • An <img> element has no alt attribute.

        Exceptions

        <img> elements with an empty string alt="" attribute won’t raise any issue. However, this way should be used in two cases only:

        When the image is decorative and it is not possible to use a CSS background image. For example, when the decorative <img> is generated via javascript with a source image coming from a database, it is better to use an <img alt=""> tag rather than generate CSS code.

        <li *ngFor="let image of images">
            <img [src]="image" alt="">
        </li>
        

        When the image is not decorative but its alt text would repeat a nearby text. For example, images contained in links should not duplicate the link’s text in their alt attribute, as it would make the screen reader repeat the text twice.

        <a href="flowers.html">
            <img src="tulip.gif" alt="" />
            A blooming tulip
        </a>
        

        In all other cases you should use CSS background images.

          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