HTML Tutorial

HTML Input Types

type switches the control: text, email, number, date, checkbox, radio, file, and more.

One tag, many controls

<input> changes shape with type. The attribute does three things at once: it picks the widget (a date picker, a checkbox, a file button), it hints the keyboard on a phone, and it lets the browser refuse a value that cannot possibly be right — an email without an@, a number outside min and max.

If you omit type, you get text. Write the type anyway. The next person reading the file should not have to guess.

text, email, number, date

These four cover most “type a value” fields. Email and number look like text on a desktop, then grow a useful keyboard and built-in format check on a phone. Date usually opens a calendar widget.

Example

<form action="#" method="get">
  <label for="name">Name</label>
  <input id="name" name="name" type="text">

  <label for="email">Email</label>
  <input id="email" name="email" type="email">

  <label for="loaves">Loaves</label>
  <input id="loaves" name="loaves" type="number">

  <label for="pickup">Pickup date</label>
  <input id="pickup" name="pickup" type="date">

  <p><button type="submit">Send</button></p>
</form>

type="email" expects an @. type="number" is for actual quantities, not postal codes or phone numbers — those can start with zero and are better as text.type="date" submits as YYYY-MM-DD even if the widget shows a local format.

checkbox and radio

A checkbox is on or off. Each checkbox has its own name unless you want several boxes to submit as one group of values. A radio button is a single choice from a set. Radios that belong togethermust share the same name. Different names means they do not deselect each other.

Example

<form action="#" method="get">
  <fieldset>
    <legend>Crust</legend>
    <label><input type="radio" name="crust" value="pale"> Pale</label>
    <label><input type="radio" name="crust" value="dark" checked> Dark</label>
  </fieldset>

  <fieldset>
    <legend>Extras</legend>
    <label><input type="checkbox" name="seeds" value="yes"> Seeds</label>
    <label><input type="checkbox" name="sliced" value="yes"> Sliced</label>
  </fieldset>

  <button type="submit">Add</button>
</form>

Unchecked boxes and radios send nothing. Checked ones send their value, or the wordon if you omitted value. Set value so the server receives a word you chose. checked marks the starting state.

password, file, color, range

Password masks the characters. File opens a picker — remember POST andenctype="multipart/form-data" on the form if you will actually upload. Color offers a swatch. Range is a slider; pair it with min, max, and a visible number so the value is not a secret.

Example

<form action="#" method="post" enctype="multipart/form-data">
  <label for="pin">Password</label>
  <input id="pin" name="pin" type="password">

  <label for="photo">Label photo</label>
  <input id="photo" name="photo" type="file">

  <label for="wrap">Wrapper color</label>
  <input id="wrap" name="wrap" type="color" value="#9a3412">

  <label for="toast">Toast level</label>
  <input id="toast" name="toast" type="range" min="1" max="5" value="3">

  <p><button type="submit">Save</button></p>
</form>

type="password" hides the screen. It does not encrypt anything. Submit passwords withmethod="post" over HTTPS on a real site. Never put a password in a GET URL.

A table of common types

typeControlTypical use
textOne-line fieldNames, titles, postal codes
emailEmail fieldAddresses the browser can format-check
numberNumeric field / stepperCounts and quantities
dateDate pickerDays, submitted as YYYY-MM-DD
checkboxTick boxIndependent yes/no extras
radioRound choiceOne option in a group that shares name
passwordMasked fieldSecrets; still send with POST
fileFile pickerUploads; needs multipart POST
colorColor wellA hex color such as #9a3412
rangeSliderA number in a min/max span

Other types you will meet later include url, tel, search,time, hidden, and submit. Browsers that do not know a type fall back to a text field, so the form still works.

Pick the type the data deserves

  • If the value is a quantity, use number or range, not text.
  • If exactly one option must win, use radios with the same name, not a pile of checkboxes.
  • If the user is attaching a file, use file and multipart POST. A text field named “file” will not open a picker.
  • If you only need to hide characters, use password. That is display, not security by itself.

Try the examples in /html/try on a narrow preview. Email should offer an @-friendly keyboard on a phone. Date should not be a free-typed guess if the browser has a calendar.

What to remember

  • type chooses the widget, the mobile keyboard, and some built-in checking.
  • Radios in one question share one name. Checkboxes are independent unless you group them on purpose.
  • file needs POST plus enctype="multipart/form-data". password still uses POST.
  • Unknown types fall back to text. Known types still need a name to be submitted.

Next: input attributes — required, placeholder, min, max, pattern, and the rest of the constraints.

Worked examples

The short listings above show the tag in isolation. These pages use the same markup on documents you would actually publish: a lab report, a clinic form, a timetable, a weather card.

HTML does not calculate. It names the pieces so a browser, a screen reader, and a search engine can tell a heading from a paragraph. The numbers below are classroom values — the same Ohm, pH, and pulse figures as the C track — now sitting in real page structure.

Preview them in the HTML editor at /html/try. Change a heading or a number and watch the page, not a print log.

Biology

The right keypad for the job

type switches the control and the mobile keyboard. email, tel, url, date, number, and search are not decorations. They change validation and the keypad.

password hides glyphs. It does not encrypt. HTTPS is what protects the wire.

Example

<label>Email <input type="email" name="email" placeholder="you@clinic.test"></label>
<label>Visit <input type="date" name="day"></label>
<label>Mass / kg <input type="number" name="kg" min="0" step="0.1"></label>

Physics

A range for a current limit

range is a slider. Always show the number nearby; sliders are hard to set precisely. min and max are the legal band, like a fuse rating.

Example

<label>Limit / A
  <input type="range" name="limit" min="0" max="1" step="0.05" value="0.5">
</label>
<p>Default trip at 0.50 A</p>

FAQ: HTML Input Types

Common questions about this page.

What is the StudyGrid HTML tutorial?

The StudyGrid HTML tutorial is a full beginner track: tags, headings, links, images, tables, layout, forms, and media. Each chapter has copy-and-run examples.

Should I run html input types examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn html input types in this HTML HTML lesson (HTML Input Types).

Is the HTML editor the same as Try Python?

No. Try HTML is a live page preview at /html/try. Try Python stays at /try and runs Python. HTML lessons never open the Python editor.

Do I need to install anything to learn HTML?

No. Open a chapter, click Try it in HTML, and the page preview updates in the browser. You can also download a .html file and open it locally.

Where should I start the HTML tutorial?

Start at HTML Intro, then Basic, Elements, and Attributes. After the first document, continue to headings, links, and forms. Use Next at the bottom of each chapter.

Is the HTML tutorial free?

Yes. The HTML studio on StudyGrid (studygrid.in) is free: dashboard, chapters, and the live preview editor.