HTML attribute: capture #
::: section-content
The capture
attribute specifies that, optionally, a new file should be
captured, and which device should be used to capture that new media of a
type defined by the
accept
attribute.
Values include user
and environment
. The capture attribute is
supported on the
file input type.
The capture
attribute takes as its value a string that specifies which
camera to use for capture of image or video data, if the
accept attribute indicates that the input should be of one of
those types.
Value | Description |
---|---|
user | The user-facing camera and/or microphone should be used. |
environment | The outward-facing camera and/or microphone should be used |
::: {#sect1 .notecard .note} Note: Capture was previously a Boolean attribute which, if present, requested that the device's media capture device(s) such as camera or microphone be used instead of requesting a file input. ::: :::
Try it #
::: section-content ::: iframe ::: {.output-header .border-rounded-top}
HTML Demo: capture #
Reset :::
::: {#warning-no-script .warning-container} ::: warning The interactive example cannot be shown because JavaScript is disabled. ::: :::
::: {#warning-mathml-not-supported .warning-container .hidden} ::: warning The interactive example cannot be shown because MathML is not supported by your browser. ::: :::
::: {#editor-container .editor-container .tabbed-standard .hidden .border-rounded-bottom editor-type=“tabbed”} ::: {#tab-container .section .tabs} ::: {#tablist .tab-list role=“tablist”} HTML
CSS
JavaScript :::
::: {#html-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“html” aria-hidden=“true”} ::: {#html-editor}
<input type="file" name="picture" accept="image/*" capture="user" />
<label for="voice">Record a sample of your voice:</label>
<input type="file" name="voice" accept="audio/*" capture />
::: :::
::: {#css-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“css” aria-hidden=“true”} ::: {#css-editor} label { display: block; margin-top: 1rem; }
input {
margin-bottom: 1rem;
}
::: :::
::: {#js-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“js” aria-hidden=“true”} ::: {#js-editor} ::: ::: :::
::: {#output .output-container}
Output #
::: :::
::: {.section .console-container .hidden aria-hidden=“true”}
Console Output #
![] clear console
::: {#console .console} ::: :::
::: {#html-output .output .editor-tabbed} %html-content% ::: ::: :::
Examples #
::: section-content When set on a file input type, operating systems with microphones and cameras will display a user interface allowing the selection from an existing file or the creating of a new one.
::: code-example [html]{.language-name}
<p>
<label for="soundFile">What does your voice sound like?:</label>
<input type="file" id="soundFile" capture="user" accept="audio/*" />
</p>
<p>
<label for="videoFile">Upload a video:</label>
<input type="file" id="videoFile" capture="environment" accept="video/*" />
</p>
<p>
<label for="imageFile">Upload a photo of yourself:</label>
<input type="file" id="imageFile" capture="user" accept="image/*" />
</p>
:::
::: {#sect2 .code-example} ::: iframe ::: :::
Note these work better on mobile devices; if your device is a desktop computer, you'll likely get a typical file picker. :::
Specifications #
::: _table #
Specification #
HTML Media Capture
[#
dfn-capture]{.small}
:::
Browser compatibility #
::: _table Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
capture
No No No No No No 4.4 25 79 14 10 1.5
:::
See also #
::: section-content
::: _attribution
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5
or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture{._attribution-link}
:::