Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to indicate character set being used by a document in HTML ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

For web browser to understand the set of characters used in the HTML document, various HTML encoding character set representations has been used like ASCII, ISO-8859-1, UTF-8 etc. The character set being used by an HTML document is indicated using the charset attribute of a <meta> tag inside the <head> element of the HTML.

In HTML4, ISO-8859-1 was the by-default character set. HTML 4 also supported UTF-8.

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

In HTML5, developers were encouraged to use the UTF-8 character set, which covers all characters and symbols. Therefore, UTF-8 is the default character set for HTML-5.

<meta charset="UTF-8">

UTF stands for Unicode Transformation Format, where ‘8’ in UTF-8 means it uses 8-bit blocks to represent a character. 

Ways to indicate character set: Character Set is also abbreviated as charset, which is an attribute in an HTML document to term the character encoding. Character Set in HTML document can be represented by following two ways:

1. Using Meta tag:

  • The meta tag is used to specify the character encoding in an HTML document.
  • The meta tag defines meta-data about HTML document which is not displayed on the webpage.
  • It helps search engines to understand what that particular webpage is about.
    <meta charset="UTF-8">

2. Using Script tag:

  • The script tag is used to specify the character encoding in an external file.
  • The script tag defines client-side script.
  • The script tag refers to an external script file through the ‘src’ attribute.
<script src="script.js" charset="UTF-8"></script>

Where the charset is an attribute for character encoding. Charset allows the web browser to use the character encoding while translating the machine code into human-readable text and vice-versa to display in the browser.

Example: Below in the code section, the example snippet of both the tags are mentioned.


<!DOCTYPE html>
    <meta charset="UTF-8">
    <h2>Welcome To GFG</h2>
        Here is an example for indicating 
        character set in HTML Document.


My Personal Notes arrow_drop_up
Last Updated : 13 Dec, 2021
Like Article
Save Article
Similar Reads
Related Tutorials