Accessibility in HTML and CSS: Making Your Website Inclusive

Eziuche Nwaogu
LearnFactory Nigeria
5 min readMay 23, 2023
Photo by Growtika on Unsplash

Introduction:

In today’s digital age, ensuring that websites are accessible to everyone is not only a legal requirement but also an ethical responsibility. The process of accessibility entails the creation and construction of websites in a manner that enables individuals with disabilities to effectively perceive, navigate, and interact with the content. In this write-up, we will explore the importance of accessibility in web design and discuss how HTML and CSS can be leveraged to create inclusive websites.

Understanding Accessibility:

Web accessibility refers to the practice of removing barriers that prevent individuals with disabilities from accessing and utilizing websites. Disabilities can range from visual impairments, hearing loss, and motor disabilities to cognitive and neurological conditions. Accessibility benefits not only people with disabilities but also the broader user base, including the elderly, those with temporary impairments, and users with limited access to technology or low-bandwidth connections. By implementing accessibility standards, web developers can ensure that everyone, regardless of their abilities, can comprehend and engage with the content on a website. It also ensures improved Search Engine Optimization (SEO).

Semantic HTML for Accessibility:

HTML plays a fundamental role in making websites accessible. By utilizing semantic HTML elements, developers can provide additional meaning and context to the content, enabling assistive technologies such as screen readers to interpret and convey information accurately. Some basic HTML elements for accessibility include:

1. Use the proper Semantic Tags: Semantic tags make accessibility easier. It also makes it easier for assisted technologies to properly read and convey information accurately. Basic semantic tags include:

· Doctype(<!DOCTYPE>): This defines the type of document (usually HTML5)

· HTML(<html></html): This defines a HTML document

· The Head(<head></head>): This provides information about the document

· Body Tag(<body></body>): This defines the body of the document

· The Header Tag(<header></header>)

· Main tag(<main></main>)

· Section tag(<section></section>)

· Footer(<footer></footer>)

· Article(<article></article>)

· Aside(<aside></aside>)

· Meta (<meta>)

2. Headings: Properly structured headings (h1-h6) assist users in understanding the hierarchy and organization of content.

3. Alternative Text (Alt Text): The Alternative text is very essential for images. This enables individuals who make use of screen readers to understand visual content. Descriptive alternative image-text for images should be provided. It should be concise and accurate. It should also convey the information contained in the image. This is achieved using the code below:

<img src=”image_source/image” alt=”image description”>.

4. Labels and Forms: Associating labels with form elements helps users understand the purpose and provides clear instructions for interaction. Input fields that do not have a visual label still require a label. This is achieved through the use of the “aria-label”. This is denoted by the expression below:

<input placeholder=”Enter search term” aria-label=”Enter search term”>

If the alt text is not done, the screen readers may not convey the information within the image correctly or even skip the image altogether.

5. Forms: Forms require a higher level of label in addition to the <label> tag. This is achieved through the use of <fieldset> and <legend>. The fieldset is used to group related data in a form while the legend defines a caption for the fieldset element. This is illustrated in the code below:

<form action="/action_page.php">
<fieldset>
<legend>Personal Details:</legend>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="Smith"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Dean"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>

6. Tables: Structuring tables using the <caption>, <th>, and <td> elements ensures they are correctly interpreted by assistive technologies.

7. The use of the strong tag(<strong></strong>) and the em tag(<em></em>) are encouraged as they are interpreted better by the screen readers.

CSS for Accessibility:

While HTML lays the foundation, CSS (Cascading Style Sheets) complements it by controlling the visual presentation of web pages. CSS can contribute significantly to accessibility by enhancing the readability, usability, and flexibility of websites. Here are some CSS techniques for improving accessibility:

1. Contrast of Colors: Make sure there is a suitable distinction between the colors of the text and the background, enabling individuals with visual impairments to read and understand the content more easily.

2. Responsive Design: Create adaptable layouts that can seamlessly adjust to different screen sizes and orientations, providing a consistent and user-friendly experience across a range of devices.

3. Focus Styles: Applying distinct focus styles to interactive elements, such as links and form fields, helps individuals with motor disabilities navigate through the website using keyboard or assistive devices.

4. Media Queries: Utilize media queries to adjust the layout and presentation of content based on the user’s preferences, such as font size or color scheme.

Testing and Validation:

Web accessibility testing is a crucial process that ensures web and mobile applications can be used by individuals with disabilities.

The Web Content Accessibility Guidelines, developed by the World Wide Consortium (W3C), establish a set of accessibility standards. These guidelines are organized into four fundamental principles:

1. Perceptibility: The presentation of information and user interface elements should be designed in a way that allows users to perceive and comprehend them effectively. This guarantees that users can both access and understand the information provided.

2. Operability: The user interface components and navigation should be easily manageable. This implies that users should be able to interact with the interface without encountering any actions they are incapable of performing.

3. Comprehensibility: The information and operation of the user interface should be clear and easily understood. Users should be able to comprehend both the content and the functioning of the user interface without encountering concepts or functionalities that are too complex for them.

4. Robustness: The content should be strong and resilient enough to be accurately interpreted by assistive technologies. This ensures that users can continue to access the content as technology progresses. Regardless of evolving technologies and user agents, the content should remain accessible to all individuals.

Numerous tools and techniques are available to assess the accessibility compliance of your HTML and CSS code. Some popular options include automated accessibility checkers, manual testing with assistive technologies, and user testing involving individuals with disabilities.

Some sites that run website checks include:

· The Web Accessibility Versatile Evaluator(WAVE) https://wave.webaim.org/

· Sa11y https://sa11y.netlify.app/

· Accessibility checker https://www.accessibilitychecker.org/

· Functional Accessibility Evaluator (FAE) https://fae.disability.illinois.edu/anonymous/?Anonymous%20Report=/

It is however to be noted that no tool has been developed that can completely replace a human being. This is because it is very difficult to emulate human attributes such as common sense. They are to be used with caution. Manual testing should be used to complement automated testing.

Conclusion:

Building an inclusive website that caters to a diverse audience requires a holistic approach to accessibility. By leveraging the capabilities of HTML and CSS, web developers can create an inclusive online experience for individuals with disabilities. Embracing accessibility not only meets legal obligations but also promotes equality, inclusivity, and a positive user experience for all.

Thanks for reading.

--

--