ARIA code Role
The code role marks a short fragment of computer code. The code element has this role.
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
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.
Desktop





Tablets & Mobile





