A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-input-typetext/ below:

HTML <input type="text"> - GeeksforGeeks

HTML <input type="text">

Last Updated : 11 Jul, 2025

HTML <input type="text"> is used to create a single-line text input field where users can enter textual data. It is commonly used in forms for capturing information like names, emails, or messages.

Syntax

<input type="text">

Attributes

Attribute Description name Specifies the name of the input element, used to identify form data after submission. value Specifies the default value of the input field. placeholder Provides a hint to the user of what can be entered in the input field. maxlength Defines the maximum number of characters allowed in the input field. required Indicates that the input field must be filled out before submitting the form. readonly Makes the input field read-only, preventing the user from modifying its value. disabled Disables the input field, making it uneditable and excluding it from form submission.

Example 1: We are using the <input type="text"> element to create text input fields for collecting the first and last names in a form.

html
<!DOCTYPE html>
<html>
  
<body>
    <h2>HTML &lt;input type="text"&gt;</h2>

    <form action="#">
        <label for="fname">First Name</label>
        <input type="text" id="fname">
        <br><br>

        <label for="lname">Last Name</label>
        <input type="text" id="lname">
    </form>
</body>

</html>

Output

Example 2: Text Input with Validation

HTML
<!DOCTYPE html>
<html>

<body>
    <form>
        <label for="email">Email:</label>
        <input type="text" id="email" 
               name="email" 
               placeholder="Enter your email" required>
        <br><br>
        <label for="name">Name:</label>
        <input type="text" id="name" 
               name="name"  required>
        <br><br>
        <input type="submit" value="Submit">
    </form>
</body>

</html>

Output

Supported Browsers

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4