
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - Input Attributes
The HTML tag provides different attributes to define its characteristics and behavior.
Input Attributes
The HTML input attributes define the characteristics and behavior of the element. These input attributes are used with the different types of input fields, such as text, email, password, date, number, and so forth. Note that the input element is used to create interactive controls for the web-based forms so that it can accept data from the user.
The element requires only an opening tag, and it will work only if we add it in between the
tags. In this tutorial, we are going to explore the attributes that are used with the
element.
The attributes of the element are as follows −
- type and name
- value
- size
- maxlength
- readonly
- disabled
- min and max
- accept and multiple
- placeholder
- required
- autofocus
- list
The 'type' and 'name' Attributes
The type
attribute indicates the type of input control, like text, password, email, and so on. The name
attribute of an input element assigns an identifier to the form control that enables the server to recognize and retrieve the value.
Example
The following HTML code illustrates the use of type
and name
attributes:
The type and name Attributes
The 'value' Attribute
The value
attribute is used to provide an initial value inside the input control.
Example
In the following example, we are creating two input fields with initial value as " first name..." and " last name...":
The value Attribute
The 'size' Attribute
The size
attribute allows you to specify the width of the text-input control in terms of characters. The default size is 20 characters.
Example
In this example, the size of the text-input control is set to 40:
The size Attribute
The 'maxlength' Attribute
The maxlength
attribute allows you to specify the maximum number of characters a user can enter into the text box.
Example
The following example demonstrates how to set the maxlength
of an input field:
The maxlength Attribute
The 'readonly' Attribute
The readonly
attribute of an input field indicates the field as read-only. Although the content of a read-only field cannot be altered, users can still select it and copy the text. Also, the value of a read-only field is included when the form is submitted.
Example
The following example shows the use of the readonly
attribute of the element:
The readonly Attribute
The 'disabled' Attribute
The disabled
attribute of an input field indicates the field as disabled. Unlike readonly, the value of a disabled field will not be included when the form is submitted.
Example
In this example, the field containing the organization name is marked as disabled:
The disabled Attribute
The 'min' and 'max' Attributes
The min
and max
attributes determine the minimum and maximum values, respectively, of an input field like number, date, week, and so on. If we use them together, they will allow users to enter an input within a predefined range.
Example
In the following example, we are mentioning the minimum working hours as 3 and maximum as 8 by using the min
and max
attributes:
The min and max Attribute
The 'accept' and 'multiple' Attributes
The accept
attribute specifies the types of files that the server will take in. If we use the multiple
attribute, it will allow the users to upload more than one file.
Example
The following HTML code can accept multiple image files:
The accept and multiple Attributes
The 'placeholder' Attribute
The placeholder
attribute of an input field, like text, search, and email, briefly outlines the desired value of the field. Its predefined value is displayed in the input field until the user begins to enter their own value.
Example
In the following example, we are using the placeholder
attribute for the email input field:
The placeholder Attribute
The 'required' Attribute
The required
attribute in an input field like text, search, password, and email signifies that the field must contain some values for the form to be successfully submitted. In other words, it indicates the mandatory field.
Example
The following example illustrates the use of the required
attribute. Without filling the mandatory fields, users will not be able to submit the form:
The required Attribute
The 'autofocus' Attribute
The autofocus
attribute in an input field ensures that the field must be selected automatically once the webpage loads completely. It implies that the cursor will be positioned to the specified input field. In cases where multiple elements use the autofocus
attribute, only the first element will acquire the focus.
Example
Following is the example of the autofocus
attribute:
The autofocus Attribute
The 'list' Attribute
The list
attribute defines a set of predefined options for an element, which are defined within a
element. The
element uses a specific string as an ID to create a link to the corresponding
element.
Example
In this example, we are creating a list of cities with the help of the list
attribute:
The list Attribute