HTML form Attributes

HTML Tutorial

HTML form Attributes

The <form> element in HTML can include several attributes to control how form data is submitted, processed, and displayed. These attributes define the behavior and functionality of the form.


Common Form Attributes

AttributeDescriptionExample
actionURL of the server-side script to process the form<form action="submit.php">
methodHTTP method to send data: GET or POST<form method="post">
enctypeEncoding type for form data (needed for file uploads)<form enctype="multipart/form-data">
nameName of the form (used in scripts)<form name="contactForm">
idUnique identifier for the form (CSS/JS)<form id="regForm">
targetWhere to display the response (_self, _blank, _parent, _top)<form target="_blank">
autocompleteEnable or disable autofill for form fields<form autocomplete="off">
novalidateDisables HTML5 form validation<form novalidate>
accept-charsetCharacter encodings the server accepts<form accept-charset="UTF-8">

Example HTML Form Using Form Attributes


 


Explanation

  • action="submit.php" → Sends form data to submit.php.

  • method="post" → Uses POST method to send data securely.

  • enctype="multipart/form-data" → Required for file uploads.

  • id & name → Unique identifiers for scripting or CSS.

  • autocomplete="on" → Browser can auto-fill previously entered values.


Key Points

  • Always include action and method for proper form submission.

  • Use enctype="multipart/form-data" when handling file uploads.

  • novalidate disables browser-side validation if you plan to validate manually.

  • accept-charset ensures correct character encoding for multilingual forms.

You may also like...