Favorites

ARIA code Role

code
ARIA Document Structure RoleThis ARIA role is supported by all modern browsers.
Updated 28th November 2026

The code role marks a short fragment of computer code. The code element has this role.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The code role identifies a fragment of computer code, such as a CSS property name, a file name or a function call. The <code> element has this role natively, and that is the element to use. Like other text-level roles, it can't be given an accessible name, and many screen readers don't announce it by default unless the user turns on formatting announcements.

For longer blocks of code, wrap the <code> element in a <pre> element to keep the white space.

Use the native HTML <code> element where you can: it already has the code role, with the expected keyboard and browser behavior built in.

Properties

Category
Document Structure
HTML equivalent
<code>
Accessible name from
prohibited
Required parent role
None
Required child roles
None

ARIA Attributes

Required
None
Supported
None
Prohibited
aria-label, aria-labelledby
Global
All global ARIA attributes can also be used, such as aria-label, aria-labelledby, aria-describedby, aria-hidden.

Syntax

<element role="code">

Example

<p>Set <code>display: grid</code> on the container.</p>
<p>Or call <span role="code">document.querySelector()</span>.</p>

Browser Support

The following information will show you the current browser support for the code ARIA role. Hover over a browser icon to see the version that first introduced support for this ARIA role.

This ARIA role is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee