JavaScript Element ariaLevel Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance property

What You’ll Learn

Element.ariaLevel is an instance property that reflects the aria-level attribute. Learn how it stores a hierarchical level as a string integer, when to prefer native <h1><h6> headings, and how to get or set the property from JavaScript—with five examples and try-it labs.

01

Kind

Instance property

02

Type

String (integer)

03

Example

"1" · "2" · "3"

04

Reflects

aria-level

05

Status

Baseline widely

06

Common with

role="heading"

Introduction

Documents and widgets often have hierarchy: page title, section title, nested tree items. Assistive technologies need to know which level an item sits at in that structure.

aria-level carries that number as a string. ariaLevel is the JavaScript reflection of that attribute.

JavaScript
const el = document.getElementById("main-heading");
console.log(el.ariaLevel); // "1"
el.ariaLevel = "2";
💡
Beginner tip (MDN)

Where possible, use an HTML <h1> (or other correct heading level). Native headings already expose hierarchy and do not need ARIA attributes. Reach for role="heading" plus ariaLevel mainly when you cannot use a real heading element.

Understanding the Property

MDN: the ariaLevel property of the Element interface reflects the value of the aria-level attribute, which defines the hierarchical level of an element within a structure.

  • Reflected attribute — mirrors aria-level.
  • Get / set — readable and writable string containing an integer.
  • Hierarchy — level within headings, trees, and similar structures.
  • Baseline — widely available since October 2023 (MDN).

📝 Syntax

JavaScript
ariaLevel

Value

A string containing an integer.

ExampleMeaning
"1"Top / first level (often like h1)
"2"Second level (often like h2)
"3"Third level, and so on
⚠️
Prefer native headings

If you can write <h2>Section title</h2>, do that instead of role="heading" aria-level="2". ARIA is a bridge when native HTML is not available.

📋 MDN Example Shape

MDN starts with role="heading" and aria-level="1", then updates the level to "2" with the property:

JavaScript
<div role="heading" id="main-heading" aria-level="1">
  This is a main page heading
</div>
JavaScript
let el = document.getElementById("main-heading");
console.log(el.ariaLevel); // "1"
el.ariaLevel = "2";
console.log(el.ariaLevel); // "2"

⚡ Quick Reference

GoalCode / note
Readel.ariaLevel
Set levelel.ariaLevel = "2"
Value shapeString integer ("1", "2", …)
Prefer when possibleNative <h1><h6>
Common pairingrole="heading"
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.ariaLevel.

Kind
get / set

Instance

Type
string

Integer text

Reflects
aria-level

Attribute

Baseline
widely

Oct 2023+

Examples Gallery

Examples follow MDN Element: ariaLevel. Labs use a role="heading" element so you can safely read and write the property.

📚 Getting Started

Read the reflected value and follow MDN’s update.

Example 1 — Read ariaLevel

Log the hierarchical level from a custom heading.

JavaScript
const el = document.getElementById("main-heading");
console.log(el.ariaLevel);

// HTML includes: role="heading" aria-level="1"
Try It Yourself

How It Works

The property returns the attribute string. If the attribute is missing, many browsers return null.

Example 2 — MDN Update to "2"

MDN: change the heading level from 1 to 2.

JavaScript
let el = document.getElementById("main-heading");
console.log(el.ariaLevel); // "1"
el.ariaLevel = "2";
console.log(el.ariaLevel); // "2"
Try It Yourself

How It Works

Assigning the property updates the reflected aria-level attribute so assistive technologies hear the new hierarchical level.

📈 Create Heading Level, Attribute Sync & Snapshot

Practice setting levels and verify reflection.

Example 3 — Create a Level-3 Heading Role

Build a custom heading and set ariaLevel to "3".

JavaScript
const el = document.createElement("div");
el.setAttribute("role", "heading");
el.textContent = "Subsection title";
document.body.appendChild(el);

el.ariaLevel = "3";
console.log({
  ariaLevel: el.ariaLevel,
  attr: el.getAttribute("aria-level")
});
Try It Yourself

How It Works

Pair role="heading" with a correct level. Prefer <h3> in real pages when you can.

Example 4 — Property vs getAttribute

Confirm the attribute stays in sync after a write.

JavaScript
const el = document.createElement("div");
el.setAttribute("role", "heading");
el.setAttribute("aria-level", "1");
el.textContent = "This is a main page heading";
document.body.appendChild(el);

el.ariaLevel = "2";
console.log({
  fromProperty: el.ariaLevel,
  fromAttribute: el.getAttribute("aria-level"),
  same: el.ariaLevel === el.getAttribute("aria-level")
});
Try It Yourself

How It Works

Prefer ariaLevel in script; keep the attribute for HTML markup.

Example 5 — Support Snapshot

Feature-detect and remember the native-heading preference.

JavaScript
console.log({
  supported: "ariaLevel" in Element.prototype,
  type: "string containing an integer",
  tip: "Prefer native h1–h6 when possible (MDN)",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Use ariaLevel when ARIA heading (or another leveled role) is required; otherwise lean on HTML semantics.

🚀 Common Use Cases

  • Custom role="heading" widgets that cannot use <h1><h6>.
  • Updating heading level when a section moves in the document outline.
  • Tree items that expose nesting depth via aria-level.
  • Design-system components that render headings as non-heading tags.
  • Keeping script and markup aligned without manual setAttribute.

🔧 How It Works

1

Element sits in a hierarchy

Heading outline, tree, or similar structure.

Structure
2

Set ariaLevel to a string integer

The property reflects aria-level for get and set.

Declare
3

Assistive tech announces the level

Users hear heading level 2, tree depth 3, and so on.

Announce
4

Hierarchy stays understandable

Especially when native heading tags are unavailable.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available).
  • Prefer native <h1><h6> when possible (MDN note).
  • Value is a string containing an integer, not a Number type.
  • Related: ariaLive, ariaLabel, EventTarget, JavaScript hub.

Browser Support

Element.ariaLevel is Baseline Widely available (MDN: across browsers since October 2023). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.ariaLevel

String integer — reflects aria-level for hierarchical level within a structure.

Baseline Widely available
Google Chrome Supported (ARIA reflection)
Yes
Microsoft Edge Supported (ARIA reflection)
Yes
Mozilla Firefox Supported (ARIA reflection)
Yes
Apple Safari Supported (ARIA reflection)
Yes
Opera Follow Chromium support
Yes
Internet Explorer No ariaLevel IDL — use setAttribute
No
ariaLevel Baseline

Bottom line: Use ariaLevel to declare hierarchy for ARIA heading (and similar) roles. Prefer native HTML headings when you can. Keep the value as a string integer such as "1" or "2".

Conclusion

ariaLevel reflects aria-level so hierarchical widgets can expose their depth as a string integer. Reach for native headings first; use this property when ARIA heading roles (or other leveled roles) are the only option.

Continue with ariaLive, ariaLabel, EventTarget, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer <h1><h6> when possible
  • Use string integers like "1" and "2"
  • Keep levels consistent with the visible outline
  • Pair with role="heading" when using custom tags
  • Test heading navigation with a screen reader

❌ Don’t

  • Skip native headings just to use ARIA
  • Jump levels randomly (1 then 4 with no reason)
  • Store a Number type and assume AT will coerce it
  • Use aria-level on elements that are not hierarchical
  • Forget a clear accessible name on the heading text

Key Takeaways

Knowledge Unlocked

Five things to remember about ariaLevel

Reflected aria-level string for hierarchical level.

5
Core concepts
📝 02

String integer

"1" "2" "3"

Type
🔍 03

Prefer h1–h6

when possible

MDN
04

Baseline

widely available

Status
🎯 05

heading role

common pairing

Use

❓ Frequently Asked Questions

It reflects the aria-level attribute as a string containing an integer, which defines the hierarchical level of an element within a structure.
No. MDN marks Element.ariaLevel as Baseline Widely available (since October 2023). It is not Deprecated, Experimental, or Non-standard.
A string containing an integer, for example "1", "2", or "3".
No when you can avoid it. MDN recommends using HTML heading elements (h1–h6) where possible because they have built-in semantics and do not require ARIA attributes.
When you use role="heading" (or other hierarchical roles such as treeitem) and need to declare the level in the accessibility tree.
Yes. Reading and writing ariaLevel updates the reflected aria-level attribute.
Did you know?

aria-level is not only for headings. Roles like treeitem can also use it to express nesting depth. Still start with the simplest native HTML that matches your structure.

Next: Element ariaLive

Learn the reflected aria-live property for live region update priority.

ariaLive →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful