HTML - DOM Document charset Property



HTML DOM document charset property is deprecated property which was used to get the character encoding of the HTML document. It is a read only property.

Syntax

document.charset;

Return value

It returns string value representing character's encoding.

Example of HTML DOM Document 'charset' Property

Here is an example showing use of charset property, in this example we have used conditional statement to check if the document is common encoding(UTF-8) since charset property is no longer in use.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>HTML DOM document charset</title>
</head>
<body>
    <script>
        const enc= document.charset;
        if (enc === 'UTF-8') {
            console.log("This document is in UTF-8");
        }
        else{
            console.log(enc);
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
charset No No No No No
html_dom.htm
Advertisements