Problem Statement
Which input type is used for single-line text entry?
Explanation
The input type equals text is used for single-line text entry. This is one of the most common input types and is used for names, usernames, addresses, or any short text data. Text inputs allow users to enter any alphanumeric characters. By default, text inputs show as a single line with a cursor where users can type. You can control the visible width using the size attribute or CSS width property. The maxlength attribute limits how many characters users can enter. Text inputs are different from textarea, which allows multi-line text entry. Understanding different input types and when to use each one is fundamental to creating effective forms.
Code Solution
SolutionRead Only
<!-- Basic text input -->
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</form>
<!-- Text input with attributes -->
<form>
<label for="name">Full Name:</label>
<input type="text"
id="name"
name="fullname"
maxlength="50"
placeholder="Enter your name"
required>
</form>
<!-- Multiple text inputs -->
<form action="/submit" method="POST">
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="text" name="city" placeholder="City">
<button type="submit">Submit</button>
</form>Practice Sets
This question appears in the following practice sets:
