Open In App

HTML <audio> crossorigin Attribute

Improve
Improve
Like Article
Like
Save
Share
Report

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

Last Updated : 30 Sep, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads