Open In App

HTML <img> crossorigin Attribute

Last Updated : 22 Jul, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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 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: Below code illustrates the use of crossorigin attribute in the <img> element. It is set to "anonymous" value which retrieved the .png or .jpeg files without passing credentials information. 

  

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML img crossorigin Attribute
    </title>
</head>

<body>
  <center>
    <h1>GeeksforGeeks</h1>

    <h2>HTML <img> crossorigin Attribute</h2>

    <img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png"
        alt="GeeksforGeeks logo" crossorigin="anonymous">
</body>

</html>

Output: 

Supported Browsers:

  • Google Chrome 
  • Edge 12 and above
  • Firefox 
  • Internet Explorer 
  • Opera 
  • Safari 

Next Article

Similar Reads