37

I was wondering if it's possible to set the width of the audio tag. It is not a supported feature by default, so "hacks" will be happily accepted.
I already tried putting them in small div's and tables, but that doesn't look very smooth... As far as I can see, I'm the only one bothering about it, but I really appreciate some help

There is no need for cross-platform/browser support; I'm happy as long as FireFox (3.6 ++) supports it.

Quick example as to what I'll be using:

<audio preload="auto" id="id12" controls="controls" onended="func12();" src="http://192.168.1.68/mymusic.wav"></audio>
robertc
  • 74,533
  • 18
  • 193
  • 177
user704063
  • 373
  • 1
  • 3
  • 4

4 Answers4

60

Set it the same way you'd set the width of any other HTML element, with CSS:

audio { width: 200px; }

Note that audio is an inline element by default in Firefox, so you might also want to set it to display: block. Here's an example.

robertc
  • 74,533
  • 18
  • 193
  • 177
21

For those looking for an inline example, here is one:

<audio controls style="width: 200px;">
   <source src="http://somewhere.mp3" type="audio/mpeg">
</audio>

It doesn't seem to respect a "height" setting, at least not awesomely. But you can always "customize" the controls but creating your own controls (instead of using the built-in ones) or using somebody's widget that similarly creates its own :)

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
2

You also can set the width of a audio tag by JavaScript:

audio = document.getElementById('audio-id');
audio.style.width = '200px';
Calvin
  • 953
  • 1
  • 9
  • 16
1

You can use html and be a boss with simple things :

<embed src="music.mp3" width="3000" height="200" controls>

Momin
  • 3,200
  • 3
  • 30
  • 48
XMMR12
  • 73
  • 9