Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a colon mean within an HTML id attribute?

Tags:

html

css

tags

colon

I have seen an HTML code like this for the ID attribute:

id="t1:c3" 

Can someone explain this to me? What is the purpose of the colon (:)?

Thank you.

like image 256
Ryan Avatar asked Aug 23 '10 05:08

Ryan


People also ask

What are id attributes in HTML?

The id attribute specifies a unique id for an HTML element. The value of the id attribute must be unique within the HTML document. The id attribute is used to point to a specific style declaration in a style sheet. It is also used by JavaScript to access and manipulate the element with the specific id.

What is the symbol for id in HTML?

In Html for an element ID name starts with the “#” symbol followed by a unique name assigned to it.

Can HTML id have special characters?

The HTML 4.01 spec states that ID 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 ( . ). For the class attribute, there is no such limitation.


2 Answers

Colons are allowed inside ID attributes, but hold no special significance. It's not really advisable to use them because they can sometimes cause problems, such as when used with jQuery or CSS, where the colon has special meaning as a pseudo-selector.

like image 64
Chris Fulstow Avatar answered Oct 11 '22 02:10

Chris Fulstow


If the HTML is generated with Java ServerFaces this usually produces such IDs, i.e. if the form has the ID form1 and the element has the ID firstName this results in an ID form1:firstName if the element is on top level, if there are several ones created in a loop they look like form1:1:firstName, form1:2:firstName, …

This framework behaviour cannot be changed.

like image 41
Matthias Ronge Avatar answered Oct 11 '22 03:10

Matthias Ronge