Web Accessibility Rules – Website Accessibility Check in C#

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.0requirements, 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) and is loaded using the WebAccessibilityDataSource class. The class has an internal constructor. Therefore users cannot directly create an object of the class. 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:

 1var htmlPath = Path.Combine(DataDir, "input.html");
 2
 3// Initialize a webAccessibility container
 4var webAccessibility = new WebAccessibility();
 5
 6// List of necessary rules for checking (rule code according to the specification) 
 7var rulesCode = new string[] { "H2", "H37", "H67", "H86" };
 8
 9// Get the required IList<Rule> rules from the rules reference
10var rules = webAccessibility.Rules.GetRules(rulesCode);
11
12// Create an accessibility validator, pass the found rules as parameters, and specify the full validation settings
13var validator = webAccessibility.CreateValidator(rules, ValidationBuilder.All);
14
15// Initialize an object of the HTMLDocument
16using (var document = new HTMLDocument(htmlPath))
17{
18    // Check the document
19    var validationResult = validator.Validate(document);
20
21    // Return the result in string format
22    // SaveToString - return only errors and warnings
23    Console.WriteLine(validationResult.SaveToString());
24}
view raw Example-GetRules hosted with ❤ by GitHub

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
2    WebAccessibility webAccessibility = new WebAccessibility();
3
4	// Get the principle by code
5    Principle rule = webAccessibility.Rules.GetPrinciple("1");
6
7	// Get code and description of principle
8    Console.WriteLine("{0}:{1}", rule.Code, rule.Description);

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
 2    WebAccessibility webAccessibility = new WebAccessibility();
 3
 4	// Get the principle by code 
 5    Principle principle = webAccessibility.Rules.GetPrinciple("1");
 6
 7    // Get guideline 1.1
 8    Guideline guideline = principle.GetGuideline("1.1");
 9    if (guideline != null)
10    {
11        Console.WriteLine("{0}:{1}", guideline.Code, guideline.Description, guideline);
12    }

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

 1     // Get principle by code 
 2    Principle principle = webAccessibility.Rules.GetPrinciple("1");
 3
 4    // Get guideline 
 5    Guideline guideline = principle.GetGuideline("1.1");
 6
 7    // Get criterion by code
 8    Criterion criterion = guideline.GetCriterion("1.1.1");
 9    if (criterion != null)
10    {
11        Console.WriteLine("{0}:{1} - {2}", criterion.Code, criterion.Description, criterion.Level);
12
13        // Get all Sufficient Techniques and write to console
14        foreach (var technique in criterion.SufficientTechniques)
15            Console.WriteLine("{0}:{1}", technique.Code, technique.Description);
16    }
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.