Table of Contents
" > type="password"
" > type="email"
" > type="tel"
" > type="url"
" > type="search"
2. Numeric and Range Input Types
" > type="number"
" > type="range"
" > type="date"
" > type="time"
" > type="datetime-local"
" > type="month"
" > type="week"
3. Selection and File Input Types
" > type="checkbox"
" > type="radio"
" > type="file"
4. Button and Hidden Input Types
" > type="button"
" > type="submit"
" > type="reset"
" > type="hidden"
5. Advanced and Specialized Input Types
" > type="color"
" > type="image"
Key Attributes Common to Many Input Types
Browser Support and Fallbacks
Summary of All HTML Input Types
Home Web Front-end HTML Tutorial HTML input types complete guide

HTML input types complete guide

Aug 19, 2025 pm 04:04 PM

Text input types include text, password, email, tel, url and search, which are used to process various text data and provide format verification; 2. Numerical and range input types such as number, range, date, time, datetime-local, month and week, which support input and limitations of digital and time data; 3. Selection and file input types include checkbox, radio and file, which are used for multiple selection, single selection and file upload respectively; 4. Button and hidden input types include button, submit, reset and hidden, which are used for form operations and storage of invisible data; 5. Advanced input types color and image provide color selection and image submission functions; all input types should be combined with placeholder, required, autofocus and other attributes to enhance user experience, and cooperate with server-side verification to ensure data security, ultimately improving the accessibility, availability and accuracy of the form.

HTML input types complete guide

HTML input types are essential for creating interactive forms on web pages. They define what kind of data users can enter, how it's displayed, and how it's validated. With the evolution of HTML5, input types have expanded significantly, offering better user experience and built-in validation. Below is a complete guide to all standard HTML input types, their uses, and key attributes.

HTML input types complete guide

1. Text Input Types

These are used for textual input and include several variations.

type="text"

  • The default input type.
  • Used for single-line text input.
  • Example:
     <input type="text" placeholder="Enter your name">

type="password"

  • Masks input characters (usually with dots or asterisks).
  • Automatically disables browser autofill in some cases.
  • Example:
     <input type="password" placeholder="Enter password">

type="email"

  • Validates input as a well-formed email address.
  • Mobile browsers may show an email-friendly keyboard.
  • Example:
     <input type="email" placeholder="name@example.com">

type="tel"

  • Designed for telephone numbers.
  • Triggers a numeric keypad on mobile devices.
  • No automatic validation unless used with pattern .
  • Example:
     <input type="tel" pattern="[0-9]{10}" placeholder="123-456-7890">

type="url"

  • Expects a valid URL (eg, https://example.com ).
  • Validates format on form submission.
  • Example:
     <input type="url" placeholder="https://www.example.com">

type="search"

  • Semantic for search fields.
  • May display a clear button in some browsers.
  • Styling can different slightly from text .
  • Example:
     <input type="search" placeholder="Search...">

2. Numeric and Range Input Types

Used for numbers, dates, and ranges.

HTML input types complete guide

type="number"

  • Accepts only numeric input.
  • Can include min , max , and step attributes.
  • Example:
     <input type="number" min="1" max="100" step="1" value="10">

type="range"

  • Slider control for selecting a value within a range.
  • Less precision than number , good for inputs like volume or rating.
  • Often used with <output> to display value.
  • Example:
     <input type="range" min="0" max="10" value="5" oninput="this.nextElementSibling.value = this.value">
    <output>5</output>

type="date"

  • Opens a date picker.
  • Format: YYYY-MM-DD .
  • Example:
     <input type="date">

type="time"

  • Select time (hours and minutes).
  • Supports min , max , and step .
  • Example:
     <input type="time" min="09:00" max="18:00">

type="datetime-local"

  • Combines date and time without timezone.
  • Example:
     <input type="datetime-local">

type="month"

  • Selects a month and year.
  • Format: YYYY-MM .
  • Example:
     <input type="month">

type="week"

  • Selects a week number and year.
  • Format: YYYY-W## .
  • Example:
     <input type="week">

3. Selection and File Input Types

For choosing from options or uploading files.

type="checkbox"

  • Allows multiple selections.
  • Use checked for default selection.
  • Example:
     <input type="checkbox" name="interest" value="coding"> Coding
    <input type="checkbox" name="interest" value="design" checked> Design

type="radio"

  • Allows one selection from a group.
  • All inputs in the group must share the same name .
  • Example:
     <input type="radio" name="gender" value="male"> Male
    <input type="radio" name="gender" value="female"> Female

type="file"

  • Lets users upload one or more files.
  • Use accept to restrict file types.
  • Add multiple for multiple files.
  • Example:
     <input type="file" accept="image/*" multiple>

4. Button and Hidden Input Types

For actions and storing invisible data.

HTML input types complete guide

type="button"

  • A clickable button with no default behavior.
  • Usually used with JavaScript.
  • Example:
     <input type="button" value="Click Me" onclick="alert(&#39;Hello&#39;)">

type="submit"

  • HTML input types complete guides the form to the server.
  • Default behavior: send form data.
  • Example:
     <input type="submit" value="HTML input types complete guide Form">

type="reset"

  • Resets all form fields to their initial values.
  • Use sparingly — can frustrate users.
  • Example:
     <input type="reset" value="Reset">

type="hidden"

  • Stores data not visible to users.
  • Often used to pass metadata (eg, user ID, session token).
  • Example:
     <input type="hidden" name="userId" value="12345">

5. Advanced and Specialized Input Types

Newer types with specific purposes.

type="color"

  • Opens a color picker.
  • Value is a lowercase hex color (eg, #ff0000 ).
  • Example:
     <input type="color" value="#ff0000">

type="image"

  • Acts as a submit button using an image.
  • Requires src and alt .
  • Sends click coordinates ( x , y ) with form data.
  • Example:
     <input type="image" src="submit.png" alt="HTML input types complete guide">

Key Attributes Common to Many Input Types

  • placeholder – Hint text showed when empty.
  • required – Makes field mandatory.
  • disabled – Disables input.
  • readonly – Prevents editing but submits value.
  • autofocus – Focuses input on page load.
  • autocomplete – Controls browser autofill (eg, on , off , name , email ).
  • pattern – Regular expression for validation (works with text , tel , email , etc.).

Browser Support and Fallbacks

Old browsers may not support newer HTML5 input types (like date , color , email ). When unsupported:

  • Browsers typically fall back to type="text" .
  • Always use server-side validation — never rely solely on client-side input types.

For maximum compatibility:

  • Use polyfills for date or color if needed.
  • Test forms across browsers.

Summary of All HTML Input Types

Type Purpose
text General text input
password Masked text
email Email address
tel Telephone number
url Web address
search Search query
number Numeric input
range Slider input
date Date picker
time Time input
datetime-local Date and time
month Month and year
week Week of the year
checkbox Multiple choice
radio Single choice
file File upload
button Clickable button
submit HTML input types complete guide form
reset Reset form
hidden Invisible data
color Color picker
image Image submit button

Using the right input type improves accessibility, usability, and validation. Always pair them with proper labels ( <label for="id"></label> ) and consider mobile UX. While HTML5 input types are powerful, remember to validate on the server side — client-side features can be bypassed.

Basically, choose the input type that best matches your data needs, and let the browser help you enforce correctness.

The above is the detailed content of HTML input types complete guide. 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

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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)

Hot Topics

PHP Tutorial
1582
276
Essential HTML Tags for Beginners Essential HTML Tags for Beginners Jul 27, 2025 am 03:45 AM

To get started with HTML quickly, you only need to master a few basic tags to build a web skeleton. 1. The page structure is essential, and, which is the root element, contains meta information, and is the content display area. 2. Use the title. The higher the level, the smaller the number. Use tags to segment the text to avoid skipping the level. 3. The link uses tags and matches the href attributes, and the image uses tags and contains src and alt attributes. 4. The list is divided into unordered lists and ordered lists. Each entry is represented and must be nested in the list. 5. Beginners don’t have to force memorize all tags. It is more efficient to write and check them while you are writing. Master the structure, text, links, pictures and lists to create basic web pages.

What is the name attribute in an input tag for? What is the name attribute in an input tag for? Jul 27, 2025 am 04:14 AM

Thenameattributeinaninputtagisusedtoidentifytheinputwhentheformissubmitted;itservesasthekeyinthekey-valuepairsenttotheserver,wheretheuser'sinputisthevalue.1.Whenaformissubmitted,thenameattributebecomesthekeyandtheinputvaluebecomesthevalueinthedatasen

Can you put a  tag inside another  tag? Can you put a tag inside another tag? Jul 27, 2025 am 04:15 AM

❌Youcannotnesttagsinsideanothertagbecauseit’sinvalidHTML;browsersautomaticallyclosethefirstbeforeopeningthenext,resultinginseparateparagraphs.✅Instead,useinlineelementslike,,orforstylingwithinaparagraph,orblockcontainerslikeortogroupmultipleparagraph

Shadow DOM Concepts and HTML Integration Shadow DOM Concepts and HTML Integration Jul 24, 2025 am 01:39 AM

ShadowDOM is a technology used in web component technology to create isolated DOM subtrees. 1. It allows the mount of an independent DOM structure on ordinary HTML elements, with its own styles and behaviors, and does not affect the main document; 2. Created through JavaScript, such as using the attachShadow method and setting the mode to open; 3. When used in combination with HTML, it has three major features: clear structure, style isolation and content projection (slot); 4. Notes include complex debugging, style scope control, performance overhead and framework compatibility issues. In short, ShadowDOM provides native encapsulation capabilities for building reusable and non-polluting UI components.

HTML `style` Tag: Inline vs. Internal CSS HTML `style` Tag: Inline vs. Internal CSS Jul 26, 2025 am 07:23 AM

The style placement method needs to be selected according to the scene. 1. Inline is suitable for temporary modification of single elements or dynamic JS control, such as the button color changes with operation; 2. Internal CSS is suitable for projects with few pages and simple structure, which is convenient for centralized management of styles, such as basic style settings of login pages; 3. Priority is given to reuse, maintenance and performance, and it is better to split external link CSS files for large projects.

How to embed a PDF document in HTML? How to embed a PDF document in HTML? Aug 01, 2025 am 06:52 AM

Using tags is the easiest and recommended method. The syntax is suitable for modern browsers to embed PDF directly; 2. Using tags can provide better control and backup content support, syntax is, and provides download links in tags as backup solutions when they are not supported; 3. It can be embedded through Google DocsViewer, but it is not recommended to use widely due to privacy and performance issues; 4. In order to improve the user experience, appropriate heights should be set, responsive sizes (such as height: 80vh) and PDF download links should be provided so that users can download and view them themselves.

How to create an unordered list in HTML? How to create an unordered list in HTML? Jul 30, 2025 am 04:50 AM

To create an HTML unordered list, you need to use a tag to define a list container. Each list item is wrapped with a tag, and the browser will automatically add bullets; 1. Create a list with a tag; 2. Each list item is defined with a tag; 3. The browser automatically generates default dot symbols; 4. Sublists can be implemented through nesting; 5. Use the list-style-type attribute of CSS to modify the symbol style, such as disc, circle, square, or none; use these tags correctly to generate a standard unordered list.

How to use the contenteditable attribute? How to use the contenteditable attribute? Jul 28, 2025 am 02:24 AM

ThecontenteditableattributemakesanyHTMLelementeditablebyaddingcontenteditable="true",allowinguserstodirectlymodifycontentinthebrowser.2.Itiscommonlyusedinrichtexteditors,note-takingapps,andin-placeeditinginterfaces,supportingelementslikediv

See all articles