accept-charset

This article explains how the HTML accept-charset attribute affects form submission, why UTF-8 is the practical default today, and how to think about preventing garbled text.

What you will learn

What does accept-charset do?

accept-charset is an attribute of <form>. It describes the character encoding used when the browser turns entered text into data for submission.

In modern web development, the practical answer is usually UTF-8. Aligning the form, server, and database reduces surprises with Japanese text, emoji, and accented characters.

Three settings that are easy to confuse

<meta charset="UTF-8">
Tells the browser how to read the HTML document itself.
Content-Type: text/html; charset=UTF-8
Tells the browser how to decode the HTTP response sent by the server.
<form accept-charset="UTF-8">
Describes the encoding used for data submitted by that form.

These settings have related names but different jobs. Check sending and receiving separately when investigating mojibake.

Recommended minimum example

<form action="/submit" method="post" accept-charset="UTF-8">
  <label>
    Name
    <input type="text" name="name" autocomplete="name">
  </label>
  <button type="submit">Send</button>
</form>

Why does text become garbled?

Text is converted to bytes when it is sent. The sender uses one encoding rule and the receiver must decode those bytes with the same rule. If they disagree, the result can look like ???? or unreadable symbols.

accept-charset only describes the form submission side. It cannot fix a server, database, response header, or old file that uses a different encoding.

Practical checklist

Common mistakes

Adding the attribute does not fix the mojibake
The receiving server may be decoding the request with a different assumption. Inspect the request, server, and database separately.
Trying to use Shift_JIS as a modern fallback
Current browsers and web stacks are designed around UTF-8. Use UTF-8 consistently unless a legacy system genuinely requires otherwise.
Confusing the attribute with the page encoding
meta charset reads the page; accept-charset describes form submission. They are complementary, not interchangeable.

Related pages