In the world of web development, creating user-friendly and interactive interfaces is crucial. HTML input forms are the backbone of user interaction, whether it’s a simple contact form or a complex registration process. The <input> tag empowers developers to create versatile and dynamic web forms, enabling users to input various types of data and interact with web applications. In this blog post, we will explore HTML Input Types and Attributes.
What is the HTML Input Element?
The HTML <input> element is used to display an input field where the user can enter data, such as text, numbers, dates, checkboxes, radio buttons, etc., and interact with the web applications. As an empty element, it does not have a closing tag.
The <input> element includes a range of attributes that control its behaviour and appearance.
<form> <label for="firstName">First name:</label><br> <input type="text" id="firstName" name="lastName"><br> <label for="lastName">Last name:</label><br> <input type="text" id="lastName" name="lastName"> </form>
The <label> element is used with the <input> element to define the title for it. <label> element’s “for” attribute and <input> element’s “id” attribute link each other.
Types of Input Element
Let’s explore the types of input element:
<input type="text">defines a single-line text field and allows users to enter single-line text such as names, email addresses, etc.
<label for="text">Text:</label> <input type="text" id="text" name="text">
<input type="number">defines a numeric field and allows users to enter numeric values such as age, weight etc. It also includes up and down arrows to increase or decrease the value.
<label for="number">Number:</label> <input type="number" id="number" name="number">
<input type="button" />defines a button that can be used to trigger javascript functions or any other actions without submitting the form.
<input type="button" value="Click Me!">
<input type="email" />defines an input field that allows users to enter their email addresses.
<label for="email-address">Email address:</label> <input type="email" id="email-address" name="email-address">
<input type="password" />defines a password input field that allows users to enter the password. It hides the characters entered by the user, to protect the user’s privacy.
<label for="password">Password:</label> <input type="password" id="password" name="password">
<input type="checkbox" />defines a checkbox that allows users to select one or more options from a list.
<input type="checkbox" id="option1" name="option1"> <label for="option1">One</label><br> <input type="checkbox" id="option2" name="option2"> <label for="option2">Two</label><br> <input type="checkbox" id="option3" name="option3"> <label for="option3">Three</label>
<input type="radio" />defines a radio button that allows users to select only one single option from a list.
<input type="radio" id="html" name="html" value="html" /> <label for="html">HTML</label> <input type="radio" id="css" name="css" value="css" /> <label for="css">CSS</label> <input type="radio" id="javascript" name="javascript" value="javascript" /> <label for="javascript">JavaScript</label>
<input type="tel" />defines an input field that allows the user to enter a telephone number.
<label for="phone-number">Phone number:</label>
<input type="tel" id="phone-number" name="phone-number" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}"><input type="search" />defines a single-line text field that allows users to enter their search queries.
<label for="search">Search</label> <input type="search" id="search" name="search">
<input type="file" />defines an input field that allows users to select a file to upload. It can be used to upload files such as images, videos, documents, audio, etc.
<label for="profile"> Profile: </label> <input type="file" id="profile" name="profile" accept="image/png, image/jpg" />
<input type="submit" />defines a button that allows the user to submit the form.
<input type="submit" value="Submit">
<input type="color" />defines a field that allows the user to select a colour.
<label for="color">Select Color</label> <input type="color" id="color" value="#2222eb">
<input type="date" />defines a field that allows users to select a date.
<label for="date">Date:</label> <input type="date" id="date">
<input type="datetime-local" />defines a field that allows the user to select a date and time, without time zone information.
<label for="datetime">Datetime:</label> <input type="datetime-local" id="datetime">
<input type="hidden" />defines an input field that is not visible to the user. It serves as a storage mechanism for sensitive information like session tokens or other data that must be included in form submissions but remain invisible and unmodifiable to the user.
<input type="hidden" value="5462">
<input type="image" />defines an image as a submit button.
<input type="image" value="Click me" src="click.jpg">
<input type="month" />defines an input field that allows the user to select month and year.
<label for="month">Month:</label> <input type="month" id="month">
<input type="range" />defines a field that allows the user to select a value within a range of values using a slider. The default range is 0 to 100, but it can be changed using themin,max, andstepattributes.
<label for="rate">Rate (between 0 and 10):</label> <input type="range" id="rate" name="rate" min="0" max="10">
<input type="reset" />defines a reset button that resets all form values to their default values.
<form> <label for="firstName">First name:</label><br> <input type="text" id="firstName" name="firstName"><br> <label for="lastName">Last name:</label><br> <input type="text" id="lastName" name="lastName"><br> <input type="submit" value="Submit"> <input type="reset"> </form>
<input type="time" />defines a field that allows users to select the time.
<label for="time">Time:</label> <input type="time" id="time">
<input type="url" />defines a field that allows the user to enter a URL.
<label for="url">Your website:</label> <input type="url" id="url" placeholder="https://shefali.dev" pattern="https://.*">
<input type="week" />defines a field that allows the user to select a week and year.
<label for="week">Week:</label> <input type="week" id="week">
HTML Input Attributes
Let’s explore the attributes of the input element:
acceptattribute specifies a filter for what file type the user can select to upload.
<label for="profile"> Profile: </label> <input type="file" id="profile" name="profile" accept="image/*" />
altattribute specifies an alternate text for the user if, for some reason, the image is not available.
<input type="image" value="Click me" src="click.jpg" alt="Click">
autocompleteattribute enables or disables the browser’s autocomplete feature for the input field.
<label for="email">Email:</label> <input type="email" id="email" name="email" autocomplete="off">
autofocusattribute specifies that an<input>element should automatically get focused when the page loads. It is a boolean attribute.
<form> <label for="firstName">First name:</label><br> <input type="text" id="firstName" name="firstName" autofocus><br> <label for="lastName">Last name:</label><br> <input type="text" id="lastName" name="lastName"><br> <input type="submit" value="Submit"> <input type="reset"> </form>
checkedattribute specifies that an<input>element must be checked when the page loads. It is a boolean attribute.
This can be used only on the<input type="checkbox" />and<input type="radio" />.
<input type="checkbox" name="checkbox1" id="checkbox1" checked> <label for="checkbox1">One</label><br> <input type="checkbox" name="checkbox2" id="checkbox2"> <label for="checkbox2">Two</label>
dirnameattribute enables the submission of the text direction of the input field.
<form> <label for="firstName">First name:</label> <input type="text" id="firstName" name="firstName" dirname="firstName.dir"> <input type="submit" value="Submit"> </form>
disabledattribute disables the input field, preventing user interaction.
<form> <label for="firstName">First name:</label><br> <input type="text" id="firstName" name="firstName"><br> <label for="lastName">Last name:</label><br> <input type="text" id="lastName" name="lastName" disabled><br> <input type="submit" value="Submit"> </form>
formactionattribute determines the destination URL where the input control will be processed upon form submission. This attribute overrides the action attribute of the<form>element.
Theformactionattribute is used with<input type="submit" />and<input type="image" />.
<form action="action_1.html"> <label for="firstName">First name:</label><br> <input type="text" id="firstName" name="firstName"><br> <label for="lastName">Last name:</label><br> <input type="text" id="lastName" name="lastName"><br> <input type="submit" value="Submit" formaction="action_2.html"> </form>
formmethodattribute defines the HTTP method for sending form-data. This attribute overrides themethodattribute of the<form>element.
Theformmethodattribute is used with<input type="submit" />and<input type="image" />.
<form action="action.html" method="get">
<label for="firstName">First name:</label><br>
<input type="text" id="firstName" name="firstName"><br>
<label for="lastName">Last name:</label><br>
<input type="text" id="lastName" name="lastName"><br>
<input type="submit" value="Submit" formmethod="post">
</form>formnovalidateattribute specifies that the form is not to be validated during submission. It is a boolean attribute. Theformnovalidateattribute overrides the novalidate attribute of the<form>element.
Theformnovalidateattribute is used with<input type="submit" />.
<form action="action.html">
<label for="firstName">First name:</label><br>
<input type="text" id="firstName" name="firstName"><br>
<label for="lastName">Last name:</label><br>
<input type="text" id="lastName" name="lastName"><br>
<input type="submit" value="Submit" formnovalidate>
</form>heightattribute specifies the height of the<input>element.
<form action="action.html"> <label for="firstName">First name:</label> <input type="text" id="firstName" name="firstName"><br> <label for="lastName">Last name:</label> <input type="text" id="lastName" name="lastName"><br> <input type="image" src="submit.png" width="50" height="50"> </form>
maxattribute specifies the maximum value for an<input>element. This is used with the following input types:number,range,date,datetime-local,month,timeandweek.
<label for="rate">Rate (between 0 and 10):</label> <input type="range" id="rate" name="rate" min="0" max="10">
maxlengthattribute specifies the maximum number of characters to allow in the<input>element.
<label for="name">Name:</label> <input type="text" id="name" name="name" maxlength="10">
minattribute specifies the minimum value for an<input>element. This is used with the following input types:number,range,date,datetime-local,month,timeandweek.
<label for="rate">Rate (between 0 and 10):</label> <input type="range" id="rate" name="rate" min="0" max="10">
minlengthattribute specifies the minimum number of characters to allow in the<input>element.
<label for="name">Name:</label> <input type="text" id="name" name="name" minlength="5">
multipleattribute is a boolean attribute and specifies that the user is allowed to enter more than one value in the<input>element.
Themultipleattribute is used with<input type="email" />and<input type="file" />.
<label for="files">Select files:</label> <input type="file" id="files" name="files" multiple>
nameattribute specifies the name of an<input>element.
<label for="name">Name:</label> <input type="text" id="name" name="name">
patternattribute specifies a pattern for the input value.
Thepatternattribute works with the following input types:text,date,search,url,tel,email, andpassword.
<label for="phone-number">Phone number:</label>
<input type="tel" id="phone-number" name="phone-number" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">placeholderattribute provides a sample value to guide users on what to input.
<label for="name">Name:</label> <input type="text" id="name" name="name" placeholder="Your name">
readonlyattribute is a boolean attribute and specifies that an input field is read-only.
<label for="country">Country</label> <input type="text" id="country" name="country" value="India" readonly>
requiredattribute ensures that the input field must be filled out before submitting the form.
<form> <label for="firstName">First name:</label> <input type="text" id="firstName" name="firstName" required><br> <label for="lastName">Last name:</label> <input type="text" id="lastName" name="lastName"><br> <label for="email">Email:</label> <input type="email" id="email" name="email" required><br> <input type="submit" value="Submit"> </form>
sizeattribute specifies the visible width, in characters, of an<input>element.
Thesizeattribute works with the following input types:text,search,tel,url,email, andpassword.
<form> <label for="firstName">First name:</label> <input type="text" id="firstName" name="firstName" size="25"><br> <label for="tel">Telephone number:</label> <input type="tel" id="tel" name="tel" maxlength="10" size="10"><br><br> <input type="submit" value="Submit"> </form>
srcattribute specifies the URL of the image. This is used only with<input type="image" />.
<input type="image" value="Click me" src="click.jpg">
stepattribute specifies the interval between numbers in an<input>element. This attribute works with the following input types:number,range,date,datetime-local,month,timeandweek.
<label for="rate">Rate (between 0 and 10):</label> <input type="range" id="rate" name="rate" min="0" max="10" step="2">
typeattribute specifies the type of an<input>element.
<input type="number" /> <input type="button" /> <input type="email" /> <input type="password" /> <input type="checkbox" />
valueattribute specifies the value of an<input>element.
<label for="country">Country</label> <input type="text" id="country" name="country" value="India">
widthattribute specifies the width of the<input>element.
<form action="action.html"> <label for="firstName">First name:</label> <input type="text" id="firstName" name="firstName"><br> <label for="lastName">Last name:</label> <input type="text" id="lastName" name="lastName"><br> <input type="image" src="submit.png" width="50" height="50"> </form>
That’s all for today!
If you’re new to web development, check out Learnify — my curated platform with beginner-friendly tutorials to help you learn web development step-by-step with examples and simple explanations.
If you enjoy my work and want to support what I do:
👉 Become a Patreon supporter
👉 Or buy me a coffeeEvery small gesture keeps me going! 💛
Follow me on X (Twitter) to get daily web development tips & insights.
Enjoyed reading? You may also find these articles helpful.
13 HTML Attributes You Should Know About
21 HTML Tips You Must Know About

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.