HTML TUTORIAL
The HTML id
In many cases, it is very useful to identify an HTML element with a unique id. It may be used to create a hyperlink to that particular element within the webpage.
Here is a code snippet that shows the usage of linking to the internal element of the HTML
|
Take a look at the complete example here.
|
You may try this example online here
Example - Understanding headers
There are other usage of the id. As you may learn, using Cascading Style Sheet , you can apply the styling to one particular HTML element. To apply the Styling to a particular element you need to identify it with its id.
The id is also used in advance programming. Using jQuery , for example, we may format or change the content, style, or perform other action on that particular id.
ID must be unique
The html id attribute must be absolutely unique. An id applied to an element must not match an id used anywhere else on the same page. This is different from html class where you can have more than one html element share the same class.
ID Value syntax
The id attribute value must follow some basic syntax rules. It must begin with a small or a capital letter in the range(a–z or A–Z). This is followed by any combination of letters (a–z or A–Z), digits (0–9), hyphens (-), underscores (_), colons (:), and periods (.).
Additionally, id value is case sensitive, so
<h1 id="section1">Header 1 </h1>
is different from
<h1 id="Section1">Header 1 </h1>