HTML-JavaScript WebCam Access API

This is a simple html code with code snippet of the javascript for accessing the webcam of you laptop (Mac/Windows/Linux-Fedora/Ubuntu)



<meta charset=”utf-8" />

<title>::| |:: Webcam-access</title>


#videoElement {

border: 30px solid #ccc;

background: green;

width: 400px;

height: 400px





<button>Start camera</button>


<video autoplay=”true” id=”videoElement”></video>

<script type=”text/javascript”>

var video = document.querySelector(“#videoElement”);

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUsermedia

|| navigator.mozGetUserMedia || navigato.msGetUserMedia || navigator.oGetUserMedia;


navigator.getUserMedia({video:true}, handleVideo, videoError)


function handleVideo(stream){

video.srcObject = stream;;


function videoError(e){}






Technology Enthusiast and Open Source Technology advocate

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store