HTML Form Controls

 

Form Controls (Form Elements)

The form is made up of form controls that allow users to interact with the form. Each form control (e.g., <input>, <textarea>, <select>, <button>) has its own set of attributes.


1. <input> Element

The <input> tag is used for various types of form controls, such as text fields, checkboxes, radio buttons, etc.

Attribute

Description

Possible Values

Default

type

Specifies the type of input control to display.

text, password, checkbox, radio, submit, button, email, date, number, etc.

text (default)

name

Specifies the name of the input field, used to reference the data after form submission.

A string (e.g., username)

None

value

Specifies the initial value of the input field. For buttons, it specifies the button label.

A string (e.g., Submit, John)

None

placeholder

Provides a short hint that describes the expected value of the input field (shown inside the field).

A string (e.g., Enter your name)

None

required

Specifies that the input field must be filled out before submitting the form.

required (Boolean attribute)

None

disabled

Specifies that the input field is disabled and cannot be interacted with.

disabled (Boolean attribute)

None

readonly

Specifies that the input field is read-only, so users cannot change its value.

readonly (Boolean attribute)

None

maxlength

Specifies the maximum number of characters allowed in the input field.

An integer (e.g., 10)

None

min and max

Specifies the minimum and maximum values for numeric inputs.

Numeric values (e.g., 1, 100)

None

step

Specifies the interval between valid values for input fields of type number, range, etc.

A number (e.g., 5)

None

Example:

<input type="text" name="username" placeholder="Enter your username" required>

2. <textarea> Element

The <textarea> tag is used for multi-line text input.

Attribute

Description

Possible Values

Default

name

Specifies the name of the textarea.

A string (e.g., comments)

None

rows

Specifies the number of visible text lines in the textarea.

Integer value (e.g., 5)

None

cols

Specifies the visible width of the textarea (in characters).

Integer value (e.g., 50)

None

placeholder

Provides a hint for the user about the expected input.

A string (e.g., Enter comments)

None

required

Specifies that the textarea must be filled out before submitting the form.

required (Boolean attribute)

None

readonly

Specifies that the textarea is read-only and cannot be edited by the user.

readonly (Boolean attribute)

None

disabled

Specifies that the textarea is disabled and cannot be interacted with.

disabled (Boolean attribute)

None

Example:

<textarea name="message" rows="4" cols="50" placeholder="Write your message" required></textarea>

3. <select> Element

The <select> tag is used to create a dropdown menu.

Attribute

Description

Possible Values

Default

name

Specifies the name of the select element.

A string (e.g., country)

None

required

Specifies that the select field must be filled out before submitting the form.

required (Boolean attribute)

None

disabled

Specifies that the select element is disabled and cannot be interacted with.

disabled (Boolean attribute)

None

multiple

Specifies that multiple options can be selected.

multiple (Boolean attribute)

None

size

Specifies the number of visible options in the dropdown.

Integer value (e.g., 5)

None

Example:

<select name="country" required>

  <option value="USA">United States</option>

  <option value="Canada">Canada</option>

  <option value="Mexico">Mexico</option>

</select>

4. <button> Element

The <button> tag creates a clickable button.

Attribute

Description

Possible Values

Default

type

Specifies the type of button.

submit, reset, button

submit

name

Specifies the name of the button, which can be used to reference the data after form submission.

A string (e.g., submitBtn)

None

value

Specifies the value to be sent when the button is clicked.

A string (e.g., Submit)

None

disabled

Specifies that the button is disabled and cannot be clicked.

disabled (Boolean attribute)

None

Example:

<button type="submit" name="submit" value="Submit Form">Submit</button>

 

Comments

Popular posts from this blog

Introduction to Computer

History of Computer

Computer Generation