Home > Software engineering >  Can i play an audio on hover in css without JS?
Can i play an audio on hover in css without JS?

Time:12-08

<!DOCTYPE html>
<html>
  <head>
    <title>game</title>
    <meta charset="UTF-8" />
    <meta name="description" content="the description of my website" />
    <link rel="stylesheet" href="main.css" />
    <link rel="icon" href="" type="image/x-icon" />
  </head>
  <body>
    <h1>Hover me !</h1>
    <img src="/a.png" alt="" />
  </body>
</html>

i tried to make audio visibilty and when i hover a photo add auto play atrr but i don't know how !

Notice "i only know HTML & CSS" Thx :)

CodePudding user response:

No.

CSS has no features that can trigger an audio player.

CodePudding user response:

It is not possible to play a sound on hover with CSS.

You need to access a specific function to trigger the play() function.

Here is a simple article https://css-tricks.com/play-sound-on-hover/

CodePudding user response:

you can use the autoplay like this

<audio controls autoplay>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
The browser does not support the audio element.
</audio>
  • Related