HTML5: How to specify the character encoding used in an external script file?
Solution:
HTML Code:
<!DOCTYPE html><!-- Define document type as HTML5 -->
<html><!-- Start of HTML document -->
<head><!-- Start of head section -->
<meta charset="utf-8"><!-- Define character encoding -->
<title>How to specify the character encoding used in an external script file</title><!-- Title of the document -->
</head><!-- End of head section -->
<body><!-- Start of body section -->
<p id="output">Click Me</p><!-- Define a paragraph with an id for interaction -->
<script charset="utf-8" src="https://www.w3resource.com/html-css-exercise/basic/solution/async-example.js">
</script><!-- Include an external script with specified character encoding -->
</body><!-- End of body section -->
</html><!-- End of HTML document -->
Explanation:
- This HTML code demonstrates how to specify the character encoding used in an external script file using the charset attribute.
- The <script> element is used to include an external JavaScript file indicated by the src attribute.
- The src attribute points to the URL of the external script file, "https://www.w3resource.com/html-css-exercise/basic/solution/async-example.js".
- The charset attribute is added to specify the character encoding used in the external script file, in this case, "utf-8".
- Specifying the character encoding ensures that the browser interprets the script file correctly, especially if it contains non-ASCII characters or characters specific to a certain character encoding.
- Using the correct character encoding is important for ensuring the proper functioning and display of the script content.
Live Demo:
See the Pen script-charset-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics