HTML CSS Bootstrap Javascript Icons Python
HTML References
HTML - Tag Reference HTML - Tag by Category HTML - Attributes HTML - Global Attributes HTML - Events HTML - Language Codes HTML - Country Codes HTML - URL Encoding HTTP Methods HTTP Status Codes <input> types
All HTML Tags
<!-- --> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <script> tag

The HTML <script> element is used for declaring a client-side script (such as JavaScript) within your HTML document.

The <script> element either contains scripting statements, or it points to an external script file through the src attribute.

Run code

You can place any number of scripts in an HTML document.

Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.

Common uses for JavaScript are event capturing, form validation, and dynamic changes of content.

Browser compatibility

The <script> element is fully supported by all browsers:

<script> yes yes yes yes yes


The following table shows the attributes that are specific to the <script> tag:

Attribute Value Description
async - This is a Boolean attribute indicating that the browser should, if possible, execute the script asynchronously
charset character-set Specifies the character encoding used in an external script file
defer - This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed
src URL Specifies the URL of an external script; this can be used as an alternative to embedding a script directly within a document
type text/JavaScript
Specifies the scripting language as a content-type (MIME type).
This attribute is required in HTML 4, but optional in HTML5

Global Attributes

The <script> tag supports the global attributes described in HTML Global Attributes Reference

More Examples

This example point to an external JavaScript file:

Run code

Last updated: Friday 28 Sep, 2018