Skip to content
techsnow

HTML Forms

Input Types

The <input> element changes completely depending on its type attribute. Choosing the right type gives users the right keyboard on phones and built-in validation for free.

TypeShowsExample
textSingle-line text boxName
emailText box that checks for an emailyou@example.com
passwordHidden characters••••••
numberNumber with up/down arrowsAge
telPhone keypad on mobile0300 1234567
urlChecks for a web addresshttps://...
searchSearch box with a clear buttonSearch...
date / timeDate or time pickerDate of birth
colorColour pickerTheme colour
rangeSliderVolume
fileFile chooserUpload CV
checkbox / radioTick boxes / single choiceCovered in their own lesson
hiddenNothing visibleIDs sent with the form

Example:

<input type="text" name="name" placeholder="Your name">
<input type="email" name="email" placeholder="you@example.com">
<input type="password" name="password" minlength="8">
<input type="number" name="age" min="5" max="100">
<input type="date" name="dob">
<input type="range" name="volume" min="0" max="10">
<input type="file" name="cv" accept=".pdf">

Useful input attributes

AttributePurpose
nameThe key the value is sent under. Required for the value to be submitted.
placeholderHint text shown when empty.
valueA starting value.
requiredThe form won't submit if it's empty.
disabled / readonlyCan't be used / can't be edited.
min, max, minlength, maxlengthLimits.
autofocusPuts the cursor here when the page loads.