Mobile Camera Integration
What you'll learn: How to use the capture attribute to let mobile users access their device camera or microphone directly from a file input.
The Problem on Mobile
On mobile devices, users often want to take a photo right now rather than dig through their camera roll. The standard file input works, but it typically opens the file picker first. The capture attribute tells mobile browsers: "Give the user direct camera access as the primary option."
How It Works
The capture attribute is added to file inputs that accept image, video, or audio types. It has three possible values:
capture="user"– Use the front-facing (selfie) cameracapture="environment"– Use the rear-facing cameracapture(no value) – Let the browser decide
Think of capture as a shortcut button: instead of opening the file manager, it opens the camera app directly—like having an express lane to the camera.
<!-- Direct access to rear camera for photos -->
<input type="file" accept="image/*" capture="environment">
<!-- Direct access to front camera for videos -->
<input type="file" accept="video/*" capture="user">
<!-- Direct audio recording -->
<input type="file" accept="audio/*" capture>
Browser Behavior
On desktop browsers, capture is typically ignored—the standard file picker appears. On mobile, it shortcuts to the camera/microphone interface. Users can usually still access their existing files if they cancel the camera.
This is progressive enhancement: mobile users get a streamlined experience, while desktop users get the standard behavior.
Key Takeaway: The capture attribute provides direct camera or microphone access on mobile devices, creating a faster, more intuitive upload experience without requiring complex JavaScript APIs.