top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Difference between id and name attributes in HTML

+2 votes
135 views

what is the Difference between id and name attributes in HTML?

posted May 26, 2014 by Muskan

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+2 votes
 
Best answer

Use the id attribute to identify elements for style and scripting purposes. Use the name attribute only for form elements.

Other than forms, there’s really no reason to use the name attribute now that the id attribute is universally compatible. The only practical use that name has left is for submitting your form values.

Some differences can be:

Id Attribute
Valid on any element
Each Id should be unique
Can be used as anchor reference in URL
Is referenced in CSS or URL with # sign
Is referenced in JS with getElementById()
Shares same name space as name attribute
Must begin with a letter
Is case sensitive

Name Attribute
Valid only on a, form, iframe, img, map, input, select, textarea
Name does not have to be unique
Can not be referenced in CSS or URL
Is referenced in JS with getElementsByName()
Shares same name space as id attribute
Must begin with a letter
Is case sensitive
Used on form elements to submit information

answer May 29, 2014 by Asmita Agrawal
Solid Statement:
Use the id attribute to identify elements for style and scripting purposes. Use the name attribute only for form elements.
Similar Questions
0 votes

Sorry for simple question, need to clean some queryhome code.

Can someone help me to find out the difference between these three: onclick, onmouseover, onmouseout.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...