Welcome to Part 1 of the Ultimate Music Player tutorial series! In this post, we’ll create a super simple HTML5 music player that:

✅ Plays one song
✅ Has Play, Pause, and Stop buttons
✅ Uses clean HTML, CSS, and a bit of JavaScript
✅ Works in any modern browser

🧠 Goal: Build the foundation before adding advanced features (like playlists, shuffle, categories, and visualizers in later posts).


📁 Step 1: Setup Your Project Folder

Create a new folder named:

html5-music-player-part1/

 

Inside it, place:

  • index.html → (you’ll write the code below in this file)

  • music.mp3 → (your chosen MP3 file)


🧱 Step 2: Write the HTML

html

<!DOCTYPE html>

<html lang=“en”>

<head>

<meta charset=“UTF-8”>

<title>Mini Music Player</title>

<style>

body {

background: #111;

color: white;

font-family: Arial, sans-serif;

text-align: center;

padding: 50px;

}

.player {
background: #1e1e1e;
padding: 30px;
border-radius: 12px;
max-width: 400px;
margin: auto;
}

button {
padding: 10px 15px;
margin: 10px;
font-size: 16px;
background: #333;
border: none;
border-radius: 6px;
color: white;
cursor: pointer;
}

button:hover {
background: #555;
}
</style>
</head>
<body>

<h1>🎵 Mini Music Player</h1>

<div class=“player”>
<p>Now Playing: <strong>music.mp3</strong></p>
<audio id=“audioPlayer” src=“music.mp3” preload=“metadata”></audio>

<div>
<button onclick=“playAudio()”>▶️ Play</button>
<button onclick=“pauseAudio()”>⏸️ Pause</button>
<button onclick=“stopAudio()”>⏹️ Stop</button>
</div>
</div>

<script>
const audio = document.getElementById(‘audioPlayer’);

function playAudio() {
audio.play();
}

function pauseAudio() {
audio.pause();
}

function stopAudio() {
audio.pause();
audio.currentTime = 0;
}
</script>

</body>
</html>


🧪 Step 3: Test It Out

  1. Place your music.mp3 file in the same folder.

  2. Open index.html in your browser.

  3. Click ▶️ Play, ⏸️ Pause, and ⏹️ Stop.

💡 TIP: If it doesn’t work, open your browser’s dev tools (F12) and check the Console for errors like “file not found.”


📝 What You Learned

  • ✅ Using the <audio> tag to embed music

  • ✅ How to control audio playback using JavaScript

  • ✅ Styling a basic interface with CSS

  • ✅ Structuring HTML for a player layout


🧭 What’s Next?

In Part 2, you’ll learn how to build a playlist using a list of songs — each clickable and dynamically loaded into the player.

🔜 Coming Up:

  • Multiple songs

  • Click-to-play

  • Dynamic title updates