To add background sound to an HTML page, you can use the <audio> tag. Here's an example:

<!DOCTYPE html>
<html>
<head>
    <title>Background Sound Example</title>
</head>
<body>
    <audio src='path/to/sound.mp3' autoplay loop>
        Your browser does not support the audio element.
    </audio>
    
    <h1>Welcome to my website!</h1>
    <p>This is an example of background sound.</p>
</body>
</html>

In the example above, replace 'path/to/sound.mp3' with the actual path to your audio file. The autoplay attribute makes the audio play automatically when the page loads, and the loop attribute makes it repeat continuously. The text between the <audio> tags is shown in case the browser doesn't support the audio element.

Note: Autoplaying audio is often considered a bad user experience, so it's recommended to check if the sound can be played without user interaction and provide a control for the user to enable or disable the sound.

How to Add Background Sound to Your HTML Website

原文地址: https://www.cveoy.top/t/topic/iFPr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录