Blob: slice() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Note: This feature is available in Web Workers.

The slice() method of the Blob interface creates and returns a new Blob object which contains data from a subset of the blob on which it's called.

Syntax

js
slice()
slice(start)
slice(start, end)
slice(start, end, contentType)

Parameters

start Optional

An index into the Blob indicating the first byte to include in the new Blob. If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob. The default value is 0. If you specify a value for start that is larger than the size of the source Blob, the returned Blob has size 0 and contains no data.

end Optional

An index into the Blob indicating the first byte that will not be included in the new Blob (i.e., the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob. The default value is size.

contentType Optional

The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string.

Return value

A new Blob object containing the specified subset of the data contained within the blob on which this method was called. The original blob is not altered.

Specifications

Specification
File API
# dfn-slice

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
slice()
Chrome – No support
Chrome 5 – 24 (Release date: 2010-05-25)
prefix
footnote Removed in 25 and later
prefix Implemented with the vendor prefix: webkit
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote Full support
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – No support
Firefox 5 – 12 (Release date: 2011-06-21)
prefix
prefix Implemented with the vendor prefix: moz
Firefox – Full support
Firefox 13 (Release date: 2012-06-05)
footnote
footnote Before Firefox 12, there was a bug that affected the behavior of Blob.slice(); it did not work for start and end positions outside the range of signed 64-bit values; it has now been fixed to support unsigned 64-bit values.
Opera – Full support
Opera 12 (Release date: 2012-06-14)
footnote Full support
Safari – No support
Safari 6 – 6 (Release date: 2012-07-25)
prefix
prefix Implemented with the vendor prefix: webkit
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – No support
Chrome Android 18 – 18 (Release date: 2012-06-27)
prefix
prefix Implemented with the vendor prefix: webkit
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote Full support
Firefox for Android – No support
Firefox for Android 5 – 10 (Release date: 2011-06-21)
prefix
prefix Implemented with the vendor prefix: moz
Firefox for Android – Full support
Firefox for Android 14 (Release date: 2012-06-26)
footnote
footnote Before Firefox for Android 14, there was a bug that affected the behavior of Blob.slice(); it did not work for start and end positions outside the range of signed 64-bit values; it has now been fixed to support unsigned 64-bit values.
Opera Android – Full support
Opera Android 12 (Release date: 2012-02-25)
footnote Full support
Safari on iOS – No support
Safari on iOS 6 – 6 (Release date: 2012-09-10)
prefix
prefix Implemented with the vendor prefix: webkit
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – No support
Samsung Internet 1 – 1 (Release date: 2013-04-27)
prefix
prefix Implemented with the vendor prefix: webkit
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote Full support
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – No support
WebView on iOS 6 – 6 (Release date: 2012-09-10)
prefix
prefix Implemented with the vendor prefix: webkit
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – No support
Node.js 14.18 – 14.18 (Release date: 2021-09-28)
footnote Removed in 15 and later
Node.js – Full support
Node.js 15.7 (Release date: 2021-01-26)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also