Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML <script> crossorigin Attribute

  • Last Updated : 30 Sep, 2021

The HTML <script> crossorigin Attribute is used for loading an external script into their domain from a third party server or another domain with the support of HTTP CORS Request. This attribute is used to protect sensitive information from the third party when fetching out the results.

Cross-Origin Resource Sharing(CORS) is a tool that allows web pages requesting for resources from another domain that is outside of their own domain. It is also used for managing cross-origin requests which is a request for a resource from an outside domain.


<script crossorigin="anonymous | use-credentials">

Attribute Values:

  • anonymous: It has a default value. It defines a CORS request will be sent without passing the credentials information.
  • use-credentials: A cross-origin request will be sent with credentials, cookies, and certificate.

Note: This attribute is only valid for use if we try to fetch the resources from the third party domain. 

Example: Below code illustrates the use of crossorigin attribute with the <script> element. 


<!DOCTYPE html>
    <title>HTML script crossorigin Attribute</title>
<body style="text-align: center">
    <h2>HTML script crossorigin Attribute</h2>
    <br />
    <script type="text/javascript" 
        src="my_script.js" crossorigin="anonymous">


Supported Browsers:

  • Google Chrome 30.0
  • Firefox 13.0
  • Microsoft Edge 18.0
  • Opera 12.0
  • Safari 1.0
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!