Yogesh Chauhan's Blog

Give buttons accessible names

in UI/UX on November 2, 2020

If you try to run an audit check from Google or any other services, you might get an accessibility error saying that, “Buttons do not have an accessible name”.

When a button doesn’t have an accessible name screen readers and other assistive technologies announce it as button.

When someone who is a disabled and using hearing devices or any other means to get access to your website, the button will no serve any purpose. Because it will provide no information to users about what the button does.

How to add accessible names to buttons

For buttons with visible labels, add text content to the button element.

Make the label a clear call to action.

For example:


<button>Book room</button>

For buttons without visible labels, like icon buttons, use the aria-label attribute to clearly describe the action to anyone using an assistive technology.

For example:


<button class="btn" aria-label="Left Arrow">
   <span class="class-name" aria-hidden="true">left_arrow</span>
</button>

OR

<button aria-label="Close" onclick="myDiv.close()">X</button>

The aria-label attribute

The aria-label attribute is used to define a string that labels the current element.

We can use it in cases where a text label is not visible on the screen.

If there is visible text labeling the element, use aria-labelledby instead.

This attribute can be used with any typical HTML element; it is not limited to elements that have an ARIA role assigned.

Sources


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to add MySQL alternate port and sockets/pipes in WordPress?WordPressWhat are Big Data Clusters in SQL Server?SQL/MySQLJavaScript Input Validation Theme Park Example using throw StatementJavaScriptLearn how to give a temporary name to a column or to a table using SQL AliasesSQL/MySQLABS and NEG functions in Envision BasicEnvision BasicA Step by Step Guide to Make RSS in XML For Any Website or Blog For FreeMiscellaneous