Web Accessibility Rules – Website Accessibility Checking According to WCAG

Aspose.HTML for .NET provides the Aspose.Html.Accessibility namespace, 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.

You can learn how to use the AccessibilityValidator class to check web accessibility from the article Accessibility Validator – Website Accessibility Check in C#.

Accessibility rules are a set of guidelines, standards, or best practices that define how digital content and interfaces should be designed and developed to ensure they are accessible to people with disabilities. These guidelines are intended to make digital content, such as websites, apps, and multimedia, accessible to a wide range of people, including those with visual, hearing, motor, and cognitive impairments. Accessibility rules are crucial for promoting digital inclusion and ensuring everyone has equal access to online information and services.

The structure of the quick reference can be presented in the form of a diagram, which is indicated below:

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

The directory contains the rules that implement the IRule interface.

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.

1    // Initialize a webAccessibility container
2    var webAccessibility = new WebAccessibility();
3
4    // Get the accessibilityRules repository
5    AccessibilityRules accessibilityRules = webAccessibility.Rules;

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

MethodsDescription
GetPrinciple(string code)Returns 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// Retrieve and list accessibility rules by code with their descriptions from the rules repository
 2
 3// Initialize a webAccessibility container
 4WebAccessibility webAccessibility = new WebAccessibility();
 5
 6// List of rule codes can contain both technique codes and principles, guidelines and criteria - all rules that implement the interface IRule
 7string[] rulesCodes = new string[] { "H2", "H37", "H30", "1.1", "1.2.1" };
 8
 9// Get a list of IRule objects; if a rule with the specified code is not found, it will not be in the list
10IList<IRule> rules = webAccessibility.Rules.GetRules(rulesCodes);
11
12// Get code and description of rule
13foreach (IRule rule in rules)
14    Console.WriteLine("{0}:{1}", rule.Code, rule.Description);
Example-GetRules.cs 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// Retrieve and display the code and description of an accessibility principle by its code
 2
 3// Initialize a webAccessibility container
 4WebAccessibility webAccessibility = new WebAccessibility();
 5
 6// Get the principle by code
 7Principle rule = webAccessibility.Rules.GetPrinciple("1");
 8
 9// Get code and description of principle
10Console.WriteLine("{0}:{1}", rule.Code, rule.Description);  // output: 1:Perceivable
Example-GetPrinciple.cs 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// Retrieve and display the code and description of an accessibility guideline
 2
 3// Initialize a webAccessibility container
 4WebAccessibility webAccessibility = new WebAccessibility();
 5
 6// Get the principle by code 
 7Principle principle = webAccessibility.Rules.GetPrinciple("1");
 8
 9// Get guideline 1.1
10Guideline guideline = principle.GetGuideline("1.1");
11if (guideline != null)
12{
13    Console.WriteLine("{0}:{1}", guideline.Code, guideline.Description, guideline);  // output: 1.1:Text Alternatives
14}
Example-GetGuideline.cs 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 – not the techniques.

Verifiable success criteria are provided for each recommendation so WCAG 2.0 can be applied in areas where compliance testing is required.

PropertyDescription
LevelCompliance levels: A (lowest), AA and AAA (highest).
SufficientTechniquesReturns list of Sufficient techniques that are reliable ways to meet the success criteria.
AdvisoryTechniquesReturns list of Advisory techniques that are suggested ways to improve accessibility. They are often very helpful to some users, and may be the only way that some users can access some types of content.
FailuresReturns list of Failures that are things that cause accessibility barriers and fail specific success criteria.

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() method to access criteria from guideline:

 1// Retrieve and display the code and description of an accessibility criterion
 2
 3// Initialize a webAccessibility container
 4WebAccessibility webAccessibility = new WebAccessibility();
 5
 6// Get the principle by code 
 7Principle principle = webAccessibility.Rules.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{
16    Console.WriteLine("{0}:{1} - {2}", criterion.Code, criterion.Description, criterion.Level); // output: 1.1.1:Non-text Content - A
17
18    // Get all Sufficient Techniques and write to console
19    foreach (IRule technique in criterion.SufficientTechniques)
20        Console.WriteLine("{0}:{1}", technique.Code, technique.Description);
21}
Example-GetCriterion.cs hosted with ❤ by GitHub

Check HTML Against Specific Web Accessibility Rules

 1// Validate an HTML document using specific rule codes with C#
 2
 3string htmlPath = Path.Combine(DataDir, "input.html");
 4
 5// Initialize a webAccessibility container
 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<Rule> rules from the rules reference
12IList<IRule> rules = webAccessibility.Rules.GetRules(rulesCode);
13
14// Create an accessibility validator, pass the found rules as parameters, and specify the full validation settings
15AccessibilityValidator validator = webAccessibility.CreateValidator(rules, ValidationBuilder.All);
16
17// Initialize an object of the HTMLDocument
18using (HTMLDocument document = new HTMLDocument(htmlPath))
19{
20    // Check the document
21    ValidationResult validationResult = validator.Validate(document);
22
23    // Return the result in string format
24    // SaveToString - return only errors and warnings
25    Console.WriteLine(validationResult.SaveToString());
26}

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

See Also

  • In the chapter Web Accessibility Check, you will learn how to check website accessibility for all WCAG compliance or only meet specific criteria using classes and methods of the Aspose.Html.Accessibility and Aspose.Html.Accessibility.Results namespaces.
  • The article How to Improve Website Accessibility explains how to make your website accessible to users and how to check your website for WCAG compliance using the Aspose.HTML API for .NET.
  • The article Screen Reader Accessibility explains how to design a website for screen reader accessibility in accordance with WCAG guidelines using the Aspose.HTML for .NET API.
  • Check out the article Сolor Сontrast Accessibility if you want to learn how to properly adjust the contrast of your web content to WCAG standards, the world authority on web accessibility. You will discover how to test color contrast accessibility using C# and make your web content easy to read for all users.
  • In the article Accessibility Validator, you will learn about the AccessibilityValidator class that can be used to test web accessibility rules such as principles, guidelines, and criteria.

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.