Tuesday, 16 July 2024

Write the html program to create sound

 Creating a simple HTML program to play sound involves using the `<audio>` tag. Here's a basic example:


```html

<!DOCTYPE html>

<html>

<head>

    <title>Play Sound</title>

</head>

<body>

    <h1>Play Sound Example</h1>

    

    <!-- Audio controls -->

    <audio controls>

        <source src="path_to_your_audio_file.mp3" type="audio/mpeg">

        Your browser does not support the audio element.

    </audio>


    <!-- Auto play the sound -->

    <audio autoplay>

        <source src="path_to_your_audio_file.mp3" type="audio/mpeg">

        Your browser does not support the audio element.

    </audio>

</body>

</html>

```


In this example:


1. The `<audio>` element is used to embed sound content in the HTML document.

2. The `controls` attribute adds play, pause, and volume controls.

3. The `autoplay` attribute plays the audio automatically when the page loads.

4. The `<source>` element specifies the path to the audio file. Replace `path_to_your_audio_file.mp3` with the actual path to your audio file.

5. The `type` attribute specifies the MIME type of the audio file.


Save this code as an HTML file and open it in a web browser to see it in action. Make sure to replace `path_to_your_audio_file.mp3` with the actual path to your audio file.

No comments:

Post a Comment