HTML Hidden Inputs: Metadata and Trust Boundaries
Carry a record identifier
A hidden input contributes a named value without displaying an editable control. It is useful for identifying a record in an edit form. It can be inspected and changed in developer tools, so the server must check whether the user may edit the record.
<form> <input type="hidden" name="record" value="42"> <label> Title <input name="title" value="Draft"> </label></form>Only Title is visible, but record=42 is also in the form data.
Names and disabled values
A hidden input still needs a name for normal inclusion in form data. Disabled hidden controls are omitted, just like disabled text controls. The hidden state is not the same as the global hidden attribute: the latter hides an element visually but does not change its input type.
<form> <input type="hidden" name="category" value="books"> <input type="hidden" name="unused" value="1" disabled> <input type="hidden" value="no-name"></form>Only category=books is included.
Keep display and trust separate
Suppose an order form sends a product ID. The server should look up the price from trusted records instead of accepting a client-provided price. Hidden controls do not participate in normal constraint validation, and they cannot protect authorization.
<form> <input type="hidden" name="product" value="notebook-7"> <label> Quantity <input type="number" name="qty" min="1" value="2"> </label></form>The product ID and quantity are sent as data, not as proof of price or permission.
Common mistakes and practice
Never store secrets or authoritative permission flags in hidden fields. A server-generated anti-CSRF token can be carried in a hidden field, but protection depends on server verification and token handling, not invisibility. Keep real credentials out of examples.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Hidden Inputs: Metadata and Trust Boundaries — Knowledge Check
Apply the control concepts taught in this lesson.
Can a user change a hidden input?
Which hidden field is omitted?
Where should a product price be determined?
Does a hidden input without a name normally contribute a form entry?
What is a suitable use for a hidden field in an edit form?