Advertisement
Home Open Editor ❯

HTML charset Attribute

Example

<head>
  <meta charset="UTF-8">
  <!-- or -->
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

Try this code ❯

Meaning

<meta>

The charset attribute is used to set the character encoding for the document like “UTF-8”.

This approach is an alternative to using the http-equiv method currently employed.

<script>

The charset attribute specifies the character encoding used in an external script file. It is used when the character encoding in an external script file differs from the encoding in the HTML document.

Note: The charset attribute is only for external scripts.


Standard Syntax

<element charset="">


Applies to:

The charset attribute can be used on the following element:

Element Attribute
<meta> charset
<script> charset

Advertisement

Attribute Values

Value Description
characterSet Specifies the character encoding for the document. The HTML5 specification recommend to use the UTF-8 character set!

More Examples

Example

<script charset="UTF-8" src="demo-script-charset.js"></script>

Try this code ❯

Home Open Editor ❯
Advertisement