search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
date: Let users pick a calendar date
color: Capture hex color values ​​with a native picker
range: Control numeric values ​​with a slider
Home Web Front-end H5 Tutorial How to Use the New Input Types in HTML5? (date, color, range)

How to Use the New Input Types in HTML5? (date, color, range)

Dec 31, 2025 am 03:12 AM

HTML5 adds three new input types: date, color, and range: date provides a localized date picker, and the value is in YYYY-MM-DD format; color returns a 7-digit lowercase hexadecimal color value and does not support transparency; range uses a slider to select a numerical range, and min/max needs to be set, which is often displayed in real time with output.

How to Use the New Input Types in HTML5? (date, color, range)

HTML5 introduced several new input types that simplify common user interface tasks—like picking dates, selecting colors, or adjusting values ​​on a slider—without needing JavaScript libraries or custom widgets. These inputs offer better semantics, built-in validation, and native UI controls that adapt to the device (eg, mobile date pickers).

date: Let users pick a calendar date

The date input renders a clean, localized date picker in most modern browsers. It expects the value in YYYY-MM-DD format (ISO 8601), which makes parsing and storing straightforward.

  • Use it like:
  • Add constraints with min , max , or value : eg, min="2024-01-01" blocks earlier dates
  • On unsupported browsers (like older Safari or IE), it gracefully falls back to a plain text field—so always validate server-side
  • JavaScript access is simple: input.value returns a string like "2024-07-15" ; no manual parsing needed

color: Capture hex color values ​​with a native picker

The color input gives users an intuitive color selector and always returns a lowercase 7-character hex string (eg, #ff6b35 ). It's ideal for themes, design tools, or customization forms.

  • Basic usage:
  • It doesn't support transparency (alpha) — only #rrggbb format
  • No min / max , but you can set a default value to preselect a color
  • Works well with real-time previews: listen to input or change events and update a preview element's background or border

range: Control numeric values ​​with a slider

The range input provides a horizontal slider for selecting a number within a defined interval. It's great for settings like volume, brightness, or rating inputs.

  • Required attributes: min , max , and optionally step (default is 1):
  • It shows no visible value by default—you'll usually pair it with an adjacent element updated via JavaScript
  • Example: bind input.value to an output tag using the input event so the display updates instantly as the user drags
  • Unlike number , range doesn't allow direct keyboard typing—only dragging or arrow keys (for accessibility)

These inputs reduce boilerplate, improve UX consistency, and work reliably across platforms when used with appropriate fallbacks and validation. They're not magic—but they do make everyday form interactions smoother and more accessible.

The above is the detailed content of How to Use the New Input Types in HTML5? (date, color, range). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)