Select Web Accessibility Rules with a .NET API
Aspose.HTML for .NET
provides an
AccessibilityRules
repository containing WCAG 2.0 principles, guidelines, success criteria, and techniques. Select the required rules by code, create an AccessibilityValidator, and check an HTML file or webpage for related accessibility issues.
Selecting specific rules is useful when a project follows a defined accessibility policy or needs to test one type of issue. The validation report shows which checks failed and which HTML elements require attention.
Check HTML Against Selected WCAG Rules
The example selects four HTML techniques covering image alternatives, form labels, iframe titles, and unique element IDs. GetRules() returns the matching IRule objects, which are then passed to a focused validator.
C# code to validate selected accessibility rules
using System;
using System.Collections.Generic;
using System.IO;
using Aspose.Html;
using Aspose.Html.Accessibility;
using Aspose.Html.Accessibility.Results;
string documentPath = Path.Combine("data", "input.html");
string[] ruleCodes = { "H37", "H44", "H64", "H93" };
WebAccessibility webAccessibility = new WebAccessibility();
// Retrieve only the requested accessibility rules
IList<IRule> selectedRules = webAccessibility.Rules.GetRules(ruleCodes);
AccessibilityValidator validator = webAccessibility.CreateValidator(
selectedRules,
ValidationBuilder.All);
// Validate the document against the selected rules
using HTMLDocument document = new HTMLDocument(documentPath);
ValidationResult validationResult = validator.Validate(document);
if (!validationResult.Success)
{
Console.WriteLine(validationResult.SaveToString());
}
How to Validate Specific Accessibility Rules
- Create a
WebAccessibility
object and access its
Rulesrepository. - Define the codes for the principles, guidelines, criteria, or techniques required by the project’s validation policy.
- Pass the codes to GetRules() and verify that every requested rule was returned.
- Create an
AccessibilityValidator
from the resulting
IList<IRule>. - Load the HTML with
HTMLDocument
, call
Validate(), and inspect or save the returned report.
Understand the Accessibility Rule Hierarchy
- Principles. Top-level WCAG categories describe the broad goals of accessible content.
- Guidelines. Each principle contains guidelines that organize related accessibility requirements.
- Success criteria. Criteria provide testable requirements and identify conformance levels A, AA, or AAA.
- Techniques and failures. Technique codes such as
H37describe implementation checks; failure codes identify patterns that violate a criterion. - Code-based selection.
GetRules()accepts one or more codes and omits codes that are not present in the repository. - Focused validation. Selected rules can support project-specific checks, but a narrow rule list is not a complete accessibility audit.
Use the HTML Accessibility Validator when the application needs a broad or builder-filtered check instead of an explicit list of rule codes.
WCAG Rules Documentation and Reference
Read
Web Accessibility Rules
for the full repository hierarchy and examples of GetPrinciple(), GetGuideline(), GetCriterion(), and GetRules(). The W3C
WCAG Techniques
index describes the purpose and test procedure for individual technique and failure codes.
Get Started with Aspose.HTML for .NET API
Install Aspose.HTML for .NET from NuGet with the .NET CLI:
dotnet add package Aspose.HTML
You can also use the NuGet Package Manager UI or run Install-Package Aspose.HTML in the Package Manager Console. See the
installation guide
for setup details, or request a
temporary license
to evaluate the API without evaluation limitations.
Web Accessibility Rules FAQ
1. What is the difference between a WCAG criterion and a technique?
A success criterion is a testable requirement used to determine WCAG conformance. A technique describes one documented way to meet a criterion, while a failure describes a pattern that does not meet it. Passing one technique does not by itself establish conformance.
2. How do I validate only specific WCAG rules in C#?
Pass the required codes to AccessibilityRules.GetRules(), create an AccessibilityValidator with the returned IList<IRule>, and validate the HTMLDocument. This limits the report to the selected rule scope and applicable builder settings.
3. Can GetRules() accept principles, guidelines, criteria, and techniques?
Yes. Each of these rule types implements IRule, so their codes can be supplied to GetRules(). Choose the level that matches the intended scope; a higher-level object includes a broader group, while a technique code targets a specific check.
4. What happens if a requested accessibility rule code is not found?
The GetRules() method omits a code that is not present in the repository. Compare the returned collection with the requested codes before validation so a spelling error or unsupported code does not silently reduce the intended coverage.
5. Does validating selected rules prove WCAG compliance?
No. It proves only that the document was evaluated against the selected automated checks. WCAG conformance requires the applicable success criteria to be assessed, including requirements that need manual testing and human judgment.
Related Web Accessibility Workflows
Continue with complete validation, image alt checks, color contrast testing, or the accessibility API overview.