Course Content
HTML Forms
HTML forms are an essential part of web development and provide a way for users to input and submit data to a server. Forms allow users to enter data such as text, numbers, checkboxes, radio buttons, and more. When a user submits a form, the data is typically sent to a server for further processing.
0/6
HTML Graphics
HTML provides various ways to incorporate graphics into web pages.
0/2
HTML Media
HTML provides built-in support for embedding and displaying various types of media content on web pages.
0/5
HTML APIs
HTML APIs, also known as browser APIs or web APIs, are a set of interfaces and methods provided by web browsers to interact with and manipulate web content, access device features, and perform various tasks. These APIs are implemented in JavaScript and are accessible to web developers when creating web applications. Here are some commonly used HTML APIs:
0/5
HTML Examples
Creating a Simple Web Page, Adding Links and Images and more
0/4
HTML5 for Free | HTML5 – Unleashing the Potential of Web Development
About Lesson

HTML forms have several attributes that provide additional functionality and customization options. Here are some commonly used attributes for HTML forms:

  1. action: Specifies the URL or server-side script that will handle the form submission. For example: action="/submit-form".
  2. method: Defines the HTTP method to be used when submitting the form. The two most commonly used methods are:
  • GET: Sends the form data as parameters in the URL. This method is suitable for retrieving data and has limitations on the amount of data that can be sent.
  • POST: Sends the form data in the body of the HTTP request. This method is suitable for sending sensitive or large amounts of data.
  1. name: Provides a unique name for the form. This attribute is used to identify the form when processing the data on the server-side.
  2. target: Specifies where the response from the server should be displayed. The commonly used values are:
  • _blank: Opens the response in a new window or tab.
  • _self: Loads the response in the same window/tab as the form.
  • _parent: Loads the response in the parent frame of the current frame, if the form is embedded within frames.
  • _top: Loads the response in the full body of the window, if the form is embedded within frames.
  1. enctype: Specifies how the form data should be encoded and sent to the server. The two most common values are:
  • application/x-www-form-urlencoded: This is the default value. The form data is URL-encoded and included in the body of the HTTP request.
  • multipart/form-data: Used when uploading files through the form. The data is sent in multiple parts.
  1. autocomplete: Specifies whether the form should have autocomplete enabled or disabled for input fields. The values can be:
  • on: Enables autocomplete.
  • off: Disables autocomplete.
  1. novalidate: Prevents the browser from validating form inputs before submission. This attribute is useful when you want to handle validation on the server-side.

These are just a few examples of the attributes available for HTML forms. There are additional attributes and options that can be used to enhance form functionality, such as placeholder, disabled, readonly, pattern, and more. It’s important to refer to the HTML specification or documentation for a comprehensive list of form attributes and their usage.

<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form>

Here are examples of HTML form attributes: action, target, method, autocomplete, and novalidate.

  1. action attribute:
    The action attribute specifies the URL or server-side script that will handle the form submission.
<form action="/submit-form" method="post">
  <!-- form fields -->
</form>

In this example, when the form is submitted, the data will be sent to the server-side script located at /submit-form for processing.

  1. target attribute:
    The target attribute specifies where the response from the server should be displayed.
<form action="/submit-form" method="post" target="_blank">
  <!-- form fields -->
</form>

In this example, when the form is submitted, the response from the server will open in a new window or tab.

  1. method attribute:
    The method attribute defines the HTTP method to be used when submitting the form.
<form action="/submit-form" method="get">
  <!-- form fields -->
</form>

In this example, when the form is submitted, the data will be sent as parameters in the URL using the GET method.

  1. autocomplete attribute:
    The autocomplete attribute specifies whether the form should have autocomplete enabled or disabled.
<form action="/submit-form" method="post" autocomplete="off">
  <!-- form fields -->
</form>

In this example, autocomplete is disabled for the form, which means that the browser will not suggest or remember previously entered values for the form fields.

  1. novalidate attribute:
    The novalidate attribute prevents the browser from validating form inputs before submission.
<form action="/submit-form" method="post" novalidate>
  <!-- form fields -->
</form>

In this example, the browser will not perform validation on the form inputs before submitting the form. The validation can be handled on the server-side.

These examples demonstrate the usage of the action, target, method, autocomplete, and novalidate attributes in HTML forms. Remember that the actual behavior and functionality may vary depending on the server-side implementation and the browser being used.

List of All <form> Attributes

AttributeDescription
accept-charsetSpecifies the character encodings used for form submission
actionSpecifies where to send the form-data when a form is submitted
autocompleteSpecifies whether a form should have autocomplete on or off
enctypeSpecifies how the form-data should be encoded when submitting it to the server (only for method=”post”)
methodSpecifies the HTTP method to use when sending form-data
nameSpecifies the name of the form
novalidateSpecifies that the form should not be validated when submitted
relSpecifies the relationship between a linked resource and the current document
targetSpecifies where to display the response that is received after submitting the form
Join the conversation