How I make my apps more accessible: axe Accessibility Linter
Tags: webdev, a11y, javascript, html
Published: 2023-02-21 20:18:17

Last time I talked to you about [axe DevTools](https://dev.to/celest67/how-i-make-my-apps-more-accessible-axe-devtools-cmh) and how to use it to improve the accessibility of your site.

Now I want to talk to you about the "brother": [axe Accessibility Linter](https://www.deque.com/axe/linters/). This is an extension for VSCode and [here](https://marketplace.visualstudio.com/items?itemName=deque-systems.vscode-axe-linter) you can get it.

This one is so easy to use that I'm kinda shocked that more people don't use it. You just have to install it and it starts working right away. You could put more thought into it and add a `axe-linter.yml` configuration file, but for me it works great right out of the box.

Works with most languages that we use in the front nowadays.

> Checks React (.js .jsx .ts .tsx), Vue (.vue), Angular (.component.html), HTML (.html .htm), and Markdown (.md .markdown) files so you can avoid common accessibility defects. Inline Angular templates are not currently supported.

I can't say enough how much I like this one, I like it because this way you can avoid many accessibility issues before you even deploy your site.

> Axe-linter is now available on a multitude of other platforms! We currently provide integrations for:
>
> - GitHub Actions
> - Git Pre-Commit Hooks
> - SonarQube
> - Jenkins, Azure DevOps, CircleCI, and more!

The idea is that while you are coding you get errors right there in your VSCode. So let me show you some examples, for this I just have a simple html form but remember that this extension also works with javascript and typescript.

The first error that I get is because I didn't set up the language of my page.

![lang error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ptqqmj5iiubdhfffctq.png)

And this matters because if you have a screen reader you need to tell it how the words have to sound.

Next we have an error in our title: 
>Screen readers alert users to the presence of a heading tag. If the heading is empty or the text cannot be accessed, this could either confuse users or even prevent them from accessing information on the page's structure.

![title error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yejqabe3i9mc8jgwv7gb.png)

Some other errors that you can detect may be related to interactive controls, like this one where you have a link inside a button

![nested error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgqpgmo3wfoy2wla3vzv.png)

Then this one I have seen a million times, images without an alt, a screen reader will say that is an image but the user has no way of knowing what  it is about.

![image error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tpibbo7h0bomzp3djcyl.png)

Then you can have errors where you try to use a role that is not meant to be for the element that you have, like this.

![role error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mia322c6a8r4g7wwj4r0.png)

> When a text node is split by markup, VoiceOver will treat it as two separate phrases instead of just one. Adding role="text" around the elements solves the problem. However, it also overrides the role of the element and all descendants and treats them all as text nodes. If one of the descendant elements is also focusable it would create an empty tab stop. That is, you could tab to the element but VoiceOver would not announce its name, role, or value.

These are just some examples of what you can detect, I hope it helps you!

Well I think that is it for now.

Cheers!