Recent Posts

Responsive Advertisement

html coding - Part 8 - HTML Forms.


HTML Forms

Forms are used to collect user input, such as text, selections, and file uploads.

Form Syntax

HTML
<form action="[Form Handler URL]" method="[GET/POST]">
	<label for="[Input ID]">Label</label>
	<input type="[Input Type]" id="[Input ID]" name="[Input Name]">
	<button type="submit">Submit</button>
</form>
Form Elements
  • <form>: Defines the form
  • <label>: Defines a label for an input
  • <input>: Defines an input field
  • <button>: Defines a submit button
Input Types
  • text: Single-line text input
  • password: Password input
  • email: Email input
  • checkbox: Checkbox input
  • radio: Radio button input
  • file: File upload input
  • submit: Submit button
Form Attributes
  • action: Specifies the form handler URL
  • method: Specifies the form submission method (GET or POST)
  • enctype: Specifies the encoding type for file uploads
Example Form
HTML
<form action="https://example.com/submit" method="POST">
	<label for="name">Name:</label>
	<input type="text" id="name" name="name">
	<label for="email">Email:</label>
	<input type="email" id="email" name="email">
	<button type="submit">Submit</button>
</form>
Form Best Practices
  • Use <label> elements to associate labels with inputs.
  • Use the name attribute to identify form inputs.
  • Use the action and method attributes to specify form submission.
  • Use the enctype attribute for file uploads.

Post a Comment

0 Comments


Comments

Ad Code

Responsive Advertisement