Web Accessibility Rules – Principles, Guidelines, Criterions, and Techniques

Aspose.HTML for Java provides the com.aspose.html.accessibility package, which is intended for all Web Accessibility related manipulations and checks. In this article, you will learn how to use the AccessibilityRules class, which is a repository of WCAG 2.0 requirements, success criteria, and techniques.

Accessibility rules are a set of guidelines, standards, or best practices that define how to design and develop digital content, such as websites, applications, and media, to ensure that they are usable by people with disabilities. These rules help make online experiences accessible to individuals with visual, auditory, motor, or cognitive disabilities, promoting digital inclusion and ensuring equal access to information, services, and technology for everyone.

The structure of the web accessibility quick reference can be represented as a diagram, which is shown below:

Text “The structure of the web accessibility rules – principles, guidelines, and criteria.”

Accessibility Rules

The AccessibilityRules class is a repository of WCAG 2.0 requirements, success criteria, and techniques and has a structure that corresponds to the specification WCAG (Quick Reference). In order to view the list of rules, you need to initialize the WebAccessibility container and use the property Rules.

The property returns an object of type AccessibilityRules, which has such methods for accessing the rules:

MethodsDescription
getPrinciple(string code)Returns a Principle object by code from WCAG.
getPrinciples()Returns a list of principles IList<Principle>.
getRules(params string[] codes)Returns a list of rules IList< IRule> for given codes from WCAG.

The directory contains rules that inherit from the abstract class Rule. There are several types of rules:

IRule

All rules implement the interface IRule is a public interface that defines the basic properties of the rules:

PropertyDescription
CodeRule code from the quick reference WCAG.
DescriptionDescription of Rule from the quick reference WCAG.

Rule

The base abstract class for all rules, which implements the interface IRule. To get any rule, you can use the getRules() method:

 1// Initialize a webAccessibility container
 2WebAccessibility webAccessibility = new WebAccessibility();
 3
 4// List of rule codes can contain both technique codes and principles,
 5// guidelines and criteria - all rules that implement the interface IRule
 6String[] rulesCodes = new String[]{"H2", "H37", "H30", "1.1", "1.2.1"};
 7
 8// Get a list of IRule objects; if a rule with the specified code is not found,
 9// it will not be in the list
10List<IRule> rules = webAccessibility.getRules().getRules(rulesCodes);
11
12// Get code and description of rule
13for (IRule rule : rules) {
14    System.out.println(String.format("%s: %s",
15            rule.getCode(),
16            rule.getDescription()
17    ));
18}
Example_GetRules hosted with ❤ by GitHub

The program will output to the console:

1    H2:Combining adjacent image and text links for the same resource
2    H37:Using alt attributes on img elements
3    H30:Providing link text that describes the purpose of a link for anchor elements
4    1.1:Text Alternatives
5    1.2.1:Audio-only and Video-only (Prerecorded)

Principle

At the first level of the list of rules are the Principles, they indicate the main direction and purpose of the rules that are in this section. Therefore, work with the directory begins with them.

The Principle class inherited from Rule and also contains a list of guidelines.

MethodDescription
getGuideline(string code)Get Guideline by code from WCAG, contained in principle. Return Guideline object.
getGuidelines()Get a list of Guideline from Principle. Return IList< Guideline> object.

An example of how to get a Principle object from a list of rules:

 1// Initialize a webAccessibility container
 2WebAccessibility webAccessibility = new WebAccessibility();
 3
 4// Get the principle by code
 5Principle rule = webAccessibility.getRules().getPrinciple("1");
 6
 7// Get code and description of principle
 8System.out.println(String.format("%s: %s",
 9        rule.getCode(),
10        rule.getDescription()
11));
12// @output: 1:Perceivable
Example_GetPrinciple hosted with ❤ by GitHub

Guideline

The Guideline class inherited from Rule and contains a criteria list. Guidelines are the next level after principles. They outline frameworks and general goals that help authors understand success criteria and better apply the techniques.

MethodDescription
getCriterion(string code)Get Guideline by code from WCAG, contained in current Guideline. Return Criterion object.
getCriterions()Get a list of Criterion from current Guideline. Return IList< Criterion> object.

An example of how to get a Guideline object from a list of rules:

 1// Initialize a webAccessibility container
 2WebAccessibility webAccessibility = new WebAccessibility();
 3
 4// Get the principle by code
 5Principle principle = webAccessibility.getRules().getPrinciple("1");
 6
 7// Get guideline 1.1
 8Guideline guideline = principle.getGuideline("1.1");
 9if (guideline != null) {
10    System.out.println(String.format("%s: %s, %s",
11            guideline.getCode(),
12            guideline.getDescription(),
13            guideline
14    ));
15    // @output: 1.1:Text Alternatives
16}
Example_GetGuideline hosted with ❤ by GitHub

Criterion

The Criterion class describes the WCAG success criteria, inherited from abstract class Rule. Detailed information can be found here – Understanding Techniques for WCAG Success Criteria. The basis for determining conformance to WCAG 2.0 is the success criteria from the standard. The criterion contains a list of techniques for meeting WCAG web content accessibility guidelines. If all sufficient methods for a given criterion are supported by accessibility, then the success criterion has passed.

Use the getCriterion(code) method to access criteria from guideline:

 1// Initialize a webAccessibility container
 2WebAccessibility webAccessibility = new WebAccessibility();
 3
 4// Get the principle by code
 5Principle principle = webAccessibility.getRules().getPrinciple("1");
 6
 7// Get guideline
 8Guideline guideline = principle.getGuideline("1.1");
 9
10// Get criterion by code
11Criterion criterion = guideline.getCriterion("1.1.1");
12if (criterion != null) {
13    System.out.println(String.format("%s: %s - %s",
14            criterion.getCode(),
15            criterion.getDescription(),
16            criterion.getLevel()
17    ));
18    // @output: 1.1.1:Non-text Content - A
19
20    // Get all Sufficient Techniques and write to console
21    for (IRule technique : criterion.getSufficientTechniques())
22        System.out.println(String.format("%s: %s",
23                technique.getCode(),
24                technique.getDescription()
25        ));
26}
Example_GetCriterion hosted with ❤ by GitHub

Check HTML Against Specific Web Accessibility Rules

This code demonstrates how to validate an HTML document for web accessibility using the specified set of rules.

 1String htmlPath = "input.html";
 2
 3// Initialize a webAccessibility container
 4WebAccessibility webAccessibility = new WebAccessibility();
 5
 6// List of necessary rules for checking (rule code according to the specification)
 7String[] rulesCode = new String[]{"H2", "H37", "H67", "H86"};
 8
 9// Get the required IList<Rule> rules from the rules reference
10List<IRule> rules = webAccessibility.getRules().getRules(rulesCode);
11
12// Create an accessibility validator, pass the found rules as parameters,
13// and specify the full validation settings
14AccessibilityValidator validator = webAccessibility.createValidator(
15        rules, ValidationBuilder.getAll());
16
17// Initialize an object of the HTMLDocument
18final HTMLDocument document = new HTMLDocument(htmlPath);
19// Check the document
20ValidationResult validationResult = validator.validate(document);
21
22// Return the result in string format
23// SaveToString - return only errors and warnings
24System.out.println(validationResult.saveToString());

See Also

  • You will find helpful tips on evaluating and improving text visibility in the article Color Contrast Accessibility, which covers contrast checking based on WCAG using Aspose.HTML for Java.
  • For instructions on checking web content is compatible with screen readers, you will find in the article Screen Reader Accessibility. You will learn how to check alt text and other key elements.
  • If you want to learn how to view validation results and identify web accessibility issues, see the Validation Results article.
  • In the article Web Accessibility Check – Errors and Warnings, you will learn how to programmatically in Java collect error and warning information while checking a website’s accessibility.

Aspose.HTML offers free online Web Accessibility Checker. This tool scans web pages, validates them for WCAG compliance, identifies problems, and suggests improvements. Get instant insights into your website’s compliance, allowing you to determine the scope of necessary corrections and the gap between the current state of your website or HTML document and WCAG requirements.

Text “Web Accessibility Checker”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.