HTML FORM ATTRIBUTES

HTML form attributes are special properties added to the <form> tag to control how form data is submitted and processed.

Common HTML Form Attributes

AttributeDescription
actionSpecifies the URL where form data is sent after submission.
methodDefines the HTTP method used to send data (GET or POST).
targetSpecifies where to display the response after submission.
enctypeSpecifies how form data should be encoded when sent to the server.
autocompleteEnables or disables browser auto-completion.
novalidateDisables built-in form validation.
accept-charsetSpecifies the character encoding used for form submission.
nameAssigns a name to the form.

1. action

Defines the destination URL for submitted data.

<form action="/submit-form">

2. method

Specifies how data is sent.

<form action="/submit-form" method="post">

Values:

  • get – Appends data to the URL.
  • post – Sends data in the request body.

3. target

Specifies where to open the server response.

<form action="/submit-form" target="_blank">

Common values:

  • _self (default)
  • _blank
  • _parent
  • _top

4. enctype

Used with method="post".

<form action="/upload" method="post"
enctype="multipart/form-data">

Values:

  • application/x-www-form-urlencoded (default)
  • multipart/form-data (for file uploads)
  • text/plain

5. autocomplete

Controls browser autofill.

<form autocomplete="on">

or

<form autocomplete="off">

6. novalidate

Disables HTML5 validation.

<form novalidate>

7. accept-charset

Specifies character encoding.

<form accept-charset="UTF-8">

8. name

Assigns a name to the form.

<form name="registrationForm">

Complete Example

<form action="/register"
method="post"
target="_self"
enctype="multipart/form-data"
autocomplete="on"
accept-charset="UTF-8"
name="registrationForm">

<label>Name:</label>
<input type="text" name="username">

<label>Photo:</label>
<input type="file" name="photo">

<button type="submit">Submit</button>
</form>

This form sends user data to /register using the POST method, allows file uploads, uses UTF-8 encoding, and enables browser autocomplete.

Comments

Popular posts from this blog

HTML | HTML INTRODUCTION

HTML ELEMENTS

HTML RESPONSIVE WEB DESIGN