input Elements in html

input Elements in html

what is the Input elements?

  • the <input> HTML elements is used to create interactive controles for web-based forms in order to accept data from the user, a wide variety of types of input data and controles widget are available

  • An input element is an HTML element that provides a field for data insertion. It is a self-closing tag with quite a few attributes associated with it. Currently, there are 23 input types available with different functions. It is usually always identified with the label element, as they go hand in hand in form pages.

the <input> element is one of the most powerful and complex in all of html due to the sheer number of combinations of input types and attributes.

input types

Text

  1. Reiterating from above, this is the default attribute value for the input element. It defines a single-line text field, that is, one without line breaks. Therefore, the text will continue in one line to any length unless there is a maximum value established. Below is a typical example of one of the components of a sign-up page.

Submit

The submit type is self-explanatory as it simply displays a button specifically for submission. It is usually enabled after a user has filled the other input types with relevant data. Additionally, the text displayed on the button for providing context on the form's purpose is customizable with the "value" attribute, like so

<input type="submit" value="Sign Up">

Password

The password input type creates a password field where sensitive information, such as a password, can be entered securely. The characters entered into this field will be masked with asterisks or dots, hiding the actual password entered by the user. Consequently, it helps prevent prying eyes from seeing the password, providing an added layer of security.

 <label for="pwd">Password </label>
  <input type="password" id="pwd">

Email

The Email input type creates a field specifically for entering an Email address. This input type is often validated to ensure the entered Email is in the correct format. Without added attributes, it could easily pass for text type input.

  <label for="email">Email </label>
  <input type="email" id="email">

Number

The number input type defines a field, particularly for entering a numerical value. Up and down arrows to increase or decrease the value follow after the data field. It is displayed below by the "Age" label.

  <label for="num"> Age </label>
  <input type="number" id="num">

CheckBox

The checkbox input type displays a toggleable on/off control for a single option in a form. Occasionally, it represents multiple options where the user can select one or more options. An example of its use case is in a "terms and conditions" acceptance section of a form, like so

 <label for="tandc"> </label>
  <input type="checkbox" id="tandc">
    <p> I agree with the Terms and Conditions</p>
  </div>

Radio

The radio input type defines a toggleable on/off control for a group of mutually exclusive options in a form. Only one option in the group can be selected at a time, but not by default. Although, for the radios to function as a group, they all have to contain a name attribute and share the same value.

<div class="gender">
    <h2>Gender</h2>
    <input type="radio" id="gender" name="gender"> 
        <label for="gender">Male </label> <br>
      <input type="radio" id="gender" name="gender"> 
        <label for="gender"> Female</label> <br>
      <input type="radio" id="gender" name="gender">
        <label for="gender">Prefer not to respond
</label> <br>
  </div>

Date

The date input type defines a field for selecting a date (year, month, and day). Depending on the user's device and browser, a date picker calendar will be displayed, making it easier for the user to choose a date. Additionally, the format of the date returned is controllable using the "min" and "max" attributes.

<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">

Image

The image input type creates an image as a submit button. When the user clicks on the image, the form it is associated with is submitted. The source of the image is specified using the "src" attribute.

Button

The button type creates a clickable button on a form. It is different from the submit type in the case of automatic form submission, but it can work hand in hand with JavaScript to create dynamic behavior. The text displayed on the button can be customized using the "value" attribute.

<input type="button" value="Click me" onclick="msg()">

Color

The color type creates a color picker control on a form, which allows users to select a color. This type is supported in modern browsers and provides a graphical interface for color selection. The default value is #000000, a hex code for the color black.

<label for="favcolor">Select your favorite color:</label>
<input type="color" id="favcolor" name="favcolor" value="#ff0000">

File

The file type creates a file input control on a form, allowing users to select a file for upload. The form performs specific actions, i.e., sending the file to a server, with the selected file information. The file type also allows multiple files selection at once by setting the "multiple" attribute.

<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">

Conclusion

The input types in HTML provide a way to create and present different types of form fields to users. Each input type serves a specific purpose and offers a unique user experience. By utilizing these input types in your forms, you can ensure that users can input the correct data type, leading to more accurate and efficient data collection.