HTML Course 9.5 – Range, Color and Other Controls
HTML5 introduced new input types to handle specialized controls: range, color and file. These simplify user interaction and reduce the need for custom scripts or plugins. Below is an in-depth exploration of each.
1. Input type=’range’
The <input type='range'> element renders as a slider allowing users to select a numeric value in a given interval.
| Attribute | Description |
|---|---|
| min | Minimum allowed value (default: 0) |
| max | Maximum allowed value (default: 100) |
| step | Increment step (default: 1). Can be decimals. |
| value | Initial slider value |
| list | References a <datalist> of suggested tick marks |
Basic slider example:
Slider with visible tick marks via <datalist>:
Slider that updates its numeric display with JavaScript:
100%
2. Input type=’color’
The <input type='color'> control opens a color picker UI. The value is a hexadecimal RGB string (#rrggbb).
| Attribute | Description |
|---|---|
| value | Initial color in #rrggbb format |
| list | References a <datalist> of predefined colors (no native dropdown UI) |
Basic color picker example:
Color picker updating background color live:
3. Input type=’file’
The <input type='file'> element allows selection of one or more files from the user’s device for upload or processing.
| Attribute | Description |
|---|---|
| accept | Comma-separated list of MIME types or file extensions (e.g. image/*, .pdf) |
| multiple | Allows selecting multiple files (boolean) |
| capture | Hints to use camera/microphone on mobile ('user' or 'environment') |
Single file upload:
Multiple image upload with accept filter:
Capture photo from device camera on mobile:
Summary
The range, color and file input types provide rich, native controls for sliders, color pickers and file selectors. Their built-in attributes (min, max, step, accept, multiple, etc.) allow fine-tuned behavior without heavy JavaScript or external libraries. Experiment with <datalist> for suggestions and harness minimal scripts for live feedback to create a polished user experience.
Leave a Reply
You must be logged in to post a comment.