media capture with HTML

The HTML capture attribute lets users record new mediaโ€”photos, videos, or audioโ€”using their deviceโ€™s camera or mic, instead of selecting an existing file. Itโ€™s especially useful on mobile devices.


โš™๏ธ How It Works

Use the capture attribute with:

<input type="file" capture accept="media-type/*">

โœ… Combined with the accept attribute, it lets users:

  • Record new media using their camera or microphone
  • Choose between capturing new media or uploading existing files

๐Ÿ“ฒ Capture Settings

Use these values for the capture attribute:

  1. user โ€“ Front-facing camera or mic (great for selfies or voice)
  2. environment โ€“ Back-facing camera (for surroundings or landscape shots)

๐Ÿงช Examples

๐ŸŽค Record Audio

<input type="file" capture="user" accept="audio/*">

โžก๏ธ Opens mic for voice recording.


๐Ÿ“ท Take a Photo

<input type="file" capture="user" accept="image/*">

โžก๏ธ Opens front camera for selfies.


๐ŸŽฌ Record Video

<input type="file" capture="environment" accept="video/*">

โžก๏ธ Opens back camera for videos.


๐Ÿ› ๏ธ When to Use

Perfect for:

  • Forms needing image/audio/video input
  • Surveys with real-time responses
  • Mobile apps that need media uploads

๐Ÿ“Œ Notes

  • Best on phones or tablets
  • On desktops, it may open the file picker instead

๐Ÿ”— Conclusion

Try the demo ๐Ÿ‘‰ Example Code

The capture attribute adds a smooth, interactive media upload experience to your HTML forms. Give it a go!


<
Previous Post
๐Ÿ”ง Unlock the Power of JavaScriptโ€™s replace() Function
>
Next Post
๐Ÿ“ธ Bard Goes Beyond Text: How Images Now Enhance Your Experience