Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a practical maximum length for HTML id?

The HTML spec says

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

And even though the SGML declaration of HTML 4 uses the value 65536 for NAMELEN, it notes "Avoid fixed limits."

But surely browsers, CSS implementations, and JavaScript toolkits must have some limits on the length they support. What is the smallest such limit that is safe to use in a HTML/CSS/JS application?

like image 574
system PAUSE Avatar asked Feb 24 '09 23:02

system PAUSE


People also ask

How long should HTML lines be?

Avoid lines longer than 80 characters. When a statement will not fit on a single line, it may be necessary to break it.

How many ID can a HTML element have?

You can only have one ID per element, but you can indeed have more than one class. But don't have multiple class attributes; put multiple class values into one attribute.

What characters are allowed for ID in HTML?

From the HTML 4 specification: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Can HTML id be used more than once?

For Html and Css:- In Html Page, You can apply the style of that ID many times as per your wish. If you use same ID to more than one field, then you cannot validate that field. Because, ID must be unique to perform operations on Javascript and JQuery.


1 Answers

Just tested: 1M characters works on every modern browser: Chrome1, FF3, IE7, Konqueror3, Opera9, Safari3.

I suspect even longer IDs could become hard to remember.

like image 179
phihag Avatar answered Oct 05 '22 04:10

phihag