Is it possible to style html5 audio tag?

HtmlAudio

Html Problem Overview


I haven't found any resources on how to do that. Something as simple as changing the color of the player would be nice to have :)

Html Solutions


Solution 1 - Html

Yes: you can hide the built-in browser UI (by removing the controls attribute from audio) and instead build your own interface and control the playback using Javascript (source):

<audio id="player" src="vincent.mp3"></audio>
<div> 
  <button onclick="document.getElementById('player').play()">Play</button> 
  <button onclick="document.getElementById('player').pause()">Pause</button> 
  <button onclick="document.getElementById('player').volume += 0.1">Vol +</button> 
  <button onclick="document.getElementById('player').volume -= 0.1">Vol -</button> 
</div>

You can then style the elements however you wish using CSS.

MDN HTMLAudioElement API reference

Solution 2 - Html

<audio>

audio::-webkit-media-controls-panel

audio::-webkit-media-controls-mute-button

audio::-webkit-media-controls-play-button

audio::-webkit-media-controls-timeline-container

audio::-webkit-media-controls-current-time-display

audio::-webkit-media-controls-time-remaining-display

audio::-webkit-media-controls-timeline

audio::-webkit-media-controls-volume-slider-container

audio::-webkit-media-controls-volume-slider

audio::-webkit-media-controls-seek-back-button

audio::-webkit-media-controls-seek-forward-button

audio::-webkit-media-controls-fullscreen-button

audio::-webkit-media-controls-rewind-button

audio::-webkit-media-controls-return-to-realtime-button

audio::-webkit-media-controls-toggle-closed-captions-button

REFERENCE: https://chromium.googlesource.com/chromium/blink/+/72fef91ac1ef679207f51def8133b336a6f6588f/Source/core/css/mediaControls.css?autodive=0%2F%2F%2F

Solution 3 - Html

Yes! The HTML5 audio tag with the "controls" attribute uses the browser's default player. You can customize it to your liking by not using the browser controls, but rolling your own controls and talking to the audio API via javascript.

Luckily, other people have already done this. My favorite player right now is jPlayer, it is very stylable and works great. Check it out.

Solution 4 - Html

The appearance of the tag is browser-dependent, but you can hide it, build your own interface and control the playback using Javascript.

Solution 5 - Html

some color tunings

audio {
    filter: sepia(20%) saturate(70%) grayscale(1) contrast(99%) invert(12%);
    width: 200px;
    height: 25px;
}

Solution 6 - Html

Ken had it right as well.

a css tag:

audio {

}

will get you some results. seems it doesnt want the player any height above or below 25px but the width can be shortened or lengthened to an extent.

this was good enough for me; see this example (warning, audio plays automatically): www.thenewyorkerdeliinc.com

Solution 7 - Html

Missing the most important one IMO the container for the controls ::-webkit-media-controls-enclosure:

&::-webkit-media-controls-enclosure {
	border-radius: 5px;
    background-color: green;
}

Solution 8 - Html

To change just the colour of the player, simply address the audio tag in your css file, for instance on one of my sites the player became invisible (white on white) so I added:

audio {
    background-color: #95B9C7;
}

This changed the player to light blue.

Solution 9 - Html

Yes, it's possible, from @Fábio Zangirolami answer

audio::-webkit-media-controls-panel, video::-webkit-media-controls-panel {
			    background-color: red;
}

Solution 10 - Html

If you are using Chrome, turned on "Show user agent shadow DOM" in Chrome Dev Tool settings

Show user agent shadow DOM

Now you'll able to see all the pseudos

audio::-webkit-media-controls-panel

audio::-webkit-media-controls-mute-button

audio::-webkit-media-controls-play-button

...

enter image description here

and now you can style them

audio::-webkit-media-controls-mute-button {
  display: none;
}

Solution 11 - Html

I did some customizations on the Audio component. Here is what i did.

audio {
/*border-radius: 90px;*/
width: 250px;
height: 45px;
margin-top: 5px;
margin-bottom: 5px;
}

audio::-webkit-media-controls-mute-button {
display: none !important;
}

audio::-webkit-media-controls-volume-slider {
display: none !important;
}

audio::-webkit-media-controls-volume-control-container.closed {
display: none !important;
}
audio::-webkit-media-controls-volume-control-container{
display: none !important;
}

I found that these customizations only works for Edge and Chrome. Not Firefox..

Solution 12 - Html

You can use HTMLMediaElement Api to create your own audioplayer with html/css. It is likely the only option. Because the default player can't be styled.

Solution 13 - Html

If you want to style the browsers standard music player in the CSS:

audio {
    enter code here;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionrabidmachine9View Question on Stackoverflow
Solution 1 - Htmlgilad905View Answer on Stackoverflow
Solution 2 - HtmlFábio ZangirolamiView Answer on Stackoverflow
Solution 3 - HtmlBennyView Answer on Stackoverflow
Solution 4 - HtmlMihaiView Answer on Stackoverflow
Solution 5 - HtmlArthur VeselovView Answer on Stackoverflow
Solution 6 - HtmlNickView Answer on Stackoverflow
Solution 7 - HtmlStefanBobView Answer on Stackoverflow
Solution 8 - HtmlKarinView Answer on Stackoverflow
Solution 9 - HtmlHernán EcheView Answer on Stackoverflow
Solution 10 - HtmlAlex GView Answer on Stackoverflow
Solution 11 - HtmlKul Bhushan PrasadView Answer on Stackoverflow
Solution 12 - HtmlErnest RutherfordView Answer on Stackoverflow
Solution 13 - HtmlKenneth KlippertView Answer on Stackoverflow