Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h2>Test User Media</h2>
<video id="user-media" autoplay playsinline></video>
<a href="#start-video">Start camera</a>

<h2>Normal Input File</h2>
<label>
  Normal file input
  <input type="file">
</label>

<h2>Test Capture Input</h2>
<label>
  File with capture
  <input id="take-picture" type="file" accept="image/*" capture="camera" >
</label>

<label>
  Normal file input with accept
  <input type="file" accept="text/*">
</label>

<label>
  Normal file input
  <input type="file" >
</label>
<label>
  Files with Capture
  <input type="file" accept="image/*" capture="camera" multiple="multiple">
</label>
<label>
  Normal files input
  <input type="file" multiple="multiple" >
</label>
<label>
  Video capture
  <input type="file" accept="video/*" capture="camcorder">
</label>
<label>
  Audio capture
  <input type="file" accept="audio/*" capture="microphone">
</label>

<img id="show-picture">



              
            
!

CSS

              
                label {
  display: block;
  padding: 2em;
  margin: 2em;
  background: lightyellow;
  border: 1px solid orange;
  border-radius: 5px;
}
label input {
  opacity: 0.1;
}
img,
video {
  display: block;
  max-width: 80%;
  margin: auto;
}
video {
  // display: none;
  // position: absolute;
  // width: 50px;
  // height: 50px;
  // opacity: 0.1;
}
              
            
!

JS

              
                /* Code example from Mozilla: https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/API/Camera_API/Introduction */
var takePicture = document.querySelector("#take-picture");
takePicture.onchange = function (event) {
  // Get a reference to the taken picture or chosen file
  var files = event.target.files,
      file;
  if (files && files.length > 0) {
      file = files[0];
  }
  
  // Image reference
  var showPicture = document.querySelector("#show-picture");

  // Create ObjectURL
  var imgURL = window.URL.createObjectURL(file);

  // Set img src to ObjectURL
  showPicture.src = imgURL;

  // For performance reasons, revoke used ObjectURLs
  URL.revokeObjectURL(imgURL);
};

// Get User Media
const constraints = {
  video: true,
  audio: true
};

document.querySelector('a[href="#start-video"]').addEventListener('click', ()=>{
  const video = document.querySelector('video#user-media');

  navigator.mediaDevices.getUserMedia(constraints).
    then((stream) => {video.srcObject = stream});
  
});


// Un-comment the following code with caution. It starts camera access right away.
// const video = document.querySelector('video#user-media');
// navigator.mediaDevices.getUserMedia(constraints).
//     then((stream) => {video.srcObject = stream});
              
            
!
999px

Console