HTML Text Tag

The Html <text> tag is employed to specify the one-line text field on a webpage. When we assign the value text to the type attribute of an input element as illustrated in the syntax below:

Syntax:

Example

<input type="text" name="firstname"/>

Example

Example

<html>

<head>

<title> Example of text field </title>

</head>

<body>

<form>

<br>  

<label>

Firstname:

</label> 

<input type="text" name="FN" size="5"/>  

<br>

<br>

<label>

Lastname:

</label>         

<input type="text" name="LN" size="10"/>

<br> 

<br>

<label>

Course:

</label>  

<input type="text" name="Course" size="15"/>  

<br> 

<br>

<label>

College:

</label>  

<input type="text" name="Course" size="20"/>            

</form>

</body>

</html>

Output:

Attributes of HTML Text Tag

1. Size

The size property is employed to specify the width of the text field. It allows for numerical values above zero. In case you omit defining this property, it will automatically default to 20. The syntax below illustrates the usage of this attribute:

Example

<input type="text" name="firstname" size="Any_numeric_value" />

2. Value

The value parameter is employed to specify the content that appears within the text box. The syntax below outlines the proper usage of this parameter:

Example

<input type="text" name="firstname" value=?Any_value? />

3. maxlength

The maxlength attribute is employed to specify a value that indicates the maximum number of characters that the input can accept. The syntax below illustrates how to utilize this attribute:

Example

<input type="text" name="firstname" maxlength="5" />

4. minlength

The maxlength attribute is employed to specify a maximum length for a value. This length indicates the minimum number of characters that the input can accept. The syntax below illustrates how to utilize this attribute:

Example

<input type="text" name="firstname" minlength="5" />

Browser Support

Element Chrome IE Firefox Opera Safari
<text> Yes Yes Yes Yes Yes

Input Required

This code uses input(). Please provide values below: