Imagine asking for the booking date with a plain input type="text". One customer will write "12/12", another "12 December", another "Dec 12" and another "Saturday". The same thing happens with the phone number and the email address: everyone writes them their own way, and on a mobile you have to switch keyboards by hand to find the at sign or the numbers. HTML5 solved this problem with new, specialised input types: fields for email, phone, number, date, time, colour, search or file, which display the right control (a calendar, a time picker), adapt the mobile keyboard and send the data in a standard format. In this lesson you will meet them one by one, learn what each one sends and what happens in browsers that don't understand them. By the end, the booking form will ask for the email address, phone number, date, time and number of guests properly, and news.html will have its own search box.
Contents
- Why specialised types
- Email, phone and website:
email,telandurl - Numbers:
numberwithmin,maxandstep - Sliders:
range - Dates and times:
date,timeanddatetime-local - Months and weeks:
monthandweek - Colours:
color - Searches:
search - Files:
file - Adapted mobile keyboards
- Compatibility and fallback to text
- Project: email, phone, date, time and guests; news search
Why specialised types
All the types in this lesson are written in the same way as the ones you already know, changing only the type:
And they all still build a name=value pair on submission. What changes is what the browser does for you:
| Advantage | Example |
|---|---|
| A control suited to the data | A calendar for choosing the date, a colour picker |
| An adapted keyboard on mobile | A numeric keypad for the phone number, @ visible for the email |
| A standard submission format | The date always arrives as 2026-12-12, however the user writes it |
| Basic checking of the format | It won't let you submit an email address without an @ |
| More precise autofill | The browser offers your saved email address in the email field |
All this without a single line of JavaScript. And if a browser doesn't know a type, it treats it as text: the form still works.
Email, phone and website: email, tel and url
These three types look like an ordinary text field, but the browser knows what they contain.
<p>
<label for="email">Email</label>
<input type="email" id="email" name="email">
</p>
<p>
<label for="phone">Phone</label>
<input type="tel" id="phone" name="phone">
</p>
<p>
<label for="website">Your website or professional profile</label>
<input type="url" id="website" name="website">
</p>email
- On submission, the browser checks that the text looks like an email address (something,
@, something). If you typemarta.gmail.com, it will show a warning and will not submit. It is a format check, not an existence check:x@ypasses, even though that mailbox doesn't exist. - With the boolean attribute
multiple, it accepts several addresses separated by commas (useful, for example, for "invite your friends"). - On mobile, the keyboard puts
@and.within easy reach.
tel
- It doesn't check any format: phone numbers are written in a thousand ways (
+34 900 000 000,900000000,(900) 00 00 00), so the browser doesn't impose any. You will learn to require a format withpatternin Form Attributes and Validation. - Its great advantage is the phone keypad on mobile.
- Why not
numberfor a phone number? Because a phone number is not a quantity: you don't add it up, it can start with+or0, it contains spaces, and it makes no sense to "increase" it with arrows. The same applies to postcodes or card numbers.
url
- It checks that the text is an absolute URL, with its scheme:
https://thebluecup.exampleis valid;thebluecup.exampleis not (it lackshttps://). It is a good idea to tell the user with an example next to the field. - On mobile, the keyboard offers
/and.com.
Numbers: number with min, max and step
type="number" is for quantities: guests, units, years of experience…
<p>
<label for="quantity">Number of loaves</label>
<input type="number" id="quantity" name="quantity" min="1" max="10" step="1" value="1">
</p>- The browser shows arrows (on desktop) for going up and down, and only accepts numeric characters.
minandmax: the limits. The arrows won't go beyond them.step: the increment of the arrows and the permitted values.step="1"only allows whole numbers;step="0.5"allows 1, 1.5, 2…;step="any"allows any decimal. The default value is1.value: the initial value.
If the user types a number outside the limits (for example, 25), the browser will detect it on submission and show a warning. How that check works and how the warnings are displayed is the subject of Form Attributes and Validation.
A detail about format: even if a user in Spain types "1,5" and the browser displays it that way, the value is sent with a point: quantity=1.5. HTML5 types separate the presentation (according to the user's language) from the value (in a universal format). You will see this same principle with dates.
Sliders: range
range is a slider for choosing an approximate value within an interval, when the exact number matters little:
<p>
<label for="strength">How do you like your coffee? (1 = mild, 5 = strong)</label>
<input type="range" id="strength" name="strength" min="1" max="5" step="1" value="3">
</p>- It uses the same
min,maxandstepasnumber. By default, from 0 to 100. - It always sends a value: if the user doesn't touch it, the initial value is sent (or the midpoint if there is no
value). - The user doesn't see the number chosen, only the position. That is why it is suitable for ratings or intensities, and not for exact data such as the number of guests. In Labels and Grouping: label, fieldset, legend and datalist you will see the
outputelement, which can display the value.
Dates and times: date, time and datetime-local
These are the types that save the most work.
<p>
<label for="date">Date</label>
<input type="date" id="date" name="date">
</p>
<p>
<label for="time">Time</label>
<input type="time" id="time" name="time">
</p>
<p>
<label for="collection">Date and time to collect your order</label>
<input type="datetime-local" id="collection" name="collection">
</p>| Type | What the user chooses | How it looks (browser in British English) | What is sent |
|---|---|---|---|
date |
Day, month and year | 12/12/2026, with a calendar |
date=2026-12-12 |
time |
Hours and minutes | 13:30, with a picker |
time=13%3A30 (that is, 13:30) |
datetime-local |
Date and time together | 12/12/2026, 13:30 |
collection=2026-12-12T13%3A30 |
Note the important points:
- The presentation adapts to the user's language and region (a browser in US English would show
12/12/2026as month/day/year and the time as1:30 PM). - The value sent is always in the same international format (ISO 8601):
YYYY-MM-DDfor the date,HH:MMin 24-hour format for the time, joined by aTindatetime-local. The colons are encoded as%3Ain the URL. datetime-localis so called because it doesn't include a time zone: it is "local time". For a booking at a neighbourhood café, that is exactly what you want.
These types also accept min, max and step (for example, to disallow past dates or limit the times to opening hours). You will do this in Form Attributes and Validation. For now, using the type is enough.
Months and weeks: month and week
<input type="month" id="workshop-month" name="workshop_month">
<input type="week" id="week" name="week">monthsends the year and month:workshop_month=2027-01. Useful, for example, for choosing the month of a monthly workshop or a card expiry date.weeksends the year and the ISO week number:week=2027-W02.
Use them with caution: not all desktop browsers offer them (Firefox, for example, displays them as an ordinary text field). If the format matters, a more robust alternative is to combine two select elements (month and year) or to use date.
Colours: color
<p>
<label for="cake-colour">Main colour for your cake's decoration</label>
<input type="color" id="cake-colour" name="cake_colour" value="#1f4e79">
</p>- It displays a colour swatch which, when clicked, opens the system's colour picker.
- The value is always a 6-digit hexadecimal colour in lower case:
cake_colour=%231f4e79(the#is encoded as%23). - The initial
valuemust have that same format; if you don't set one, it is black (#000000). Here it uses the brand blue you defined for the tables.
Searches: search
It works like a text field, with a few details designed for searching:
- Many browsers show an "x" to clear the content.
- On mobile, the keyboard's Enter key becomes "Search" or a magnifying glass.
- It tells screen readers and the browser that it is a search field.
It doesn't search anything by itself: the form sends the term and it is the server that does the searching. The usual name is q (query).
Files: file
type="file" lets the user attach files from their device:
<p>
<label for="cake-photo">Photo of the cake you'd like (optional)</label>
<input type="file" id="cake-photo" name="cake_photo" accept="image/*">
</p>- It shows a button ("Choose File" or similar, depending on the browser) and the name of the chosen file.
acceptfilters the files offered by the picker. It can be:- A family of types:
image/*(any image),audio/*,video/*. - Specific extensions:
.pdf,.doc,.docx. - Exact types:
image/jpeg,image/png,image/webp.
- A family of types:
- On mobile,
accept="image/*"offers to take a photo with the camera as well as choosing from the gallery. - The boolean attribute
multipleallows several files to be chosen at once.
Two important warnings:
acceptis only a suggestion for the picker: the user can change the filter and choose any file. The server must always check the type and size of what it receives.- A file doesn't fit in a URL. With the form as you have written it so far, only the file's name would travel on submission (
cake_photo=cake.jpg), not its content. To really send files, the form needsmethod="post"and a specialenctypeattribute. You will learn how in Submitting Forms.
Adapted mobile keyboards
On a mobile, each type displays a different keyboard or control. This table sums up the usual behaviour (the details vary depending on the system and the keyboard installed):
| Type | Keyboard or control on mobile |
|---|---|
text |
Standard letter keyboard |
email |
Letters with @ and . within easy reach |
tel |
Phone keypad (numbers, +, *, #) |
url |
Letters with /, . and often .com |
number |
Numeric keypad (sometimes with sign and decimal point) |
search |
Letters, with the Enter key as "Search" |
date, time, datetime-local, month, week |
The system's native wheel or calendar, no keyboard |
range |
Touch slider |
color |
The system's colour picker |
file |
Menu: camera, gallery or files |
For special cases there is the inputmode attribute, which requests a keyboard without changing the field's type. For example, for a postcode (which is not a quantity, but contains only digits):
Its most useful values are numeric (digits only), decimal (digits and decimal separator), tel, email, url and search.
Try it without a mobile: in DevTools, turn on the device toolbar (the phone-and-tablet icon, or Ctrl + Shift + M) to simulate a phone screen. You will see the touch controls, though not the real keyboard. To check the real keyboard, open the page on your mobile: Live Server shows a local network address you can use if your computer and mobile are on the same Wi-Fi network.
Compatibility and fallback to text
What happens if a browser doesn't know a type? HTML's rule is reassuring: an unknown type behaves like text.
In a browser without support for week, the user will see an empty text field. They can type something and it will be sent; it simply won't have the special control or the guaranteed format. This is called graceful degradation: the page gets a little worse, but it doesn't break.
The current situation, broadly speaking:
| Types | Support in current browsers |
|---|---|
email, tel, url, number, search, range, color, file |
All modern browsers |
date, time, datetime-local |
All modern browsers (with controls that look different in each) |
month, week |
Incomplete on desktop (not in Firefox, for example) |
Practical consequences:
- Use HTML5 types without fear: in the worst case, they behave like text.
- When a format is essential, add a visible hint next to the field ("YYYY-MM-DD", "Starts with https://"), in case the special control doesn't appear.
- To check support for any type, you can consult reference sites such as MDN Web Docs or Can I use.
- The appearance of these controls (calendar, time picker) is drawn by the browser and varies between browsers and systems. Don't try to make them identical everywhere.
Project: email, phone, date, time and guests; news search
- The booking form
To confirm a booking, The Blue Cup needs to contact the customer and know when they are coming. In bookings.html, just after the name field, add the email and phone fields:
<p>
<label for="email">Email</label>
<input type="email" id="email" name="email">
</p>
<p>
<label for="phone">Phone</label>
<input type="tel" id="phone" name="phone">
</p>After the "What would you like to book?" group, add the date and time:
<p>
<label for="date">Date</label>
<input type="date" id="date" name="date">
</p>
<p>
<label for="time">Time</label>
<input type="time" id="time" name="time">
</p>Finally, revisit the previous lesson's decision about the number of guests. The café has decided to accept groups of up to 12 people online. A list of 12 options is starting to get long, and a number is quicker to type than to look for in a drop-down. Replace the select with:
<p>
<label for="guests">Number of guests</label>
<input type="number" id="guests" name="guests" min="1" max="12" step="1" value="2">
</p>min="1"andmax="12": the limits of the online service (larger groups book by phone).step="1": whole people only.value="2": the most common value, as in the earlierselect.
Both options were valid; the choice depends on the range. For 1–6, a select or even radio buttons would be just as good.
The order of the form is now: name, email, phone, booking type, date, time, guests, area, comments, privacy and button. In the next lesson you will organise it into groups.
Try it out with Live Server:
- Type an email address without an
@and submit: the browser will show a warning and won't submit. Correct it. - Choose a date in the calendar and a time, and submit. In the URL you will see
date=2026-12-12&time=13%3A30, regardless of how they were displayed on screen. - Open the DevTools device toolbar and watch how the date and time controls change.
- A search box in
news.html
news.htmlThe news keeps growing and it would be useful to be able to search it. Add this form just below the h1 in news.html:
<!-- News search: method="get" because a search can be saved and shared (see 05-06) -->
<form action="https://thebluecup.example/search" method="get">
<p>
<label for="search">Search the news</label>
<input type="search" id="search" name="q">
<button type="submit">Search</button>
</p>
</form>- The
actionis fictitious: the site doesn't have (and won't have in this course) a real search engine. name="q"follows the convention of search engines.- This form will use
getfor good, unlike the booking form. You will understand why in Submitting Forms.
Search for "bread-making workshop" and check the URL: https://thebluecup.example/search?q=bread-making+workshop.
Common Mistakes and Tips
- Using
numberfor phone numbers, postcodes or cards: they are not quantities. Usetel, ortextwithinputmode="numeric". - Expecting
telto check the format: it doesn't. That is whatpatternis for (coming up in the next lessons). - Writing the date in
valuein a local format:value="12/12/2026"doesn't work; the value is alwaysvalue="2026-12-12". - Thinking that
emailchecks that the address exists: it only checks the shape. Existence can only be verified by sending a confirmation email from the server. - Using
rangefor exact data: the user doesn't see the number. Keep it for approximate ratings. - Relying on
accept: it is a filter for the picker, not a protection. - Forgetting that a file needs
postandenctype: withget, only the file name travels. - Trying to make the calendar look the same in every browser: each one draws its own, and it is better that way: users recognise the one on their system.
- Tip: the correct type doesn't just help the user; it also improves autofill. In Form Attributes and Validation you will reinforce it with the
autocompleteattribute.
Exercises
Exercise 1. Choose the most suitable type for each data item and justify your choice: a) date of birth; b) postcode; c) number of croissants for an order (from 6 to 48, in sixes); d) supplier's website; e) rating from 1 to 10 of the last visit; f) CV in PDF for the "Work with us" section.
Exercise 2. Write the field for item c) of the previous exercise with its attributes. Which values will the browser accept?
Exercise 3. A user chooses 5 January 2027 at 9:15 in this field, with their browser set to British English. What will they see on screen and what will be sent? Would what is sent change if their browser were set to US English?
Solutions
Solution 1.
| Data item | Type | Why |
|---|---|---|
| a) Date of birth | date |
It is a date; the value arrives in the standard YYYY-MM-DD format |
| b) Postcode | text with inputmode="numeric" |
Digits only, but it is not a quantity (it can start with 0 and is not added up) |
| c) Croissants | number with min, max and step |
It is a quantity, with limits and an increment |
| d) Supplier's website | url |
It checks that it is an absolute URL and adapts the keyboard |
| e) Rating 1–10 | range (or number) |
An approximate value within an interval; with range, it is a good idea to display the number (you will see this with output) |
| f) CV | file with accept=".pdf" |
It attaches a file; it will need post and enctype |
Solution 2.
<label for="croissants">Number of croissants</label>
<input type="number" id="croissants" name="croissants" min="6" max="48" step="6" value="6">It accepts 6, 12, 18, 24, 30, 36, 42 and 48. step counts from min: the valid values are min plus multiples of step. If someone types 20, the browser will warn on submission that the value is not valid and suggest the nearest ones (18 or 24).
Solution 3.
- On screen (British English):
05/01/2027, 09:15(the exact format may vary slightly between browsers). - What is sent:
collection=2027-01-05T09%3A15, that is,2027-01-05T09:15. - In US English they would see
01/05/2027, 09:15 AM, but what is sent would be identical. That is precisely the advantage: the server doesn't have to guess whether "01/05" is 1 May or 5 January.
Conclusion
In this lesson you have met HTML5's input types: email, tel and url for contact details; number and range for quantities, with min, max and step; date, time, datetime-local, month and week for dates and times in a standard format; color, search and file, the last of these with accept, multiple and the warning that it will need enctype to send files. You have seen how each type adapts the mobile keyboard, how what is displayed is separated from what is sent, and that an unknown type falls back to text without breaking anything. The booking form now asks for the email address, phone number, date, time and number of guests, and the news page has a search box. However, the booking form has turned into a long string of fields with no apparent order, and the groups of radio buttons are still titled with a stray paragraph. In the next lesson, Labels and Grouping: label, fieldset, legend and datalist, you will learn to label each field properly and to organise the form into meaningful blocks.
HTML Course
Module 1: Introduction to HTML
- What Is HTML?
- Setting Up Your Work Environment
- Basic Structure of an HTML Document
- Tags, Elements and Attributes
- Creating Your First HTML Page
- File Organisation and Paths
Module 2: Text Formatting in HTML
- Headings and Paragraphs
- Text Formatting Tags
- Lists: Ordered, Unordered and Description Lists
- Block Quotes and Preformatted Text
- Block and Inline Elements: div and span
Module 3: Links and Media in HTML
- Creating Hyperlinks
- Special Links: Anchors, Email, Phone and Downloads
- Adding Images
- Embedding Videos
- Using the Audio Element
Module 4: Tables in HTML
- Basic Table Structure
- Table Head, Body and Foot
- Merging Cells: colspan and rowspan
- Accessible Tables: caption, scope and headers
- Styling Tables
Module 5: Forms in HTML
- Creating a Basic Form
- Form Elements: input, textarea and select
- HTML5 Input Types
- Labels and Grouping: label, fieldset, legend and datalist
- Form Attributes and Validation
- Submitting Forms
Module 6: HTML5 Semantic Elements
- Introduction to Semantic HTML
- header, nav and footer
- article, section and aside
- main and figure
- Other Semantic Elements: time, address, details and dialog
Module 7: Advanced HTML Techniques
- HTML Entities
- Using iframes
- Data Attributes
- Metadata: meta, SEO and Open Graph
- Microdata and Structured Data
- Graphics in HTML: SVG and canvas
Module 8: Integrating HTML and CSS
- Linking CSS to HTML
- Inline, Internal and External CSS
- Basic CSS Selectors
- The Box Model
- Styling HTML Elements
- Introduction to Layout with Flexbox and Grid
Module 9: Responsive Web Design
Module 10: Best Practices and Accessibility
- HTML Best Practices
- Validating HTML Code
- Web Accessibility Basics
- Using ARIA Roles and Attributes
- Accessibility Testing
- Performance and Resource Loading
