Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Forms Fieldsets and Labels

Names vs IDs

I can see why IDs are helpful (here adding a label, and I assume server-side actions will also use the ID). However, what is the purpose of the "name"? It seems like it's redundant with the ID.

2 Answers

Blayne Holland
Blayne Holland
19,320 Points

I can't really give you a detail answer but I find name attributes particularly useful when working with PHP. The name attribute is used to help identify form elements when submitting the form using POST.

Jack Weldon
Jack Weldon
1,708 Points

The name attribute serves two purposes - it's used for servers to identify the form/field and it can help add context to your code when looking through it. IDs are used within the HTML document for various functions such as links, for example.