A virtual teacher who reveals to you the great secrets of Base64

<source>

The <source> tag provides media files for <audio>, <picture>, and <video> elements. Each of these elements may contain multiple <source> tags, thereby allowing the browser to choose the best option (for example, to display larger images for high resolution screens or to play the sound file that is supported by the browser).

Below I provide some basic examples about how to embed Base64 encoded media files using the <source> tag and data URI. For more information check the element you need. Before we start, it is worth noting that sound and video files are defined via src attribute, while for images you must use the srcset attribute.

Example #1 (<audio>):

<audio controls>
  <source src="data:audio/mpeg;base64,/+MYxAAEaAIEeUAQAgBgNgP/////KQQ/////Lvrg+lcWYHgtjadzsbTq+yREu495tq9c6v/7vt/of7mna9v6/btUnU17Jun9/+MYxCkT26KW+YGBAj9v6vUh+zab//v/96C3/pu6H+pv//r/ycIIP4pcWWTRBBBAMXgNdbRaABQAAABRWKwgjQVX0ECmrb///+MYxBQSM0sWWYI4A++Z/////////////0rOZ3MP//7H44QEgxgdvRVMXHZseL//540B4JAvMPEgaA4/0nHjxLhRgAoAYAgA/+MYxAYIAAJfGYEQAMAJAIAQMAwX936/q/tWtv/2f/+v//6v/+7qTEFNRTMuOTkuNVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV" />
  The “audio” tag is not supported by your browser. Click [here] to download the sound file.
</audio>

Example #2 (<picture>):

<picture>
  <source media="(min-width:1px)" srcset="data:image/gif;base64,R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs" />
  <img src="about:blank" />
</picture>

Example #3 (<video>):

<video controls>
  <source src="data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAAu1tZGF0AAACrQYF//+p3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE1NSByMjkwMSA3ZDBmZjIyIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAxOCAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYm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AAAAAAQAAAAACgAAAAWgAAAAAAJGVkdHMAAAAcZWxzdAAAAAAAAAABAAAD6AAAAAAAAQAAAAABkG1kaWEAAAAgbWRoZAAAAAAAAAAAAAAAAAAAQAAAAEAAVcQAAAAAAC1oZGxyAAAAAAAAAAB2aWRlAAAAAAAAAAAAAAAAVmlkZW9IYW5kbGVyAAAAATttaW5mAAAAFHZtaGQAAAABAAAAAAAAAAAAAAAkZGluZgAAABxkcmVmAAAAAAAAAAEAAAAMdXJsIAAAAAEAAAD7c3RibAAAAJdzdHNkAAAAAAAAAAEAAACHYXZjMQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAACgAFoASAAAAEgAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABj//wAAADFhdmNDAWQACv/hABhnZAAKrNlCjfkhAAADAAEAAAMAAg8SJZYBAAZo6+JLIsAAAAAYc3R0cwAAAAAAAAABAAAAAQAAQAAAAAAcc3RzYwAAAAAAAAABAAAAAQAAAAEAAAABAAAAFHN0c3oAAAAAAAAC5QAAAAEAAAAUc3RjbwAAAAAAAAABAAAAMAAAAGJ1ZHRhAAAAWm1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAALWlsc3QAAAAlqXRvbwAAAB1kYXRhAAAAAQAAAABMYXZmNTguMTIuMTAw" />
  The “video” tag is not supported by your browser. Click [here] to download the video file.
</video>

Please note that Base64 Data URIs have some limitations. In addition, like almost any unconventional solutions, it has both advantages and disadvantages. Therefore, if you plan to use it, first of all, read about Base64 Data URI.

Comments (16)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • nqhXncMU,
    0yVHOhOY' OR 188=(SELECT 188 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1 OR 3+870-870-1=0+0+0+1 --
  • nqhXncMU,
    -5) OR 488=(SELECT 488 FROM PG_SLEEP(15))--
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • gBqsPxAZ,
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • gBqsPxAZ,
    -5 OR 567=(SELECT 567 FROM PG_SLEEP(15))--
  • nqhXncMU,
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • nqhXncMU,
    GiW1cyUw')) OR 444=(SELECT 444 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    -1' OR 2+818-818-1=0+0+0+1 or 'A6hDlZYO'='
  • nqhXncMU,
    H17VNGze')) OR 505=(SELECT 505 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • ncMUFCMU,
    I2NP2xgl')) OR 162=(SELECT 162 FROM PG_SLEEP(15))--
  • nqhXncMU,
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • nqhXncMU,
    XVchosM8')) OR 135=(SELECT 135 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    qZHGsBeY'; waitfor delay '0:0:15' --
  • ncMUFCMU,
    -1' OR 2+806-806-1=0+0+0+1 or 'tbh4IqYm'='
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.