Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML <audio> crossorigin Attribute

  • Last Updated : 30 Sep, 2021

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 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.

 

Example: The below code illustrates the use of crossorigin attribute in <audio> element. It is set to “anonymous” value which retrieved the audio files without passing credentials information.  

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>HTML audio crossorigin Attribute</title>
</head>
  
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h2>HTML audio crossorigin Attribute</h2>
        <b>
            <p>Audio Sample</p>
        </b>
  
        <!-- Use of crossorigin Attribute in audio element -->
        <audio crossorigin="anonymous" controls>
            <source src="test.mp3" type="audio/mp3" />
            <source src="test.ogg" type="audio/ogg" />
        </audio>
    </center>
</body>
  
</html>

Output:

Supported Browsers:

  • Google Chrome 94.0 & above
  • Firefox 92.0 & above
  • Microsoft Edge 93.0
  • Opera 79.0
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!