Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
HTML Script Tag
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. HTML Tutorials
  3. HTML Script Tag

HTML Tutorial

Basic HTML Fundamentals

  • HTML Table Content
  • Introduction To HTML
  • What Is HTML
  • HTML Tags
  • HTML Formatting
  • HTML Heading
  • HTML Paragraph
  • HTML Anchor
  • HTML Image
  • HTML Table
  • HTML Lists
  • HTML Ordered List
  • HTML Unordered List
  • HTML Description List
  • HTML Form

HTML Tags

  • Marquee HTML
  • HTML Textarea
  • HTML Quotes
  • HTML Style
  • HTML Title Or HTML Doctype
  • HTML Div Tag
  • HTML Pre Tag
  • HTML Code Tag
  • HTML Label Tag
  • HTML Input Tag
  • HTML Button Tag
  • HTML Hr Tag
  • HTML Br Tag
  • HTML Script Tag
  • HTML NoScript Tag
  • HTML Bold Tag

HTML Script Tag

HTML Script Tag

HTML script tag is used to specify client-side script such as JavaScript. It facilitate you to place a script within your HTML document.

JavaScript is used for image manipulation, form validation, and dynamic content.

The <script> element either contains scripting statements, or it points to an external script file through the src attribute.

The syntax of script tag is given below:

<script>  
  //code to be executed  
</script>  

Attributes of HTML script tag

Attribute Description Compatibility
src It specifies the URL of an external script file. HTML 4.01, HTML5
type It specifies the media type of the script. HTML 4.01
async It is a boolean value which specifies that the script is executed asynchronously. HTML5
defer It is a boolean value which is used to indicate that script is executed after document has been parsed. HTML 4.01, HTML5
charset charset : Specifies the character encoding used in an external script file HTML 4.01, HTML5
xml:space preserve : Specifies whether whitespace in code should be preserved Not supported in HTML5.

Usage of script tag

There can be two usage of HTML script tag:

  • to embed script code
  • to link script file

Embed script code

The script tag can be used within <body> or <head> tag to embed the scripting code. Let's see the example to have script tag within HTML body.

<script type="text/javascript">  
document.write("JavaScript is a simple language for Easytolearning learners")  
</script> 

Output

JavaScript is a simple language for Easytolearning learners

Link script file

The script tag can be used to link external script file by src attribute. It must be used within the <head> tag only.

<script type="text/javascript" src="myjsfile.js" />  

Tips and Notes

Note: If the "src" attribute is present, the <script> element must be empty.

Tip: Also look at the <noscript> element for users that have disabled scripts in their browser, or have a browser that doesn't support client-side scripting.

Note: There are several ways an external script can be executed:

  • If async="async": The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing)
  • If async is not present and defer="defer": The script is executed when the page has finished parsing
  • If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page
Series: HTML Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
HTML Script Tag HTML JavaScript HTML Script Tag Tutorial with Examples html script src html script example javascript tags list html javascript function html script type

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.