When do you use id and name in a form?

I’m learning about forms in HTML and I’m struggling to understand when to use id and name in a form and the difference between them both, if anyone has an answer please tell me.


must be unique to an element.
CAN be referenced in CSS.

CAN’T be referenced in CSS.
can only be used with selected elements ( button, input, form, etc )

I believe, in general, name is used for things like retrieving user input, working out which button has been pressed, etc.

So, for example, you could have a set of radio buttons which each have their own id, so you can style them individually. But then they also have a common name attribute so that only one will be selected at a time.

Hope that helps