Favorites

DOM Element.id Property

☕
Enjoying this site?

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

Buy us a coffee
Element.id
DOM Element PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The id property gets or sets an element's id attribute.

Description

The id property reflects the element's id attribute: its unique identifier in the document. IDs are used by getElementById(), CSS #id selectors, fragment links and attributes such as for and aria-labelledby, so each must be unique on the page.

Changing an element's id can break CSS rules, links and ARIA relationships that refer to the old value, so avoid changing it after the page has loaded unless you update everything that depends on it.

IDs are case-sensitive and must not contain spaces. Elements with an id are also available as global variables with the same name in browsers, a legacy feature you shouldn't rely on; use getElementById() instead.

Syntax

element.id
element.id = value

Value

A string: the element's id attribute, or an empty string.

Example

<section id="intro">Content</section>
const el = document.querySelector('section');
console.log(el.id);
el.id = 'pricing';
console.log(document.getElementById('pricing') === el);

Browser Support

The following information will show you the current browser support for the Element.id property. Hover over a browser icon to see the version that first introduced support for this property.

This property 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