Write "Hello world" with JavaScript:
![]()
The <script> tag is supported in all major browsers.
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.
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.
HTML 4 and XHTML deal different with the content inside scripts:
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:
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 the script | STF |
| Attribute | Value | Description | DTD |
|---|---|---|---|
| charset | charset | Specifies the character encoding used in an external script file | STF |
| defer | defer | Specifies that the script is executed when the page has finished parsing (only for external scripts) | STF |
| src | URL | Specifies the URL of an external script file | STF |
| xml:space | preserve | Specifies whether whitespace in code should be preserved |
The <script> tag does not support any standard attributes.
More information about Standard Attributes.
The <script> tag does not support any event attributes.
More information about Event Attributes.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| Download XML Editor |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|