9

How would I know what the maximum length of an element's attribute value is?

e.g.

<div id="value1..."></div>

What's the maximum allowable length for ID attribute of this div and any other attributes of any elements?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
mars-o
  • 1,695
  • 4
  • 23
  • 38
  • 2
    Duplicate of http://stackoverflow.com/questions/1496096/is-there-a-limit-to-the-length-of-html-attributes. See also http://stackoverflow.com/questions/584184/what-is-a-practical-maximum-length-for-html-id – outis May 02 '10 at 04:46

3 Answers3

18

According to the SGML Declaration of HTML 4, the limit could be 65536 characters:

ATTSPLEN 65536   -- These are the largest values --
LITLEN   65536   -- permitted in the declaration --
NAMELEN  65536   -- Avoid fixed limits in actual --
PILEN    65536   -- implementations of HTML UA's --

The LITLEN limits the number of characters which can appear in a single attribute value literal and the ATTSPLEN limits the sum of all lengths of all attribute value specifications which appear in a tag.

Apparently, the limits used to be much lower in HTML 2, and people were complaining back then in 1995.

Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
2

According to this page, technically unlimited. An actual test in various browsers will show their limits but my guess is the limit would be unreasonably long.

Trey Hunner
  • 10,975
  • 4
  • 55
  • 114
1

Beyond any practical need.

I use ASP webforms regularly, and often have 100+ character ID's.

Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222