CHAPTER 36 · HTML

Specialised form controls: time, ranges, colours and files

Choose controls by the answer you need. Learn what their values mean, and separate selecting a file from uploading it.

Download example files (ZIP)

Start with the question, then choose a control

A college workshop might ask when a session should start, which month it belongs to and which notes to attach. These are different kinds of answers. A specialised input is a field designed for one kind of answer. It can offer a picker, a slider or a file chooser. The exact appearance depends on the browser and device.

Time, month, week and local date-time

Time is a clock time such as 16:30. Month is a year and month such as 2027-02. Week uses an ISO week-year and week number, such as 2027-W06. Week 1 is the week containing the first Thursday, so week-years can differ near New Year. Datetime-local combines a date and time, such as 2027-02-09T16:30, without a time zone.

A time zone tells us how a local clock relates to clocks elsewhere. A remote meeting needs an agreed zone; datetime-local alone does not tell a service whether 16:30 means India time or another location. Visible picker formats can differ from the value sent. Some browsers fall back to text for some types, so test intended devices and give visible format instructions when needed.

Ranges: an approximate preference

A range input is a slider for a numeric value. Min and max set its endpoints; step sets allowed increments. With min=1, max=5 and step=1, the stops are 1, 2, 3, 4 and 5. Give endpoints clear meanings. A slider is usually a poor choice for an exact account balance or a phone number.

The browser does not automatically print the current value in a separate sentence. A live number display needs additional behaviour, usually JavaScript. Inspect the submitted pace value in the saved example instead. A range already has a value before the reader moves it, so it is not a useful unanswered-question control.

Colour selection does not recolour the page

Type=color offers colour selection. This example uses a six-digit hexadecimal value: #2458a6. Each pair describes one colour channel. You do not need to memorise the code to try the picker. Newer colour features and picker interfaces vary; these exercises use the established simple format. Choosing a colour does not automatically recolour the page or check text readability.

File selection: each part explained

Type=file lets a person choose files from their device. Accept gives the chooser suggested types; .pdf,.txt requests PDF or text choices. Multiple permits more than one selected file. Neither proves that a file is safe, small enough or really the stated type. There is no standard input attribute that enforces a maximum file size.

A page cannot fill in an arbitrary local file path and silently collect that file. The browser may expose a privacy-protecting fake path rather than its real location. JavaScript can inspect selected files, but JavaScript is not required for a normal HTML upload form.

What a real upload needs

Selecting a file and sending it are separate actions. A normal upload form needs a real receiving address, method=post and enctype=multipart/form-data. Enctype describes how the form packages data. The receiving application must check permissions, actual file type, size and safe storage. HTTPS protects data in transit; POST alone does not encrypt it.

Our complete file-chooser example has no form or upload button. It does not pretend that a static result page can store an attachment. Build real upload handling with backend development later.

Other controls you may meet

Type=submit submits its form. Type=reset restores initial values and can discard work, so use it cautiously. Type=button has no built-in action. An image submit input sends click coordinates and needs alt text; an ordinary labelled button is easier for these lessons. A hidden input can carry data, but visitors can inspect or alter it. It cannot protect a secret.

Follow the idea

Choose by the answer
  1. 1Time or month: choose a calendar or clock value
  2. 2Range: an approximate bounded preference
  3. 3Colour: choose a colour value
  4. 4File: select; upload needs a receiving service

A picker is an entry tool, not a booking or storage service.

Complete program: planning-controls.html

Save this as planning-controls.html. Open it in your browser.

planning-controls.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Try Planning Controls</title>
  </head>
  <body>
    <h1>Plan an imaginary study session</h1>
    <p>Use fictional preferences. Keep form-result.html from Chapter 31 beside this file.</p>
    <form action="form-result.html" method="get">
      <p>
        <label for="session-time">Starting time (local clock)</label>
        <input type="time" id="session-time" name="start" value="16:30" />
      </p>
      <p>
        <label for="study-month">Study month</label>
        <input type="month" id="study-month" name="month" value="2027-02" />
      </p>
      <p>
        <label for="study-week">Study week</label>
        <input type="week" id="study-week" name="week" value="2027-W06" />
      </p>
      <p>
        <label for="meeting">Local meeting date and time (no time zone)</label>
        <input type="datetime-local" id="meeting" name="meeting" value="2027-02-09T16:30" />
      </p>
      <p>
        <label for="pace">Practice pace: 1 slow, 5 fast</label>
        <input type="range" id="pace" name="pace" min="1" max="5" step="1" value="3" />
      </p>
      <p>
        <label for="ink">Notebook colour</label>
        <input type="color" id="ink" name="ink" value="#2458a6" />
      </p>
      <button type="submit">Inspect planning values</button>
    </form>
  </body>
</html>
Browser previewDocument title: Try Planning Controls

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Form submission is disabled in this preview. Save the example and its result page locally to test submission. Use fictional practice values.

Expected result: six labelled controls and an Inspect button. In saved files, submission opens form-result.html with named values in the URL. The embedded preview blocks submission. No meeting is booked or preference stored. Changing the slider does not add a live number beside it.

Complete program: file-selection.html

Save this as file-selection.html. Open it in your browser.

file-selection.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Select a Local Practice File</title>
  </head>
  <body>
    <h1>Try a file chooser without uploading</h1>
    <p>This page only lets you select files. It has no form submission or upload service.</p>
    <p id="file-help">
      Use a harmless practice PDF or text file. The chooser hint is not a safety check.
    </p>
    <label for="notes-file">Practice notes (PDF or text; more than one allowed)</label>
    <input
      type="file"
      id="notes-file"
      name="notes"
      accept=".pdf,.txt"
      multiple
      aria-describedby="file-help"
    />
  </body>
</html>
Browser previewDocument title: Select a Local Practice File

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.

Expected result: a labelled chooser and visible instructions. Choose a harmless local file to see its name. Nothing is uploaded. Try selecting two harmless files where your chooser supports multiple selection.

Problem and solution

Problem: a student adds accept=".pdf" and says every selected file is now a safe PDF.

Solution: describe accept as a chooser hint. In a real service, check the received file and its size on the receiving side. In this exercise, practise selection only.

Common mistakes and useful tips

  • Do not call datetime-local a worldwide meeting time.
  • Do not expect a colour picker to apply a theme.
  • Do not use GET to upload file contents.
  • Explain range endpoints and test arrow keys.
  • Use harmless fictional practice files.

Practice questions

  1. Which control suits a month and year?
  2. Does datetime-local include a time zone?
  3. How many stops are in the example slider?
  4. Does accept guarantee a safe PDF?
  5. What does multiple do on a file input?
  6. Save both examples. Change the pace with arrow keys and select a harmless text file. What did not happen?
Check your practice answers
  1. Type=month; a value can be 2027-02.
  2. No. Agree or collect the zone separately for a remote meeting.
  3. Five: 1, 2, 3, 4 and 5.
  4. No. It guides selection; the receiver must check the actual file.
  5. It permits selecting more than one file where supported.
  6. No live range number, theme change, booking or upload is created by these examples.

Interview questions

Is JavaScript required for a normal file upload?

No. An HTML form can send files using POST and multipart/form-data to a real receiving application. That application must handle and check them.

Why does datetime-local need care?

It describes a local date and clock time without identifying a time zone. People in different zones can interpret it differently.

When is range useful?

For an approximate bounded preference. Use a numeric entry when an exact visible quantity is more suitable.

How do accept and file validation differ?

Accept suggests choices in the picker. Validation checks received files against actual rules; the hint can be bypassed.

Quick revision

  • Match the input to the answer.
  • Explain formats, limits and browser differences.
  • Selection does not mean upload.
  • A real service must check received data.