HTML id Attribute

 

ATTENTION: THIS PAGE IS Valid HTML 5 AND IS BEST VIEWED WITH HTML 5 - Please upgrade your browser or download one of the HTML 5 compatible browsers such as Mozilla Firefox, Chrome, Opera or IE 9 (March 14, 2011 or later). For more information see HTML 5 browsers.


If you find this helpful, please click the Google +1 Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.)


PDF mobile

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 id attribute is one of the global attributes that may be included on any HTML element.
  • The value of the id attribute cannot be an empty string and is not permitted to have any spaces within it.
  • The same id attribute value cannot be used for any other id in 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 an id attribute. Since the value of the id attribute must be unique, the same value should never be used for any other id or name attribute 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>
Episode #1
Episode #2
Episode #3
Episode #4
Episode #5
Episode #6
Episode #7
Episode #8
Episode #9
Episode #10
Episode #11
Episode #12
Episode #13
Episode #14
Episode #15
Episode #16
Episode #17
Episode #18
Episode #19
Episode #20
Episode #21
Episode #22
Episode #23
Episode #24
Episode #25
Episode #26
Episode #27
Episode #28
Episode #29
Episode #30
Episode #31
Episode #32
Episode #33
Episode #34
Episode #35
Episode #36
Episode #37
Episode #38
Episode #39
Episode #40
Episode #41
Episode #42
Episode #43
Episode #44
Episode #45
Episode #46
Episode #47
Episode #48
Episode #49
Episode #50
Episode #51
Episode #52
Episode #53
Episode #54
Episode #55
Episode #56
Episode #57
Episode #58
Episode #59
Episode #60
Episode #61
Episode #62
Episode #63
Episode #64
Episode #65
Episode #66
Episode #67
Episode #68
Episode #69
Episode #70
Episode #71
Episode #72
Episode #73
Episode #74
Episode #75
Episode #76
Episode #77
Episode #78
Episode #79
Episode #80

Valid HTML 5