<script> - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:script

Introduction

The script element can include scripting in your pages, either inline or an external file.

The script Element summary

Item Value
Element script
Local Attributes type, src, defer, async, charset
Contents Script language statements or empty if an external JavaScript library is specified
Tag Style A start and end tag are required; self-closing tags are not permitted even when referencing an external JavaScript library
New in HTML5 No
Changes in HTML5 The type attribute is optional in HTML5. async and defer attributes are added in HTML5. language attribute is obsolete in HTML5.
Style Convention None

Local Attributes of the script Element

Attribute Description
type set the type of the script. This attribute can be omitted for JavaScript scripts.
srcset the URL for an external script file.
defer set how the script will be executed. These attributes can only be used in conjunction with the src attribute.
async set how the script will be executed. These attributes can only be used in conjunction with the src attribute.
charset set the character encoding of an external script file. This attribute can only be used with the src attribute.

Defining an Inline Script

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
   <head> 
      <script>
document.write("This is from the script");

      </script> 
   </head> 
   <body> 
      <p>
          I like 
         <code id="myId">HTML</code>
          and CSS. <!--  ww w. j  ava2 s . co m-->
      </p> 
      <a href="http://java2s.com">Visit java2s.com</a> 
      <a href="page2.html">Page 2</a>  
   </body>
</html>

Related Tutorials