lues of the key/value pairs contained in this object.

**Note:** To be clear, the difference between [ ` Headers.set() ` ](/en-
US/docs/Web/API/Headers/set) and [ ` Headers.append() ` ](/en-
US/docs/Web/API/Headers/append) is that if the specified header does already
exist and does accept multiple values, [ ` Headers.set() ` ](/en-
US/docs/Web/API/Headers/set) will overwrite the existing value with the new
one, whereas [ ` Headers.append() ` ](/en-US/docs/Web/API/Headers/append) will
append the new value onto the end of the set of values. See their dedicated
pages for example code.

**Note:** All of the Headers methods will throw a [ ` TypeError ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) if you try to pass
in a reference to a name that isn't a [ valid HTTP Header name
](https://fetch.spec.whatwg.org/#concept-header-name) . The mutation
operations will throw a ` TypeError ` if the header has an immutable [ Guard
](/en-US/docs/Glossary/Guard) . In any other failure case they fail silently.

**Note:** When Header values are iterated over, they are automatically sorted
in lexicographical order, and values from duplicate header names are combined.

##  Examples

In the following snippet, we create a new header using the ` Headers() `
constructor, add a new header to it using ` append() ` , then return that
header value using ` get() ` :

js

    
    
    const myHeaders = new Headers();
    
    myHeaders.append("Content-Type", "text/xml");
    myHeaders.get("Content-Type"); // should return 'text/xml'
    

The same can be achieved by passing an array of arrays or an object literal to
the constructor:

js

    
    
    let myHeaders = new Headers({
      "Content-Type": "text/xml",
    });
    
    // or, using an array of arrays:
    myHeaders = new Headers([["Content-Type", "text/xml"]]);
    
    myHeaders.get("Content-Type"); // should return 'text/xml'
    

##  Specifications

Specification  
---  
[ Fetch Standard  
#  headers-class  ](https://fetch.spec.whatwg.org/#headers-class)  
  
##  Browser compatibility

BCD tables only load in the browser  with JavaScript enabled. Enable
JavaScript to view data.

##  See also

  * [ ServiceWorker API ](/en-US/docs/Web/API/Service_Worker_API)
  * [ HTTP access control (CORS) ](/en-US/docs/Web/HTTP/CORS)
  * [ HTTP ](/en-US/docs/Web/HTTP)

##  Help improve MDN

Was this page helpful to you?

Yes  No

[ Learn how to contribute
](https://github.com/mdn/content/blob/main/CONTRIBUTING.md "This will take you
to our contribution guidelines on GitHub.") .

This page was last modified on  Mar 6, 2024  by  [ MDN contributors ](/en-
US/docs/Web/API/Headers/contributors.txt) .

[ View this page on GitHub
](https://github.com/mdn/content/blob/main/files/en-
us/web/api/headers/index.md?plain=1 "Folder: en-us/web/api/headers \(Opens in
a new tab\)") â¢  [ Report a problem with this content
](https://github.com/mdn/content/issues/new?template=page-report.yml&mdn-
url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FAPI%2FHeaders&metadata=%3C%21--+Do+not+make+changes+below+this+line+--%3E%0A%3Cdetails%3E%0A%3Csummary%3EPage+report+details%3C%2Fsummary%3E%0A%0A*+Folder%3A+%60en-
us%2Fweb%2Fapi%2Fheaders%60%0A*+MDN+URL%3A+https%3A%2F%2Fdeveloper.mozilla.org%2Fen-
US%2Fdocs%2FWeb%2FAPI%2FHeaders%0A*+GitHub+URL%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fblob%2Fmain%2Ffiles%2Fen-
us%2Fweb%2Fapi%2Fheaders%2Findex.md%0A*+Last+commit%3A+https%3A%2F%2Fgithub.com%2Fmdn%2Fcontent%2Fcommit%2F2c641e08878722bf29fb784d58c61873ce4a133a%0A*+Document+last+modified%3A+2024-03-06T05%3A58%3A29.000Z%0A%0A%3C%2Fdetails%3E
"This will take you to GitHub to file a new issue.")

[ MDN logo  ](/)

Your blueprint for a better internet.

  * [ MDN on Mastodon  ](https://mozilla.social/@mdn)
  * [ MDN on X (formerly Twitter)  ](https://twitter.com/mozdevnet)
  * [ MDN on GitHub  ](https://github.com/mdn/)
  * [ MDN Blog RSS Feed  ](/en-US/blog/rss.xml)

##  MDN

  * [ About ](/en-US/about