[HTML] input element

 <input>

How did I encounter this?

While practicing with <form></form>, I was required to use <input>.

Syntax

<input> is an HTML element used to create interactive form controls

  • type: to define the control's type

    • text – single-line text fields
    • password – masked input for sensitive data
    • email – validates email format in some browsers
    • number – numeric input with optional up/down controls
    • checkbox – on/off switches
    • radio – select one item from a group
    • submit – form submission button
    • reset – resets form fields to defaults
    • button – generic clickable button
    • date, time, datetime-local, range, color – specialized inputs (date picker, time picker, slider, color chooser, etc.)

  • name: to identify the form data key that gets sent to the server
    • value: the initial value for `name`
  • placeholder: a short hint displayed in the input field
  • required: to mark the field as mandatory
Example
<form action="/login" method="POST">
    <input type="text" name="username" placeholder="Enter your username" required>
    <input type="password" name="password" placeholder="Enter your password" required>
    <input type="submit" value="Login">
  </form>

When submitted, the form sends the username and password field to the /login endpoints

Comments