HTML Form Attributes

HTML Form Attributes

The <form> element in HTML supports several attributes that control how form data is sent and displayed. These attributes define behavior, appearance, and validation for forms.


Common Form Attributes

Attribute Description Example
action Specifies the URL where form data is sent <form action="submit.php">
method Defines the HTTP method (GET or POST) <form method="post">
enctype Specifies encoding type for sending data (application/x-www-form-urlencoded, multipart/form-data for file upload) <form enctype="multipart/form-data">
name Assigns a name to the form <form name="contactForm">
id Unique identifier for the form <form id="form1">
target Specifies where to display the response (_self, _blank, _parent, _top) <form target="_blank">
autocomplete Enables/disables autofill of form fields (on / off) <form autocomplete="off">
novalidate Disables HTML5 form validation <form novalidate>

Example Code Using Attributes


 


Explanation

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

  • method="post" → Data is sent securely in HTTP request body.

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

  • id="regForm" → Unique identifier for CSS or JS.

  • autocomplete="on" → Browser can auto-fill fields.


Key Points

  • Always set the action and method attributes for proper form submission.

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

  • autocomplete and novalidate help improve user experience and form control.

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *