HTML charset attribute

Charset (character set) attributes tell the browser that which character encoding should be used by the document. character encoding method is used to store or transmit the pages.


<!DOCTYPE html>
 <meta charset='UTF-8'>
 <p>meta tag is  always written in the head tag.</p>
 <p>character set used here is 'utf-8'</p>
Try </>

The value of this attribute forces the document to use "UTF-8" as encoding type.

There are many other types of character encoding but UTF-8 is recommended for the web content.

charset attribute values

The value of this attribute is the character encoding labels. The following are the types of charset (character set).

JIS_C6226-1983, JIS_X0212-1990, JOHAB, CESU-8, UTF-7, BOCU-1 and SCSU encodings should not be used for the web content.

Related Tags

The tags that support this attribute are as follows.

<meta> tag

meta tag represents the meta information of the page. It is necessary to use charset attribute in the meta element.

<meta charset="UTF-8" />

<script> tag

script tag imports or adds script in the page. charset attribute represents the character encoding of the scripting language.

<script src="URL of file to be imported" charset="UTF-8"> </script>

charset attribute should be used only once in a page.

Was this article helpful?




Get the newsletter