HTML <script> Tag
Example
Insert a JavaScript in an HTML page:
<script type="text/javascript">
document.write("Hello World!")
</script> |
Try it yourself » |
Definition and Usage
The <script> tag is used to define a client-side script, such as a JavaScript.
The script element either contains scripting statements or it points to an external script file through the src attribute.
The required type attribute specifies the MIME type of the script.
Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
Browser Support

The <script> tag is supported in all major browsers.
Differences Between HTML and XHTML
HTML 4 and XHTML deal different with the content inside scripts:
- In HTML 4, the content type is declared as CDATA, which means that
entities will not be parsed.
- In XHTML, the content type is declared as (#PCDATA), which means that
entities will be parsed.
This means that in XHTML, all special characters should be encoded or all content should be wrapped inside a CDATA section.
To ensure that a script parses correctly in an XHTML document, use the following syntax:
<script type="text/javascript"><![CDATA[
var i=10;
if (i<5)
{
// some code
}
//]]></script> |
Tips and Notes
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.
Required Attributes
DTD indicates in which HTML 4.01/XHTML 1.0
DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.
| Attribute |
Value |
Description |
DTD |
| type |
MIME-type |
Specifies the MIME type of a script |
STF |
Optional Attributes
| Attribute |
Value |
Description |
DTD |
| charset |
charset |
Specifies the character encoding used in an external script
file |
STF |
| defer |
defer |
Specifies that the execution of a script should be deferred
(delayed) until after the page has been loaded |
STF |
| src |
URL |
Specifies the URL of an external script file |
STF |
| xml:space |
preserve |
Specifies whether whitespace in code should be preserved |
|
Standard Attributes
The <script> tag does not support any standard attributes.
More information about Standard Attributes.
Event Attributes
The <script> tag does not support any event attributes.
More information about Event Attributes.
Make your web applications look like a million bucks
|
|
Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.
FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc.
and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise
whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our
12,000 customers and 150,000 users which include a majority of the Fortune 500 companies.
And yeah, your applications could look like a million bucks by spending just $69.
So go ahead, download your
copy of FusionCharts and start "wow-ing" your customers now!
|
|