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

Use the AccessibilityRules class to access WCAG 2.0 principles, guidelines, success criteria, and techniques in Java. Retrieve rules by code and pass the selected list to WebAccessibility.createValidator() to run focused accessibility checks.

Accessibility rules describe requirements and techniques for making websites, applications, and digital content usable by people with visual, auditory, motor, and cognitive disabilities. Aspose.HTML for Java provides its WCAG 2.0 rules through the com.aspose.html.accessibility package.

WCAG 2.0 Rule Structure

WCAG 2.0 organizes its rules as principles, guidelines, and testable success criteria. Techniques describe ways to meet a criterion or identify common failures. The four top-level principles are Perceivable, Operable, Understandable, and Robust.

Web accessibility rule hierarchy with principles, guidelines, and success criteria

Access Web Accessibility Rules

Create a WebAccessibility instance and call getRules() to obtain an AccessibilityRules object. Its hierarchy corresponds to the WCAG 2.0 Quick Reference.

The AccessibilityRules class provides methods for retrieving the complete collection or individual entries by code:

MethodDescription
getPrinciple(String code)Returns a Principle with the specified WCAG code.
getPrinciples()Returns the collection of principles.
getRules(String[] codes)Returns a List<IRule> for the specified rule codes.

The rules are organized into four related types:

IRule Interface and Rule Base Class

All entries implement the IRule interface and inherit their shared behavior from the abstract Rule class.

MethodDescription
getCode()Returns the rule code used in the WCAG quick reference.
getDescription()Returns the rule description.

Get Accessibility Rules by Code

Use AccessibilityRules.getRules() to retrieve different rule types in one list. The example requests three techniques, one guideline, and one success criterion, then prints each code and description.

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

The program writes the following values to the console:

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

Get a WCAG Principle

The Principle class represents the top level of the WCAG hierarchy and contains a collection of guidelines.

MethodDescription
getGuideline(String code)Returns the guideline with the specified code from this principle.
getGuidelines()Returns the principle’s guidelines.

The example retrieves principle 1, Perceivable, and prints its code and description:

 1// Get accessibility principle by code from WCAG rules in Aspose.HTML for Java
 2
 3// Create a WebAccessibility instance
 4WebAccessibility webAccessibility = new WebAccessibility();
 5
 6// Get the principle by code
 7Principle rule = webAccessibility.getRules().getPrinciple("1");
 8
 9// Get code and description of principle
10System.out.println(String.format("%s: %s",
11        rule.getCode(),
12        rule.getDescription()
13));
14// @output: 1: Perceivable

Get a WCAG Guideline

The Guideline class represents the level below a principle and contains success criteria. Guidelines describe general accessibility goals; the criteria provide testable requirements.

MethodDescription
getCriterion(String code)Returns the success criterion with the specified code from this guideline.
getCriterions()Returns the guideline’s collection of criteria.

The example obtains principle 1 and retrieves guideline 1.1, Text Alternatives:

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

Get a Success Criterion and Its Techniques

The Criterion class represents a testable WCAG 2.0 success criterion. A criterion includes a conformance level and collections of sufficient techniques, advisory techniques, and failures.

MethodDescription
getLevel()Returns the criterion’s A, AA, or AAA conformance level.
getSufficientTechniques()Returns techniques that describe sufficient ways to meet the criterion.
getAdvisoryTechniques()Returns additional techniques that can improve accessibility.
getFailures()Returns documented failures associated with the criterion.

WCAG conformance is determined by its success criteria, not by requiring authors to use a particular published technique. See Understanding Techniques for WCAG Success Criteria for that distinction.

The example retrieves criterion 1.1.1, prints its level, and lists its sufficient techniques:

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

Validate HTML Against Selected Accessibility Rules

The following Java workflow validates an HTML document against a selected set of WCAG technique codes:

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

The example prints the formatted validation result to the console. Selecting rule codes is useful for targeted checks; use the complete rule set when the workflow requires a broader automated audit.

FAQ

How do I get an accessibility rule by code?

Pass one or more codes to AccessibilityRules.getRules(String[]). To retrieve a top-level principle directly, use getPrinciple(String).

What is the difference between a success criterion and a technique?

A success criterion is a testable WCAG requirement. A technique describes a documented way to meet that criterion, while a failure describes a pattern that does not satisfy it.

Can I validate only selected accessibility rules?

Yes. Retrieve the required rules by code and pass the resulting List<IRule> to WebAccessibility.createValidator() together with the validation settings.

Related Articles

Try the Online Web Accessibility Checker

Use the free online Web Accessibility Checker for a quick page scan before selecting rules for a Java validation workflow. Automated results do not replace manual accessibility testing.

Web Accessibility Checker