Hidden and Color Inputs
You'll learn how to include invisible form data and let users pick colors with a built-in color chooser.
What Are Hidden and Color Inputs?
HTML forms support two special input types that serve very different purposes: hidden fields for storing data the user doesn't see, and color pickers that let users visually select colors.
Hidden Input (type="hidden")
A hidden input exists in the form but doesn't appear on the page. It's like a secret note attached to your form submission that travels to the server without the user seeing it.
When to use hidden inputs:
- Tracking form versions or timestamps
- Storing user IDs or session tokens
- Passing along values the user shouldn't modify
<form action="/submit" method="POST">
<input type="hidden" name="formVersion" value="2.1">
<input type="hidden" name="userId" value="12345">
<label for="feedback">Your Feedback:</label>
<input type="text" id="feedback" name="feedback">
<button type="submit">Submit</button>
</form>
The hidden fields travel with the form data but remain invisible to users.
Color Input (type="color")
The color input displays a native color picker interface, letting users choose colors visually instead of typing hex codes.
<form>
<label for="brandColor">Choose Your Brand Color:</label>
<input type="color" id="brandColor" name="brandColor" value="#3498db">
</form>
The browser displays a clickable color swatch. When clicked, a color picker appears. The value is always a lowercase hex color code (e.g., #ff5733).
Key Takeaway: Use type="hidden" to include form data users don't need to see or modify, and type="color" to provide a user-friendly interface for color selection with native browser support.