A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-charset-attribute/ below:

HTML charset Attribute - GeeksforGeeks

HTML charset Attribute

Last Updated : 11 Jul, 2025

The charset attribute in HTML is used to define the character encoding. The charset attribute is used with the <meta> and <script> elements.
Charset attribute in <meta> Tag: The charset attribute is present in the meta element. It specifies the character encoding for the HTML document.

Supported Tags: 

Syntax:  

<meta charset="character_set"> 

Attribute Values: It contains the value i.e character_set which specifies the character encoding for the HTML document.

Values:


Example: This example illustrates the use of charset attribute in meta element. 

html
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML charset Attribute
    </title>

    <meta name="keywords" 
          charset="UTF-8" 
          content="Meta Tags, Metadata" />
</head>

<body style="text-align:center">
    <h1>Hello GeeksforGeeks!</h1>

    <h2>
        HTML charset Attribute in Meta Element
    </h2>
</body>

</html>

Output: 


Charset attribute in <script> Tag: When charset attribute present in the script element, it specifies the character encoding used in an external script. 

Syntax:  

<script charset="charset">

Example: This Example illustrates the use of charset attribute in script element.  

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Charset Attribute in Script Tag
    </title>

    <style>
        body {
            text-align: center;
        }

        h1 {
            color: green;
        }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>

    <h2>
        HTML charset Attribute in
        <code>&lt;script&gt;</code> Element
    </h2>

    <p id="Geeks"></p>

    <script charset="UTF-8">
        document.getElementById("Geeks").innerHTML = "Hello GeeksforGeeks!"; 
    </script>
</body>

</html>

Output:  


Supported Browsers: The browser supported by HTML charset Attribute are listed below:  



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4