JavaScript Element localName Property

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

What You’ll Learn

Element.localName is a read-only instance property that returns the local part of an element’s qualified name. Learn how it differs from tagName, why HTML results are lowercase, and how prefixes work in XML/SVG—with five examples and try-it labs.

01

Kind

Instance property

02

Access

Read-only

03

Type

string

04

HTML case

Usually lowercase

05

Status

Baseline widely

06

Pairs with

tagName

Introduction

Every element has a name—div, button, circle, and so on. localName gives you that name as stored in the DOM for the local part of a qualified name.

In everyday HTML pages, beginners often compare tags with tagName. That works, but tagName is uppercase for HTML elements ("DIV"), while localName is lowercase ("div"). For namespaced XML/SVG markup, the local name is the part after the colon.

JavaScript
const box = document.getElementById("box");
console.log(box.localName); // "div"
console.log(box.tagName);   // "DIV"
💡
Beginner tip

Think of a qualified name like svg:circle: svg is the prefix, circle is the localName.

Understanding the Property

MDN: the read-only localName property returns the local part of the qualified name of an element.

  • Read-only — inspect the name; you cannot rename via assignment.
  • String — returns the local name (never null for Element).
  • HTML vs tagName — lowercase local name vs uppercase tagName in HTML DOMs.
  • Baseline — widely available since July 2015 (MDN).

📝 Syntax

JavaScript
localName

Value

A string representing the local part of the element’s qualified name. For HTML elements in an HTML document, this is typically lowercase.

ItemDetail
Typestring
AccessRead-only property
HTML example<div>"div"
RelatedtagName, namespaceURI, prefix
⚠️
Case tip

Prefer el.localName === "div" (or el.tagName === "DIV") for comparisons. Mixing cases is a common beginner bug.

📋 MDN Namespace Example Shape

MDN’s classic example uses a namespaced SVG circle (shown conceptually for HTML tutorials):

JavaScript
// For a namespaced element like svg:circle
console.log(circle.localName);    // "circle"
console.log(circle.namespaceURI); // "http://www.w3.org/2000/svg"

In plain HTML pages, start with localName vs tagName on everyday tags, then explore SVG elements with createElementNS.

Related learning: tagName, namespaceURI, and lastElementChild.

⚡ Quick Reference

GoalCode / note
Read local nameel.localName
Compare in HTMLel.localName === "button"
Compare with tagNameel.tagName === "BUTTON"
SVG local namesvgCircle.localName === "circle"
Namespace URIel.namespaceURI
MDN statusBaseline Widely available

🔍 At a Glance

Four facts about Element.localName.

Kind
get only

Instance

Type
string

Local name

HTML
lowercase

Usually

Baseline
widely

Jul 2015+

Examples Gallery

Examples follow MDN Element: localName. Labs use HTML and SVG elements so you can compare names safely in the browser.

📚 Getting Started

Read the local name of a normal HTML element.

Example 1 — Read localName

Log the local name of a div.

JavaScript
const box = document.getElementById("box");
console.log(box.localName);
Try It Yourself

How It Works

For HTML elements in an HTML document, localName returns the lowercase tag name stored by the DOM.

📈 Compare, SVG & Checks

See tagName case differences, SVG local names, and safe comparisons.

Example 2 — vs tagName

HTML elements show different casing between the two properties.

JavaScript
const btn = document.querySelector("button");
console.log({
  localName: btn.localName,
  tagName: btn.tagName
});
Try It Yourself

How It Works

MDN notes that while localName reflects the DOM’s lowercase storage, tagName returns uppercase for HTML elements in HTML DOMs.

Example 3 — SVG localName

Create an SVG circle and read its local name.

JavaScript
const circle = document.createElementNS(
  "http://www.w3.org/2000/svg",
  "circle"
);
console.log(circle.localName);
console.log(circle.namespaceURI);
Try It Yourself

How It Works

Even without writing a prefix in markup, the local name is "circle" and the namespace URI identifies the SVG namespace—matching the idea behind MDN’s svg:circle example.

Example 4 — Safe Tag Checks

Use localName for lowercase comparisons in HTML.

JavaScript
function isButton(el) {
  return el.localName === "button";
}
const el = document.querySelector("#go");
console.log(isButton(el));
console.log(el.tagName === "BUTTON");
Try It Yourself

How It Works

Both checks can be correct if you match the expected case. localName keeps comparisons readable with lowercase literals.

Example 5 — Support Snapshot

Feature-detect and remember the HTML case tip.

JavaScript
console.log({
  supported: "localName" in Element.prototype,
  returns: "string (local part of qualified name)",
  tip: "In HTML, localName is lowercase; tagName is uppercase",
  status: "Baseline Widely available (MDN)"
});
Try It Yourself

How It Works

Safe to use broadly. Reach for localName when you want the local tag name, especially for consistent HTML comparisons.

🚀 Common Use Cases

  • Checking an element type with lowercase literals (el.localName === "a").
  • Avoiding case bugs when mixing tagName and string compares.
  • Inspecting SVG/XML elements by their local name (for example circle).
  • Logging element kinds while debugging DOM trees.
  • Pairing with namespaceURI when namespaces matter.

🔧 How It Works

1

Element has a qualified name

Possibly with a prefix in XML/SVG contexts.

DOM
2

Browser stores the local part

The name after the colon—or the whole name if unprefixed.

Name
3

Reading returns a string

In HTML DOMs, HTML element local names are lowercase.

Read
4

Compare with matching case

Use localName for lowercase checks; tagName for uppercase HTML tags.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available).
  • Read-only—you cannot assign el.localName = ... to rename a node.
  • In HTML documents, tagName is uppercase for HTML elements; localName is lowercase.
  • Related: lastElementChild, tagName, namespaceURI, namespaceURI, JavaScript hub.

Browser Support

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

Baseline Widely available

Element.localName

Read-only — returns the local part of an element's qualified name as a string.

Baseline Widely available
Google Chrome Supported
Yes
Microsoft Edge Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Opera Supported
Yes
Internet Explorer Supported
Yes
localName Baseline

Bottom line: Use localName to read an element's local tag name. In HTML, prefer it for lowercase comparisons; remember tagName is uppercase for HTML elements.

Conclusion

localName is the clean way to read an element’s local name. It shines for lowercase HTML comparisons and for understanding namespaced SVG/XML names where the part after the colon matters.

Continue with namespaceURI, lastElementChild, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use localName for lowercase HTML tag checks
  • Pair with namespaceURI when working with SVG/XML
  • Remember MDN’s prefix tip: local name comes after the colon
  • Prefer consistent comparisons (=== "div")
  • Use it for readable debugging of element kinds

❌ Don’t

  • Assign to localName (it is read-only)
  • Compare localName to uppercase HTML tags like "DIV"
  • Assume tagName and localName always match in case
  • Ignore namespaces when comparing SVG/XML elements
  • Use it when you need the full qualified name with prefix

Key Takeaways

Knowledge Unlocked

Five things to remember about localName

Read-only string—local part of the element’s qualified name.

5
Core concepts
📝 02

string

local name

Type
🔍 03

HTML lower

vs tagName

Use
04

Baseline

widely available

Status
🎯 05

After colon

in XML names

Tip

❓ Frequently Asked Questions

It returns 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". The prefix and namespaceURI describe the namespace separately.
Yes. You read it to inspect the element name. You cannot assign to localName to rename an element.
Use localName when you want a stable, case-normalized name for comparisons in HTML, or when working with namespaced/SVG markup where the local part matters.
Did you know?

In the qualified name comm:partners, partners is the local name and comm is the prefix—exactly how MDN explains localName.

Next: namespaceURI

Learn how Element.namespaceURI reports an element’s namespace.

namespaceURI →

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