How do we display a script in HTML?

HTMLWeb DevelopmentFront End Technology

To add a script, use the <script> tag. The HTML <script> tag is used for declaring a script (such as JavaScript) within your HTML document.

The script tag supports the following additional attributes −

Attribute
Value
Description
async
sync
Specifies that the script is executed asynchronously
Charset
charset
Defines the character encoding that the script uses.
defer
defer
Declares that the script will not generate any content. Therefore, the browser/user agent can continue parsing and rendering the rest of the page.
src
URL
Specifies a URI/URL of an external script.
type
text/JavaScript application/ecmascript application/JavaScript text/vbscript
Specifies the scripting language as a content-type (MIME type).
xml:space
preserve
Deprecated − Whether the whitespace in code should be preserved

Example

You can try to run the following code to display a script in HTML −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML script Tag</title>
   </head>
   <body>
      <script>
         document.write("You're visiting tutorialspoint!")
      </script>
   </body>
</html>
raja
Published on 13-Mar-2018 08:35:04
Advertisements