HTML Form Attribute

In HTML there are various attributes available for <form> element which are given below:

The Value Attribute

The value attribute specifies the initial value for an input field.

Example
 
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title> HTML Form Value Attribute </title>
</head>
<body>
<form action=”#”>
First name:
<input type=”text” name=”firstname” value=”John”>
Last name:
<input type=”text” name=”lastname”>
</form>
</body>
</html>

Output

First name:  Last name: 

The Readonly Attribute

The readonly attribute specifies that the input field is read only that means the value of input field cannot be changed.

Example

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title> HTML Form Readonly Attribute </title>
</head>
<body>
<form action=”#”>
First name:
<input type=”text” name=”firstname” value =”John” readonly>
Last name:
<input type=”text” name=”lastname”>
</form>
</body>
</html>

Output

First name:  Last name: 

The Disabled Attribute

The disabled attribute specifies that the input field is disabled. You cannot make any modification on input field.

Example

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title> HTML Form Disabled Attribute </title>
</head>
<body>
<form action=”#”>
First name:
<input type=”text” name=”firstname” value =”John” disabled>
Last name:
<input type=”text” name=”lastname”>
</form>
</body>
</html>

Output

First name:  Last name: 

The Size Attribute

The size attribute specifies the size for the input field in character.

Example

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title> HTML Form Size Attribute </title>
</head>
<body>
<form action=”#”>
First name:
<input type=”text” name=”firstname” value=”John” size=”30″>
Last name:
<input type=”text” name=”lastname”>
</form>
</body>
</html>

Output

First name:  Last name: 

The maxlength Attribute

The maxlength attribute specifies the maximum length allowed for the input field.

Example

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title> HTML Form maxlength Attribute </title>
</head>
<body>
<form action=”#”>
First name:
<input type=”text” name=”firstname” maxlength=”10″>
Last name:
<input type=”text” name=”lastname”>
</form>
</body>
</html>

Output

First name:  Last name: 

Note : The maxlength attribute, will not accept more than the allowed number of characters in input field.

Leave a Comment

Your email address will not be published.