The Wayback Machine - https://web.archive.org/web/20250108194155/https://www.geeksforgeeks.org/html-accept-charset-attribute/
Open In App

HTML accept-charset Attribute

Last Updated : 27 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The accept-charset attribute is used to define the character encoding and is used for form submission. The default value of the accept-charset attribute is “UNKNOWN” string which indicates the encoding equals to the encoding of the document containing the <form> element. 

Syntax:

<form accept-charset = "character_set">

Attribute Value: The attribute value contains the list-separated value of one or more encoding attributes. The common value of the encoding attribute is UTF-8, ISO-8859-1. This attribute is always associated with the form element only. 

Example: In this example, we are using the accept-charset attribute within a form. It specifies “UTF-8” as the character encoding for data submission, ensuring proper handling of text inputs.

html
<!DOCTYPE html>
<html>

<head>
    <title>accept-charset attribute</title>
    <style>
        h1 {
            color:green;
        }
        body {
            text-align:center;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h2>accept-charset Attribute</h2>
    <form action="#" accept-charset="UTF-8">
        First name:<input type="text" 
                          name="fname">
        <br>
        Last name:<input type="text" 
                         name="lname">
        <br>
        <input type="submit" 
               value="Submit">
    </form>
</body>

</html>

Output:

  

Supported Browsers: The browser supported by accept-charset attribute are listed below:

HTML accept-charset Attribute – FAQs

Where is the accept-charset attribute used?

The accept-charset attribute is used within the <form> tag in HTML. It defines the character encodings that the server should accept when processing the form data.

What are the common values for the accept-charset attribute?

Common values include UTF-8, ISO-8859-1, and UTF-16. UTF-8 is the most commonly used and recommended character encoding because it supports a wide range of characters from different languages.

What is the default value of the accept-charset attribute?

If the accept-charset attribute is not specified, the default value is usually the character set specified in the document’s meta tag, typically UTF-8.

Why is UTF-8 the preferred value for accept-charset?

UTF-8 is the preferred value because it supports a wide range of characters, including most characters from all major languages, making it suitable for global web applications.

Can the accept-charset attribute affect how special characters are handled in form submissions?

Yes, the specified charset in accept-charset ensures that special characters, such as accented letters or symbols, are properly encoded when the form data is submitted.


Next Article

Similar Reads

three90RightbarBannerImg