menu

html - 3 Topics

HTML5 APIs

DEEP DIVE INTO

html

Topic:html input

menu

The<input> element in HTML is one of the most versatile and widely used form elements, allowing users to provide various types of input in web forms. It can create text input fields, checkboxes, radio buttons, file upload fields, and more. The type of input it represents depends on the type attribute. Here's how to use the <input> element and some examples of its usage:

html<input type="text" name="fieldName" value="Initial value">
  • type: Specifies the type of input element, such as text, password, checkbox, radio, file, email, number, and more.

  • name: Specifies the name of the input field, which is used when the form is submitted to identify the field's data.

  • value: Specifies an initial value for the input field.

Example:

html<input type="text" name="username" value="JohnDoe">

In this example, the <input> element creates a text input field named "username" with an initial value of "JohnDoe."

Common Use Cases:

  1. Text Input: To create single-line text input fields for users to enter information like names, emails, or search queries.

  2. Password Input: To create password input fields where characters are masked for security.

  3. Checkbox and Radio Buttons: To create checkboxes and radio buttons for users to select options in a list.

  4. File Upload: To allow users to upload files, such as images or documents.

  5. Number Input: To create fields for numeric input, like quantities or dates.

  6. Email Input: For capturing email addresses, with built-in validation for correct email format.

  7. Hidden Input: To store values that are not displayed to the user but can be used for form processing on the server.

Styling with CSS:

You can use CSS to style the appearance of input elements to match the design of your web page. This includes adjusting the size, font, color, borders, and other visual properties.

html<style>
  input[type="text"] {
    width: 200px;
    font-size: 16px;
    border: 1px solid #ccc;
  }
</style>
<input type="text" name="search" placeholder="Search...">

In this example, CSS rules are applied to style text input fields. They are given a specific width, font size, and border style.

The <input> element is a fundamental building block for creating forms on the web. It allows users to interact with web applications by providing input, and it can be customized and styled to match the design of your website. The various type attributes make it suitable for a wide range of input scenarios, from simple text entry to file uploads and more.

1280 x 720 px