Web Accessibility API for C#

Check HTML against WCAG rules, find accessibility issues, and export validation results in C#.

Check Web Accessibility with a .NET API

Aspose.HTML for .NET provides APIs for checking the accessibility of HTML files and webpages. Use the Aspose.Html.Accessibility namespace to run a complete check or select rules for specific issues, such as missing image text alternatives and insufficient color contrast.

Accessible HTML helps people who use screen readers, keyboard navigation, magnification, and other assistive technologies interact with web content. Regular accessibility checks help development teams find issues early and maintain WCAG-aligned pages as content changes.


Choose a Web Accessibility Workflow

Development taskRecommended workflow
Run a complete accessibility check and inspect detected issuesHTML Accessibility Validator
Check an HTML document against selected WCAG rulesWCAG Accessibility Rules
Check missing or incorrectly used image alt attributesImage Alt Tag Checker
Test minimum and enhanced text-contrast criteriaColor Contrast Checker

Validate HTML Against WCAG Levels A and AA

This example selects WCAG Level A and AA criteria and enables rules for HTML and CSS technologies. It validates the document and exports the detected errors and warnings.

C# code to configure web accessibility validation

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Accessibility;
using Aspose.Html.Accessibility.Results;

string documentPath = Path.Combine("data", "input.html");

WebAccessibility webAccessibility = new WebAccessibility();

// Select WCAG Level A and AA checks for HTML and CSS technologies
ValidationBuilder validationPolicy = ValidationBuilder.None
    .UseHTML()
    .UseCSS()
    .UseLowestLevel()
    .UseMiddleLevel();

AccessibilityValidator validator = webAccessibility.CreateValidator(
    validationPolicy);

// Validate the document and export detected issues
using HTMLDocument document = new HTMLDocument(documentPath);
ValidationResult validationResult = validator.Validate(document);

Console.WriteLine($"Validation passed: {validationResult.Success}");

if (!validationResult.Success)
{
    Console.WriteLine(validationResult.SaveToString());
}

Build an Accessibility Validation Workflow

  1. Choose the validation scope: all available checks, selected levels and technologies, a WCAG hierarchy object, or an explicit rule list.
  2. Create a WebAccessibility object and configure an AccessibilityValidator .
  3. Load a local file or webpage URL into an HTMLDocument .
  4. Call Validate() and process the returned ValidationResult .
  5. Record the automated findings, correct the source, and complete the workflow with the required manual accessibility tests.

Web Accessibility API Capabilities

  • Configurable validation. Use all repository rules or filter checks by conformance level, technology, HTML tag, principle, guideline, criterion, or rule code.
  • Focused checks. Build targeted workflows for text alternatives, labels, document structure, color contrast, and other supported requirements.
  • Detailed results. Inspect rule and technique outcomes, error types, messages, and the HTML or CSS targets associated with detected issues.
  • Report export. Save validation results as text, JSON, or XML for reviews, logs, and automated quality processes.
  • Application integration. Run the same policy repeatedly in content processing, CMS validation, tests, or CI/CD pipelines.
  • Defined limits. Automated checks support accessibility work but cannot certify complete WCAG conformance without manual evaluation.

For a one-time scan without writing code, use the online Web Accessibility Checker .



Web Accessibility Documentation

Start with the Web Accessibility documentation overview. Continue with Accessibility Validator for configuration, Web Accessibility Rules for the repository hierarchy, and Save Validation Results for report formats.



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 API FAQ

1. What accessibility checks can Aspose.HTML for .NET automate?

The API can evaluate HTML against supported accessibility rules, including checks involving text alternatives, labels, structure, CSS, and color contrast. The exact coverage depends on the selected rules, technologies, and conformance levels.


2. Should I validate all rules or select a smaller rule set?

Use broad validation for a general review. Select levels, technologies, tags, criteria, or individual rule codes when a project has a defined policy or needs faster feedback for a focused component. A narrow rule set should not be presented as a complete audit.


3. Can web accessibility checks run in CI/CD?

Yes. Run the validator during tests or content builds, export the results, and apply project-specific conditions to decide whether the pipeline should warn or fail. Manual accessibility testing remains a separate part of the release process.

Explore More Aspose.HTML for .NET Features

Continue with tools and API guides for editing, creating, generating, and converting HTML content.