HTML accept-charset attribute
accept charset
The accept-charset attribute specifies the character encodings a form submission can accept. This tells the browser which character sets to use when sending form data to the server.
Supported Element
- <form>
Syntax
<form accept-charset="character-set-list" >...</form>
Values
- Character Set List: A space-separated list of character encodings (e.g., UTF-8, ISO-8859-1).
- The browser prioritizes encodings from left to right.
- Common values: UTF-8 (recommended), ISO-8859-1, ISO-8859-5.
- Default Behavior: If omitted, the page’s charset (defined in ) is used.
Key Notes
1. HTML5 Support: The accept-charset attribute is valid in HTML5, not just HTML 4.01.
2. UTF-8 Recommendation: Modern applications should prioritize UTF-8 for broad compatibility.
3. Browser Handling: Browsers may ignore this attribute if the server specifies a charset via HTTP headers.
Examples
Example 1: Restricting to Image Files (HTML5)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>accept Attribute Example</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
<label for="avatar">Upload Profile Picture:</label>
<input
type="file"
id="avatar"
name="avatar"
accept="image/png, image/jpeg, .jpg, .png"
>
<button type="submit">Upload</button>
</form>
</body>
</html>
Result
View this example in a separate browser window
Example of HTML accept-charset attribute with form
Browser Compatibility
- Supported in all modern browsers (Chrome, Firefox, Safari, Edge).
- Partial support for wildcards (e.g., image/*) in older browsers.
Previous: HTML abbr attribute
Next: HTML accept attribute
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics