HTML | charset Attribute

The charset attribute in HTML is used to define the character encoding. The charset attribute is used with the <meta> and <script> element.

Charset attribute in <meta> Tag: The charset attribute is present in the meta element. It specify the character encoding for the HTML document.

Syntax:

<meta charset="character_set"> 

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            Charset Attribute script tag
        </title
          
        <style
            body { 
                text-align:center; 
            
            h1 { 
                color:green; 
            
        </style
    </head
      
    <body
        <h1>GeeksforGeeks</h1
          
        <h2>
            HTML charset Attribute in 
            <script> Element
        </h2
          
        <p id="Geeks"></p
          
          
        <script charset="UTF-8"
            document.getElementById("Geeks").innerHTML
                    = "Hello GeeksforGeeks!"; 
        </script
    </body
</html>                    

chevron_right


Output:

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

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.