Can anyone explain the id Attributes?


I’m totally new to HTML and studying and making notes from Codeacademy. From what i understood is that “id” attribute have no effect and only use to identify an element. Is it Correct?

If it’s correct, Is it really helpful to use it in HTML? to me it looks like it can be extremely helpful since ‘id’ attribute can identify the element (which you might need to Edit etc.) easily from your more than 1,000 coding lines.


The attribute has no effect but it does have a variety of important roles.

  1. Fragment anchor … The element can be hooked with a link
  2. Higher importance … id has specificity 0 1 0 0
  3. Unique selector … Styles can be confined to one fragment
  4. Unique node … Script can listen for events on single element node

Like everything else in HTML, need is the driver of design. If there is no need for it, then don’t use it.

From a coding perspective, line number bookmarks are usually available in most text editors, but searching for hooks in the code is a time saver. Can’t really say I’ve ever relied on that approach but it does have some value.

Keep forging ahead with HTML and CSS (and JavaScript) so you get a feel for where this attribute will be a good fit with sensible purpose in mind (styling, fragment, selector, node). Fow now stick to the instructions in the track, and review each unit upon completion by experimenting in the lesson workspace (or a sandbox like REPL . IT).


Thanks for the Reply! much appreciated.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.