/    Sign up×
Reference /Pin to ProfileBookmark

The script tag is used to embed a client-side script like JavaScript.

Syntax

The <script> tag can either wrap around scripting elements or it can link to an external script using the src attribute.

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>

<script src="external-script.js" type="text/javascript"></script>

Attributes

async
Used for external scripts, this attribute designates that the script is downloaded in parallel with the page and executed immediately upon availability.

crossorigin
Sets the request mode to an HTTP CORS request. Possible values: anonymous and user-credentials.

defer
Used for external scripts, this attribute designates that the script is downloaded in parallel with the page and executed after the rest of the page is loaded.

integrity
Checks the external script to make sure the code is not loaded if the source has been manipulated.

nomodule
Designates that the script will not be executed when the browser supports ES2015 modules.

referrerpolicy
Determines which referrer information is sent when fetching the script. Possible values: no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-originstrict-origin-when-cross-origin, and unsafe-url.

src
Sets the URL address of the external script file.

type
Designates the script’s media type.

Browser Compatibilty

Demos

Have a code example of <script>? Submit a codepen.io demo and we'll showcase it here

to submit a demo.
HTML
×

Success!

Help @reference spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...