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
Fundamentals
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.
Think of a qualified name like svg:circle: svg is the prefix, circle is the localName.
Concept
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).
Foundation
📝 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.
Item
Detail
Type
string
Access
Read-only property
HTML example
<div> → "div"
Related
tagName, namespaceURI, prefix
⚠️
Case tip
Prefer el.localName === "div" (or el.tagName === "DIV") for comparisons. Mixing cases is a common beginner bug.
Pattern
📋 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.
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");
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)"
});
{
"supported": true,
"returns": "string (local part of qualified name)",
"tip": "In HTML, localName is lowercase; tagName is uppercase",
"status": "Baseline Widely available (MDN)"
}
How It Works
Safe to use broadly. Reach for localName when you want the local tag name, especially for consistent HTML comparisons.
Applications
🚀 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.
Under the Hood
🔧 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.
Important
📝 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.
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.
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported
Yes
localNameBaseline
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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about localName
Read-only string—local part of the element’s qualified name.
5
Core concepts
📄01
Get only
on Element
Kind
📝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.