1. <form> Element
Purpose: The <form> element is the container for all form elements. It defines how form data is sent when the form is submitted.
Attributes:
action: Specifies the URL where the form data will be sent when the form is submitted.method: Defines the HTTP method (GET,POST, etc.) used for submitting the form data.enctype: Specifies the encoding type for form data. Commonly used for file uploads withmultipart/form-data.target: Specifies where to display the response received after submitting the form (e.g.,_self,_blank).
2. <label> Element
Purpose: The <label> element is used to define a label for an input element, providing a clickable area for input fields.
Attributes:
for: Associates the label with a specific input element. ==The value should match theidof the input it labels.==- Example:
<label for="username">Username:</label>labels the input field withid="username".
- Example:
3. <input> Element
Purpose: The <input> element is used to create various types of input fields within a form.
Attributes:
type: Specifies the type of input field. Common values include:text: A single-line text field.password: A password field where input is hidden.email: A field for email addresses, with built-in validation.number: A field for numerical input.file: A field for file uploads.submit: A button to submit the form.checkbox: A checkbox that can be toggled on or off.radio: A radio button, used in groups for single-option selections.
name: Assigns a name to the input field, which is used as the key in the form data when it is submitted.id: Provides a unique identifier for the input field. ==This is necessary to associate a<label>with an input field using theforattribute.==value: Defines the default value of the input field. Forsubmitbuttons, it defines the text displayed on the button.placeholder: Provides a hint to the user about what to enter in the input field.required: Makes the input field mandatory before form submission.disabled: Disables the input field, preventing user interaction and submission of its value.
4. <textarea> Element
Purpose: The <textarea> element is used to create a multi-line text input field.
Attributes:
rows: Specifies the number of visible text lines.cols: Defines the visible width of the textarea.name: Assigns a name to the textarea for form data submission.
5. <select> Element
Purpose: The <select> element creates a drop-down list for selecting one or more options.
Attributes:
name: Defines the name for the select element in the form data.multiple: Allows the user to select multiple options.<option>: Child elements of<select>, representing each option in the drop-down list.value: The value sent with the form data when an option is selected.selected: Pre-selects the option when the form is loaded.
6. <button> Element
Purpose: The <button> element creates a clickable button, which can be used for form submission or other purposes like running JavaScript.
Attributes:
type: Defines the button’s behavior.submit: Submits the form data.button: A general-purpose button, usually associated with JavaScript actions.reset: Resets all form fields to their initial values.
name: The name of the button, useful if the button’s action needs to be captured in form data.value: The value sent with the form data when the button is clicked.
7. <fieldset> Element
Purpose: The <fieldset> element groups related elements within a form, making it easier to organize and manage complex forms.
Attributes:
disabled: Disables all form controls within the fieldset.name: Allows you to group and name related form controls together.<legend>: A child element of<fieldset>used to provide a caption for the group.
8. Form Submission Control
<input type="submit">and<button type="submit">:- Triggers the form submission, sending the data to the server as specified in the
actionattribute of the form. - The
valueattribute defines the text displayed on the submit button.
- Triggers the form submission, sending the data to the server as specified in the
9. Special Attributes
autocomplete: Suggests previous entries based on the user’s input history. Can be set toonoroff.novalidate: Disables the built-in form validation on submission, allowing custom validation logic to be applied via JavaScript.formaction(in<input>or<button>):- Overrides the form’s
actionattribute, allowing different submit buttons to direct the form data to different URLs.
- Overrides the form’s