JavaScript Element localName Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Element.localName is a read-only string: the local part of the element’s qualified name (MDN). In HTML it is usually the lowercase tag (e.g. "div").

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use el.localName. Start with this line.

JavaScript
element.localName
CallWhat it does
element.localNamePrimary signature.

Built into the browser. Read or assign el.localName — no import required.

Library declarations
JavaScript
element.localName

Parameters

ParameterDescription
Namespace propsOptional. prefix, namespaceURI for XML/SVG

Return Value

Return ValueDescription
*String (local part)

JavaScript Examples

Example 1 — Read localName

Read the local name of a normal HTML element.

JavaScript
const box = document.getElementById("box");

console.log(box.localName);
// "div"
Try It Yourself

How It Works

  1. Find the element. getElementById("box") returns a <div>.
  2. Read localName. You get the local name string.
  3. HTML result. In an HTML document that string is "div" (lowercase).
  4. Read-only. You inspect the name; you do not rename the element this way.

Example 2 — localName vs tagName

In HTML DOMs, tagName is uppercase while localName is lowercase.

JavaScript
const el = document.querySelector("button");

console.log(el.localName); // "button"
console.log(el.tagName);   // "BUTTON"

console.log(el.localName === "button"); // true
console.log(el.tagName === "button");   // false
Try It Yourself

How It Works

  1. Same element, two strings. Both name the element, with different casing rules.
  2. localName is lowercase for HTML elements in HTML documents.
  3. tagName is uppercase for those same HTML elements.
  4. Comparisons. Prefer localName === "button" (or uppercase tagName on purpose).

Example 3 — SVG localName

Create an SVG circle and read its local name (and namespace).

JavaScript
const NS = "http://www.w3.org/2000/svg";
const circle = document.createElementNS(NS, "circle");

console.log(circle.localName);    // "circle"
console.log(circle.namespaceURI); // "http://www.w3.org/2000/svg"
Try It Yourself

How It Works

  1. Create in the SVG namespace. createElementNS builds a real SVG element.
  2. Local name is "circle". That is the part after any prefix in a qualified name.
  3. Namespace is separate. namespaceURI tells you which vocabulary it belongs to.
  4. MDN idea. For svg:circle, the local name is still "circle".

Browser Support

Element.localName is Baseline Widely available (MDN: since July 2015). Safe across modern and older evergreen browsers.

✓ Baseline · Widely available

Element.localName

Read-only local part of the element's qualified name — lowercase for HTML in HTML DOMs.

99% Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
localName Excellent

Bottom line: Safe for production. Prefer localName for case-stable HTML tag checks.

Frequently Asked Questions

The local part of the element's qualified name as a string. For HTML elements in an HTML document, that is usually the lowercase tag name (for example "div").
No. MDN marks Element.localName as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
In HTML documents, tagName is uppercase for HTML elements ("DIV"), while localName is lowercase ("div"). localName is also the part after the colon in a namespaced qualified name.
The local name is the part after the colon. For svg:circle, localName is "circle". Use prefix and namespaceURI for the namespace parts.
Yes. You read it to inspect the element name. You cannot assign to localName to rename an element.
Use localName for case-stable comparisons in HTML, or when working with SVG/XML where the local part of a qualified name matters.

Next: namespaceURI

Learn how to read the namespace URI of an element.

namespaceURI tutorial →

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.

12 people found this page helpful