Nicolas
Nicolas

Reputation: 21

how do i make a video play with no sound until clicked on in html?

I have searched everywhere and can not find a way to make a video in html play with no sound until clicked on kinda like Facebook.

Upvotes: 0

Views: 823

Answers (1)

Michael Coker
Michael Coker

Reputation: 53674

The autoplay attribute will autoplay a video, and the muted attribute will mute a video by default. So that will play the video with no sound. Then you can assign a JS click handler to the video and turn off muting by setting video.muted = false

var video = document.getElementById('video');
video.addEventListener('click',function() {
  video.muted = false;
});
<video id="video" src="http://www.w3schools.com/html/mov_bbb.mp4" autoplay muted controls></video>

Upvotes: 5

Related Questions