如何在你的网页中添加背景音乐?


若要给网页添加背景音乐,使用 <embed>…</embed> 元素。同时,使用自动播放属性。这会在网页加载时在后台播放音乐。

设置 widthheight 以使播放器隐藏在网页上。loop 属性用来指定音频是否会重新开始。将音乐文件添加到服务器,并在 src 属性中提及链接。

示例

你可以尝试运行以下代码,给网页添加背景音乐

实际演示

<!DOCTYPE html>
<html>
   <head>
      <title>HTML background music</title>
   </head>
   <body>
      <p>The music is running in the background.</p>
      <p>(Song: Kalimba which is provided as a Sample Music in Windows)</p>
      <embed src="/html/Kalimba.mp3" loop="true" autostart="true" width="2" height="0">
   </body>
</html>

更新于: 13-Sep-2023

34K+ 浏览

开启您的 职业生涯

完成课程即可获得认证

开始学习
广告
© . All rights reserved.