|
If you find this helpful, please click the Google |
The id attribute in HTML
The id attribute is a unique identifier for an element in an HTML document.
Rules for coding an id attribute
- The
idattribute is one of the global attributes that may be included on any HTML element. - The value of the
idattribute cannot be an empty string and is not permitted to have any spaces within it. - The same
idattribute value cannot be used for any otheridin the same HTML document. It must be unique. - For backward compatibility, most browsers will treat the deprecated
<a name>attribute on elements where it is not supposed to be coded as if it were anidattribute. Since the value of theidattribute must be unique, the same value should never be used for any otheridornameattribute within the same document.
Rules for referencing a fragment identifier
When an id value is referenced in a URL attribute such as <a href>, it must be URL encoded along with the rest of the URL. Use percent escape codes as explained in the URL-encoding tutorial for any special characters in the URL, including the fragment identifier. For example, when the fragment identifier contains a hash character (#), which is common for podcast episodes in feeds or HTML transformed from a feed by a style sheet it must be encoded as %23.
Here is an example HTML link that references a fragment identifier with a # character percent-encoded character as %23 in the link.
<a href="http://www.HTML-5.com/attributes/id-attribute.html#%2355">Episode #55</a>