Categories
JavaScript Answers

How to set volume of audio element with JavaScript?

Spread the love

Sometimes, we want to set volume of audio element with JavaScript.

In this article, we’ll look at how to set volume of audio element with JavaScript.

How to set volume of audio element with JavaScript?

To set volume of audio element with JavaScript, we set its volume property.

For instance, we write

const audio = new Audio("test.wav");
audio.volume = 0.2;

to create an Audio object.

Then we set its volume property to set the volume level.

Conclusion

To set volume of audio element with JavaScript, we set its volume property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *