Home > Tips & Tricks > How to Open Phone Camera Using HTML?

How to Open Phone Camera Using HTML?

Hello friends, if you are working on a mobile device project and you want to capture a photo or video of a user by accessing their phone camera?

So you are at the right place. In this trick, I will show you how you can open the phone camera using the HTML tag.

Open Users Phone’s Camera Using HTML

To open the phone device camera using HTML, you have to make an input type field with some special attributes. Those attributes will allow opening the user’s mobile device camera instead of selecting an image or video.

Attributes:

type: file => used to select the image or video
capture: environment | user => used to capture the image or video
accept: image | video => used to allow image or video

So these attributes in <input> tag will allow to capture the image or video using the capture attribute and accept the image or video using the accept attribute. And default behavior will kept uploading the file with type attribute.

To open back facing camera to capture the image

To open back facing camera to capture a video

Note: In the above lines of code we used the /* which means that it will accept any type of image or video captured through any mobile device.

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment