×

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag.

This <script> tag can be used for containing scripting statements. It can also point another external script file with the help of the src attribute in html document.

In HTML documents, JavaScript is commonly used for manipulating images, validating forms, and making dynamic changes in data and information of the document.

Syntax:

<body>
<script>
……………………………….…;
</script>
</body>

Example

In this example, we are going to write "Hello JavaScript!"with the help of JavaScript:

<!DOCTYPE html>
<html>
<head>
<title> html script tag </title>
</head>
<body>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>

Attributes of Script Tag    

Async:

It is similar to defer attribute. Using this attribute we can make the script completely independent.There is no blockage on the browser when we use async attribute

Crossorigin:

It is used to configure the HTTP CORS Request request mode.

Integrity:

It is used to allow a web browser so that it may be reviewed and ensure that the fetched script is never loaded if the source of the data has been altered.

Nomodule:

This parameter enables the ES2015 modules and specifies that the used script cannot be launched in web browsers.

Unsafe-url:   

It is used to specify the information at the time of requesting a script.

Src:

This attribute helps in providing the URL of an external script file.

Comparison between HTML and XHTML

Data and information in scripts are supplied in XHTML as #PCDATA rather than CDATA, which triggers the processing of entities.

Example:

<!DOCTYPE html>
<html>
<head>
<title> html script tag </title>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
var i = 10;
if (i < 5) {
// some code
}
//]]>
</script>
</body>
</html>

Default CSS Settings

The CSS values which are automatically saved as default in most of the browsers according to the use of section tag. The following CSS is added to the document:

script {
display: none;
}

Related Topics

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

HTML <select> tag

This tag helps in making the drop-down list on the web page. This is highly used in HTML forms for taking the input from user. You can use the id attribute...

3 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

How to append HTML code to a div using JavaScript?

In HTML, we have a div tag which is used to create a box where we can put a lot of other tags. So it works like a container. So,...

4 minutes read.

HTML <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

How to insert image in HTML

An image (technically digital image) in HTML or even in general technical aspects is a binary representation of visual information. By visual information we mean, in the form of drawings/pictures,...

5 minutes read.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML Code

Before jumping into the topic, let’s understand a common scenario where we have a code snippet in our HTML file. By code snippet, we mean computer code, which is written...

5 minutes read.

HTML Font Color

The HTML <font> tag has an attribute called color, which defines the color of the text. We use the color attribute inside the <font> tag to specify the color of...

6 minutes read.

HTML <body> tag

HTML means Hyper Text Markup Language, which is most preferred for making Web pages. It explains how a Web page is put together. There are many different elements in HTML,...

3 minutes read.

Difference between HTML and DHTML

Introduction to HTML HTML stands for Hypertext Markup Language. It is a standard web language used to create web pages and applications. HTML is used to define the structure and content...

4 minutes read.

HTML Text Format

Introduction HTML may format text in two different ways. The HTML tags define a text property to make it appear one way or another. A text element may also be formatted...

7 minutes read.

CSS Clearfix

CSS Clearfix: A clearfix (or clear float) in CSS is for a component to clear or fix the child component, so we don’t need to insert additional markup. The clear...

4 minutes read.

Html &lt;datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form...

4 minutes read.

Font tag in HTML

HTML stands for Hypertext Mark-up Language and is used to create web pages and other information that can be later displayed in a web browser. It also consists of a...

4 minutes read.

HTML Form Input Types

HTML Form Input Types An important element of the HTML form is < input type= "> in HTML. The type attribute of the input element can be of different types, which...

8 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.

HTML Paragraphs

In html, there are some elements which starts with new line and one of them is paragraph. Which is said to be a block of text. In html <p> tag...

4 minutes read.