Web Accessibility – How to Check in Java
What is Web Accessibility?
Web accessibility is the practice of designing and developing websites, applications, and digital content to ensure everyone, including people with disabilities, can use them. Accessible websites remove barriers that could prevent users with visual, auditory, motor, or cognitive impairments from interacting with online content. Checking your website for WCAG (Web Content Accessibility Guidelines) compliance ensures that it is accessible to a broader audience.
How to Check Accessibility
Aspose.HTML for Java API provides the com.aspose.html.accessibility package, which is for all web accessibility-related manipulations and checks. This chapter provides articles with recommendations on how to check the accessibility of a website or any other HTML document using Aspose.HTML for Java API.
This chapter includes the following articles:
- Web Accessibility Check – You will learn how to check website accessibility for all WCAG compliance or only meet specific criteria.
- Accessibility Validator – In this article, you will learn how to use the
AccessibilityValidator
class to check website accessibility against WCAG rules, such as principles, guidelines, and criteria. - Validation Results – In this article, you will learn how to review the results of web accessibility checks, report the criteria tested, and detail specific issues encountered during the validation process.
- Web Accessibility Rules – You will learn how to use the
AccessibilityRules
class, which is a repository of WCAG 2 requirements, success criteria, and techniques. - Screen Reader Accessibility – We will look at how to use the Aspose.HTML for Java library to check a website or any other HTML document for content accessibility for screen readers – whether it contains clear, descriptive alternative text (alt text) for all informative images, buttons, and media elements.
- Сolor Сontrast Accessibility – We will discuss color and proper contrast according to WCAG, the world’s authority on web accessibility. You learn how to check color contrast accessibility using Java and make your web content easy to read for all users.
Remember that web accessibility is an ongoing process, and it’s essential to continuously monitor and improve accessibility to ensure that your website is inclusive and usable by all visitors.
Let’s see a code snippet related to web accessibility validation. It demonstrates the basic steps for creating a validator, loading an HTML document, and validating it for web accessibility compliance:
1// Initialize a webAccessibility container
2WebAccessibility webAccessibility = new WebAccessibility();
3
4// Create an accessibility validator
5AccessibilityValidator validator = webAccessibility.createValidator();
6
7// Prepare a path to a source HTML file
8String documentPath = "test-checker.html";
9
10// Initialize an HTMLDocument object
11final HTMLDocument document = new HTMLDocument(documentPath);
12ValidationResult result = validator.validate(document);
13
14// Checking for success
15if (!result.getSuccess()) {
16 for (RuleValidationResult detail : result.getDetails()) {
17 // ... do the analysis here...
18 System.out.println(String.format("%s: %s = %s",
19 detail.getRule().getCode(),
20 detail.getRule().getDescription(),
21 detail.getSuccess()
22 ));
23 }
24}
Why is Web Accessibility Important
The internet is a vital part of modern life – education, work, healthcare, shopping, and entertainment all rely on digital access. Ensuring that everyone, regardless of ability, can use your site isn’t just good practice – it’s a legal, ethical, and social responsibility.
Here are some more website accessibility statistics. It clearly demonstrates the inability of most online resources to accept people with special needs into their digital world:
- 15% of the global population lives with some form of disability (WHO).
- 54% of adults with disabilities are active online.
- 90% of websites are still inaccessible to users with assistive technologies.
- 71% of users with disabilities leave a site if it’s hard to use.
- 82% of them say they’d spend more money online if sites were accessible.
Website accessibility is not just a moral and legal responsibility; it is a social and economic necessity. Access to information and communication technologies is defined as a fundamental human right in the UN Convention on the Rights of Persons with Disabilities. Failure to comply with accessibility laws in many countries can result in legal consequences and fines.
Web Accessibility Standards
Here are some of the most well-known accessibility standards and guidelines:
- WCAG (Web Content Accessibility Guidelines) provides a set of standards and guidelines for creating accessible web content and is widely used as a reference in the industry.
- Section 508 is a U.S. federal law that mandates accessibility standards for federal agencies’ electronic and information technology. These standards ensure that federal websites and digital services are accessible to people with disabilities.
- EN 301 549 is a European standard aligning with WCAG, which defines accessibility requirements for ICT products and services.
- While ARIA is not a standard in itself, it is a set of technical specifications published by the W3C that provide additional information about the accessibility of assistive technologies. It is often used in conjunction with other standards, such as WCAG.
The fundamental principles of website accessibility include Perceivability, Operability, Understandability, and Robustness. This means that your website should be clear, easy to use, and accessible via a variety of input methods (keyboard, voice commands, assistive technologies such as screen readers).
Web accessibility is a legal requirement in many countries:
- In the United States, under the Americans with Disabilities Act (ADA) and Section 508, certain laws and regulations require websites and digital content to be accessible to people with disabilities.
- The EU has passed laws supporting the rights of people with disabilities. Failure to comply may result in legal consequences and fines.
- In Australia, this is the Disability Discrimination Act.
- In Germany, this is the Federal Regulation on barrier-free information technology, etc.
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.