Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTML <script> crossorigin Attribute
Next article icon

HTML <script> crossorigin Attribute

Last Updated : 26 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML <script> tag with the crossorigin attribute specifies how to handle fetching of external scripts. When set to "anonymous", it indicates that the script should be retrieved without sending user credentials.

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.

Syntax:

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

Attribute Values:

AttributeDescription
anonymousIt has a default value. It defines a CORS request will be sent without passing the credentials information.
use-credentialsA cross-origin request will be sent with credentials, cookies, and certificates

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

Example: In this example the HTML script tag with crossorigin attribute set to "anonymous" for loading my_script.js file. Button for submission included in the body.

HTML
<!DOCTYPE html> <html>     <head>         <title>             HTML script crossorigin Attribute         </title>     </head>      <body>         <h2>HTML script crossorigin Attribute</h2>          <br />         <button>Submit</button>          <script             type="text/javascript"             src="my_script.js"             crossorigin="anonymous"         ></script>     </body> </html> 

Output:

scriptCross
HTML


Supported Browsers:

  • Google Chrome
  • Edge 
  • Firefox
  • Opera
  • Safari

Next Article
HTML <script> crossorigin Attribute

M

manaschhabra2
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML-Tags
  • HTML-Attributes

Similar Reads

    HTML <img> crossorigin Attribute
    The HTML crossorigin Attribute in is used in <img> element that supports a CORS request when we tried to fetch out the .png or .jpg files from the third party server or from other domain.  Syntax <img crossorigin="anonymous | use-credentials"> Attribute Values: anonymous: It has a defaul
    1 min read
    HTML | <script> charset Attribute
    The HTML <script>charset Attribute is used to specifies the character encoding used in an external script. Syntax: <script charset="charset"> Note: HTML <script>charset Attribute is not supported by HTML5. Attribute Values: It contains the value charset which specifies the characte
    1 min read
    HTML <audio> crossorigin Attribute
    The HTML crossorigin Attribute is used in the <audio> element that supports a CORS request when we tried to fetch out the audio files from the third-party servers or from another domain.  Syntax: <audio crossorigin="anonymous | use-credentials">Attribute Values: anonymous: It has a Defau
    1 min read
    HTML crossorigin Attribute
    CORS stands for cross-origin resource sharing. It is a mechanism by which one webpage requests to another domain for fetching out the resource like audio, video, script, etc from the third party server without leaking their credentials information.  If specified, the request will be sent with or wit
    2 min read
    HTML | <script> src Attribute
    The HTML <script> src Attribute is used to specify the URL of external JavaScript file. The External JavaScript file is used to run on the same script on several pages on a website. We can save the JavaScript file with an extension of .js. We can refer the external script using the src attribu
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences