Careeroza
Input Types
Text, Password, Email, Number
Example
The type attribute changes how an input behaves. On phones, email, tel and number also show a matching keyboard:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body { font-family: Arial, sans-serif; }
label { display: block; margin-top: 8px; }
input, select, textarea { padding: 6px; margin-top: 4px; }
button, input[type=submit] { margin-top: 10px; padding: 6px 14px; }
</style>
</head>
<body>
<form>
<label>Username <input type="text" name="user"></label>
<label>Password <input type="password" name="pwd"></label>
<label>Email <input type="email" name="email" placeholder="[email protected]"></label>
<label>Age <input type="number" name="age" min="18" max="99"></label>
<label>Phone <input type="tel" name="phone"></label>
</form>
</body>
</html>Result
Radio Buttons and Checkboxes
Example
Radio buttons with the same name form a group: only one can be selected. Checkboxes allow any number:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body { font-family: Arial, sans-serif; }
label { display: block; margin-top: 8px; }
input, select, textarea { padding: 6px; margin-top: 4px; }
button, input[type=submit] { margin-top: 10px; padding: 6px 14px; }
</style>
</head>
<body>
<form>
<p>Favourite language:</p>
<label><input type="radio" name="lang" value="html" checked> HTML</label>
<label><input type="radio" name="lang" value="css"> CSS</label>
<label><input type="radio" name="lang" value="js"> JavaScript</label>
<p>I own a:</p>
<label><input type="checkbox" name="device" value="laptop" checked> Laptop</label>
<label><input type="checkbox" name="device" value="phone"> Phone</label>
</form>
</body>
</html>Result
Date, Color, Range, File
Example
Browsers provide ready-made pickers for many types:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body { font-family: Arial, sans-serif; }
label { display: block; margin-top: 8px; }
input, select, textarea { padding: 6px; margin-top: 4px; }
button, input[type=submit] { margin-top: 10px; padding: 6px 14px; }
</style>
</head>
<body>
<form>
<label>Birthday <input type="date" name="bday"></label>
<label>Favourite color <input type="color" name="color" value="#04aa6d"></label>
<label>Volume (0-10) <input type="range" name="vol" min="0" max="10"></label>
<label>Resume <input type="file" name="resume" accept=".pdf,.docx"></label>
</form>
</body>
</html>Result
All Input Types
| Type | Use |
|---|---|
text, password, email, tel, url, search | text entry |
number, range | numbers |
date, time, datetime-local, month, week | dates and times |
checkbox, radio | choices |
file, color, hidden | uploads, colors, hidden values |
submit, reset, button | buttons (prefer the <button> element) |