Melon created a little premade scrip that played midi's, if you just want a simple copy-paste solution, have a look here!
Often you'll want to convert the midi to a compressed mp3 using your preferred instrument set: a great free program is GSXCC, this is a program that emulates a Famicom (NES) or SCC sound chip in order to play MIDIs. It can make any MIDI file into chiptunes! You can download it here!
You can also embed midis directly into a browser using MIDIjs:
Include the MIDIjs script on your web page (put this in the head). You can download the script to your site or use this hotlink:
<script src="https://www.midijs.net/lib/midi.js"></script>
Play or stop the MIDI file. You can use the MIDIjs.play() and MIDIjs.stop() functions to play or stop the MIDI file. For example, you can use this code to play the MIDI file:
MIDIjs.play("song.mid");
And this code to stop the MIDI file:
MIDIjs.stop();