Skip to main content

Use this tag when you see a message in the browser devtools console about CORS (Cross-Origin Resource Sharing) — e.g., your browser logged an error about Access-Control-Allow-Origin, and you want to know how to eliminate the error. Also for other questions on the CORS protocol (defined in the Fetch Standard as a way to use response headers to tell browsers to relax the same-origin policy and allow cross-origin XHR/Fetch/Ajax requests).

Browsers implement the Same-Origin Policy to block frontend JavaScript code from accessing responses to cross-origin requests.

CORS (Cross-Origin Resource Sharing) is a way that servers can instruct browsers to relax the Same-Origin Policy and allow frontend code to access cross-origin responses.

Configuring a server for CORS never causes the server itself to block any requests; instead, a CORS-enabled server just sends back additional Access-Control-* response headers, and the browser uses the values of those headers to determine whether it should allow frontend code running at a particular origin to access responses from that server.

See also: