Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The createDataChannel() method of the RTCPeerConnection interface creates a new channel linked with the remote peer, over which any kind of data may be transmitted. This can be useful for back-channel content, such as images, file transfer, text chat, game update packets, and so forth.
If the new data channel is the first one added to the connection, renegotiation is started by delivering a negotiationneeded event.
A human-readable name for the channel. This string may not be longer than 65,535 bytes.
options OptionalAn object providing configuration options for the data channel. It can contain the following fields:
ordered OptionalIndicates whether or not messages sent on the RTCDataChannel are required to arrive at their destination in the same order in which they were sent (true), or if they're allowed to arrive out-of-order (false). Default: true.
maxPacketLifeTime OptionalThe maximum number of milliseconds that attempts to transfer a message may take in unreliable mode. While this value is a 16-bit unsigned number, each user agent may clamp it to whatever maximum it deems appropriate. Default: null.
maxRetransmits OptionalThe maximum number of times the user agent should attempt to retransmit a message which fails the first time in unreliable mode. While this value is a 16-bit unsigned number, each user agent may clamp it to whatever maximum it deems appropriate. Default: null.
protocol OptionalThe name of the sub-protocol being used on the RTCDataChannel, if any; otherwise, the empty string (""). Default: empty string (""). This string may not be longer than 65,535 bytes.
negotiated OptionalBy default (false), data channels are negotiated in-band, where one side calls createDataChannel, and the other side listens to the RTCDataChannelEvent event using the ondatachannel event handler. Alternatively (true), they can be negotiated out of-band, where both sides call createDataChannel with an agreed-upon ID. Default: false.
id OptionalA 16-bit numeric ID for the channel; permitted values are 0 to 65534. If you don't include this option, the user agent will select an ID for you.
Note: These options represent the script-settable subset of the properties on the RTCDataChannel interface.
A new RTCDataChannel object with the specified label, configured using the options specified by options if that parameter is included; otherwise, the defaults listed above are established.
Thrown if the RTCPeerConnection is closed.
TypeErrorThrown in the following situations:
Thrown if values were specified for both the maxPacketLifeTime and maxRetransmits options. You may specify a non-null value for only one of these.
ResourceInUse DOMExceptionThrown if an id was specified, but another RTCDataChannel is already using the same value.
OperationError DOMExceptionThrown if either the specified id is already in use, or if no id was specified, the WebRTC layer was unable to automatically generate an ID because all IDs are in use.
This example shows how to create a data channel and set up handlers for the open and message events to send and receive messages on it (For brevity, the example assumes onnegotiationneeded is set up).
Alternatively, more symmetrical out-of-band negotiation can be used, using an agreed-upon id (0 here):
For a more thorough example showing how the connection and channel are established, see A simple RTCDataChannel sample.
| WebRTC: Real-Time Communication in Browsers # dom-peerconnection-createdatachannel |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jun 23, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.