HTML Input Attributes
HTML
The <input>
tag is the most important input element and it has some attributes developer must know about.
Most common input Attributes
value
, placeholder
,
required
, readonly
, disabled
, size
,
max
, min
, maxlength
,
height
, width
, multiple
,
pattern
, step
, list
,
autofocus
, autocomplete
etc.
<input>
tag attribute value
value
attribute specifies the initial value of a input.
It is the default value for the input if the user do not type / change anything in the input.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
<meta charset="utf-8" />
</head>
<body>
<h2>Form Example</h2>
<form action="" method="get" class="form-example">
<div class="form-group">
<label for="name">Enter your name: </label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-group">
<label for="email">Enter your email: </label>
<input type="email" name="email" id="email" required>
</div>
<div class="form-group">
<input type="submit" value="Subscribe!">
</div>
</form>
</body>
</html>
Click on the "See output" button to see how it works.
<input>
tag attribute placeholder
placeholder
attribute specifies the initial value of a input.
It is the default value for the input if the user do not type / change anything in the input.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
<meta charset="utf-8" />
</head>
<body>
<h2>Form Example</h2>
<form action="" method="get" class="form-example">
<div class="form-group">
<label for="name">Enter your name: </label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-group">
<label for="email">Enter your email: </label>
<input type="email" name="email" id="email" required>
</div>
<div class="form-group">
<input type="submit" value="Subscribe!">
</div>
</form>
</body>
</html>
Click on the "See output" button to see how it works.
<input>
tag attribute required
required
attribute specifies the initial value of a input.
It is the default value for the input if the user do not type / change anything in the input.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
<meta charset="utf-8" />
</head>
<body>
<h2>Form Example</h2>
<form action="" method="get" class="form-example">
<div class="form-group">
<label for="name">Enter your name: </label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-group">
<label for="email">Enter your email: </label>
<input type="email" name="email" id="email" required>
</div>
<div class="form-group">
<input type="submit" value="Subscribe!">
</div>
</form>
</body>
</html>
Click on the "See output" button to see how it works.
<input>
tag attribute readonly
readonly
attribute specifies the initial value of a input.
It is the default value for the input if the user do not type / change anything in the input.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
<meta charset="utf-8" />
</head>
<body>
<h2>Form Example</h2>
<form action="" method="get" class="form-example">
<div class="form-group">
<label for="name">Enter your name: </label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-group">
<label for="email">Enter your email: </label>
<input type="email" name="email" id="email" required>
</div>
<div class="form-group">
<input type="submit" value="Subscribe!">
</div>
</form>
</body>
</html>
Click on the "See output" button to see how it works.