Id, name inside Inputs

What’s the use of “id”, “name” or “value” - those attributes inside an input in html?
What is it for?

<input id="loving" type="checkbox" name="personality"> <label for="loving">Loving</label>

Hi,
So id is basically used to connect the input with a label. in your example <label for="loving"> will automatically connect to an input with the same id, it is also used to style the input. name is used in data storing or when submitting a data to a database, and value is anything the user types into the input. In some cases like radio buttons or checkboxes you would give the value yourself and the user would just choose it. name and value are both used in backend, when the form is submitted, the data from the form will be posted into a database, it’s like a variable with a name and a value.

1 Like

Well the id, name & value in HTML input elements serve multi purposes like the id provides a unique identifier for the input element and allow it to be targeted specifically for styling etc. “Name” defines the name of the input field and it identify that data when the form is sent to the server, and the “value” attribute specifies the initial value of the input element.

1 Like