You are here: Reference > JavaScript > client-side > HTML DOM > properties > defaultCharset (document)

defaultCharset property (document)

Browser support:
Returns the character set that belongs to the current regional and language settings of the operating system.
To get the character encoding of the document, use the document.charset and the document.characterSet properties. To get the character encoding used for parsing the document, use the inputEncoding property.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

String that represents the default character set. For more information, see the page for character sets.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the defaultCharset property:
<!DOCTYPE html>
    <meta charset="utf-8" />
    <script type="text/javascript">
        function GetCharSet () {
            var message = "";

            var docCharSet = document.characterSet ? document.characterSet : document.charset;
            message += "The character encoding of the document: <b>" + docCharSet + "</b><br />";

            if (document.defaultCharset) {
                message += "The character encoding that belongs to the operating system:  <b>" + document.defaultCharset + "</b><br />";
            if (document.inputEncoding) {
                message += "The character encoding used for parsing the document:  <b>" + document.inputEncoding + "</b><br />";

            var info = document.getElementById ("info");
            info.innerHTML = message;
<body onload="GetCharSet ()">
    <div id="info" style="width:500px; background-color:#e0d0d0;"></div>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content