HTML Dog
Skip to navigation

HTML Tag: script

An executable script, such as JavaScript.

Script can be embedded directly in the page by inserting it in between the opening and closing tags. It can also be imported by linking to a file with the src attribute.

Optional Attributes

Attribute Description Possible values
src The location of a script file to be imported. URL.
type The type of script being used. MIME type. Default is text/javascript.
charset The character encoding of an external script. Used only when src is present. A character encoding declaration such as UTF-8.
async Indicates that an external script should be executed asynchronously. Used only when src is present. None.
defer Indicates that an external script should be deferred and executed only after the page has been parsed. Used only when src is present. None.
crossorigin Determines how Cross Origin Resource Sharing requests are handled.
  • anonymous
  • use-credentials
Global attributes

Example


<script async src="somescript.js"></script>
<script>
    function koala() {
        alert('KOALA! KOALA!');
    }
</script>