In HTML, the accept-charset attribute is used within the <form> tag, which specifies the character encodings that the server can accept when submitting form data.
Definition and Usage
➔ This helps prevent data corruption or misinterpretation in server side data processing.
➔ By default if accept-charset is not specified, the form usually uses the same character encoding as the document containing the form.
Example
<form method="post" accept-charset="UTF-8">
<!-- code goes here -->
</form>
➔ The accept-charset attribute value is a space-separated list of character encodings. ex: accept-charset="UTF-8 ISO-8859-1"
Example
<form method="post" accept-charset="UTF-8 UTF-16">
<!-- code goes here -->
</form>
Applies to
This attribute can be used on the following element.
| Attribute | Element |
|---|---|
| accept-charset | <form> |
Example
<body>
<h2>HTML accept-charset Attribute Example</h2>
<p>This is for example purposes only, this example will not allow you to submit values.</p>
<form action="#" accept-charset="ISO-8859-1">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
<button type="submit">Submit</button>
</form>
</body>
Click on the "Try it Now" button to see how it works.