The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →To create a custom audio player, keep an HTML <audio> element as the playback source and build accessible buttons and sliders that control it with JavaScript. The example below adds play/pause, seeking, elapsed and total time, volume, repeat, format fallbacks, and a download link.
Choose native controls or build your own
The <audio> element embeds sound in a page. With the controls attribute, the browser supplies a player; without it, the browser’s default controls are omitted and you can create your own interface. Native controls are quicker to implement, while authored controls give you more control over appearance and behavior—and make you responsible for keyboard access, accessible names, visible focus, and keeping the interface synchronized with playback.
For the custom version below, the audio element remains the source of truth. The buttons and sliders call its methods or update in response to its media events.
Add the player’s HTML
Replace the example filenames with audio files hosted at URLs your page can access. The browser tries the listed sources in order, using their MIME types to identify the formats. The download link gives visitors another way to access the recording.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Pro performance with great pre-amps - Achieve a brighter recording thanks to the high performing mic pre-amps of the Scarlett 3rd Gen. A switchable Air mode will add extra clarity to your acoustic instruments when recording with your Solo 3rd Gen
- Get the perfect guitar and vocal take with - With two high-headroom instrument inputs to plug in your guitar or bass so that they shine through. Capture your voice and instruments without any unwanted clipping or distortion thanks to our Gain Halos
- Studio quality recording for your music & podcasts - Achieve pro sounding recordings with Scarlett 3rd Gen’s high-performance converters enabling you to record and mix at up to 24-bit/192kHz. Your recordings will retain all of their sonic qualities
- Low-noise for crystal clear listening - 2 low-noise balanced outputs provide clean audio playback with 3rd Gen. Hear all the nuances of your tracks or music from Spotify, Apple & Amazon Music. Plug-in headphones for private listening in high-fidelity
- Everything in the box: Includes Pro Tools Intro+, Ableton Live Lite, Cubase LE, and Hitmaker Expansion: a suite of essential effects, powerful software instruments, and easy-to-use mastering tools
<div class="audio-player">
<audio id="audio" preload="metadata">
<source src="/audio/example.opus" type="audio/ogg; codecs=opus">
<source src="/audio/example.mp3" type="audio/mpeg">
Your browser does not support embedded audio.
</audio>
<button id="play-button" type="button" aria-label="Play audio">Play</button>
<label for="seek-slider">Playback position</label>
<input id="seek-slider" type="range" min="0" max="0" value="0" step="0.1">
<div><span id="current-time">0:00</span> /
<span id="duration">0:00</span></div>
<label for="volume-slider">Volume</label>
<input id="volume-slider" type="range" min="0" max="1" value="1" step="0.01">
<button id="repeat-button" type="button" aria-pressed="false">Repeat off</button>
<a href="/audio/example.mp3" download>Download audio</a>
</div>
The first source is an Opus file served with an Ogg/Opus MIME type; the second is MP3. Keep each source’s type accurate and include alternatives appropriate for your audience. If you use a different format or container, use its corresponding MIME type. The text inside <audio> is a basic fallback for browsers that do not support the element; the separate download link is useful for visitors who prefer to save the file.
Style the controls and focus state
Keep controls large enough to operate and make keyboard focus visible. This small stylesheet gives the player a simple layout; adjust the colors and spacing to match your site.
Rank #2
- The new generation of the songwriter's interface: Plug in your mic and guitar and let Scarlett Solo 4th Gen bring big studio sound to wherever you make music
- Studio-quality sound: With a huge 120dB dynamic range, the newest generation of Scarlett uses the same converters as Focusrite’s flagship interfaces, found in the world's biggest studios
- Find your signature sound: Scarlett 4th Gen's improved Air mode lifts vocals and guitars to the front of the mix, adding musical presence and rich harmonic drive to your recordings
- All you need to record, mix and master your music: Includes industry-leading recording software and a full collection of record-making plugins
- Everything in the box: Includes Pro Tools Intro+, Ableton Live Lite, Cubase LE, and Hitmaker Expansion: a suite of essential effects, powerful software instruments, and easy-to-use mastering tools
.audio-player {
display: grid;
gap: 0.75rem;
max-width: 32rem;
padding: 1rem;
border: 1px solid #bbb;
border-radius: 0.5rem;
}
.audio-player button,
.audio-player input,
.audio-player a {
font: inherit;
}
.audio-player button:focus-visible,
.audio-player input:focus-visible,
.audio-player a:focus-visible {
outline: 3px solid #175dcc;
outline-offset: 3px;
}
.audio-player input[type="range"] {
width: 100%;
}
Connect playback, seeking, time, volume, and repeat
Save this JavaScript in a script loaded after the markup, or run it after the page’s DOM has loaded. The play() method returns a promise, so the example handles a rejected play request instead of assuming playback always starts. Media events update the interface when playback starts, pauses, reaches the end, or loads its metadata.
const audio = document.querySelector("#audio");
const playButton = document.querySelector("#play-button");
const seekSlider = document.querySelector("#seek-slider");
const volumeSlider = document.querySelector("#volume-slider");
const currentTimeLabel = document.querySelector("#current-time");
const durationLabel = document.querySelector("#duration");
const repeatButton = document.querySelector("#repeat-button");
function formatTime(seconds) {
if (!Number.isFinite(seconds) || seconds < 0) return "0:00";
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}:${String(remainingSeconds).padStart(2, "0")}`;
}
function updatePlayButton() {
const isPlaying = !audio.paused && !audio.ended;
playButton.textContent = isPlaying ? "Pause" : "Play";
playButton.setAttribute("aria-label", isPlaying ? "Pause audio" : "Play audio");
}
playButton.addEventListener("click", async () => {
if (audio.paused || audio.ended) {
try {
await audio.play();
} catch (error) {
console.error("Audio could not be played:", error);
}
} else {
audio.pause();
}
});
audio.addEventListener("play", updatePlayButton);
audio.addEventListener("pause", updatePlayButton);
audio.addEventListener("ended", () => {
audio.currentTime = 0;
updatePlayButton();
updateProgress();
});
audio.addEventListener("loadedmetadata", () => {
seekSlider.max = Number.isFinite(audio.duration) ? audio.duration : 0;
durationLabel.textContent = formatTime(audio.duration);
updateProgress();
});
audio.addEventListener("timeupdate", updateProgress);
audio.addEventListener("seeking", updateProgress);
audio.addEventListener("seeked", updateProgress);
function updateProgress() {
currentTimeLabel.textContent = formatTime(audio.currentTime);
seekSlider.value = audio.currentTime;
}
seekSlider.addEventListener("input", () => {
audio.currentTime = Number(seekSlider.value);
});
volumeSlider.addEventListener("input", () => {
audio.volume = Number(volumeSlider.value);
});
repeatButton.addEventListener("click", () => {
audio.loop = !audio.loop;
repeatButton.setAttribute("aria-pressed", String(audio.loop));
repeatButton.textContent = audio.loop ? "Repeat on" : "Repeat off";
});
How the controls stay in sync
play()andpause()start or stop playback. The play and pause events update the button label and accessible name.loadedmetadatasupplies the duration when available;timeupdate,seeking, andseekedkeep the displayed time and seek slider aligned with playback.- Changing the seek slider sets
currentTime. Changing the volume slider setsvolume, whose value ranges from 0 to 1. - The repeat button toggles the element’s
loopproperty. Onended, the example resets the displayed position and button state.
For recordings with an unknown or indefinite duration, duration may not be a finite number. The example avoids putting that value into the slider and displays a neutral time instead. If your player supports live or streaming audio, consider a separate interface for that case rather than treating its duration as a normal seekable timeline.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteRank #3
- PLUG IN AND HEAR SOUND IN SECONDS - USB Type-A connector with a 3.5mm stereo headphone output and a separate 3.5mm mono microphone input. No drivers, no software, no external power - the adapter is USB bus-powered and is recognized as a standard USB audio device.
- WORKS ON WINDOWS, MAC AND LINUX - Driverless on Windows 98SE/ME/2000/XP/Server 2003/Vista/7/8, Linux and Mac OSX, and compliant with the USB Audio Device Class 1.0 specification, so any system that supports class-compliant USB audio will see it. Select it as the sound output and input device after plugging it in.
- TWO JACKS, TWO JOBS - The green jack is stereo OUT for headphones or powered speakers; the pink jack is mono microphone IN for a 3.5mm mic. It does NOT support 4-pole headsets on a single combo plug, it does NOT power passive speakers, and it does NOT add surround sound - it is a stereo 2-channel adapter.
- FOR LAPTOPS AND DESKTOPS THAT NEED AN AUDIO PORT BACK - Adds a headphone and mic port to a laptop, desktop, or mini PC whose onboard jack has failed or was never there. Managed and work-issued computers can block new USB audio devices by policy - check with your IT department before ordering for a company machine.
- SABRENT SUPPORT AND WARRANTY - What is in the box: one USB audio sound adapter. Backed by a 1-year limited warranty, extended to 2 years when you register within 90 days on the manufacturer's website.
Choose when the audio loads
The example uses preload="metadata", which asks the browser to load metadata such as duration without requesting that it preload the entire recording. Preload is a hint, not a guarantee that every browser will fetch the same data at the same time. If reducing initial audio requests matters more, defer assigning the source until the visitor chooses to play; that requires adding source-loading logic before calling play(). Avoid starting audio automatically: autoplay can interrupt visitors and may be restricted by browsers.
Make the player accessible
Use native buttons and range inputs where possible: they already support keyboard interaction. Give each slider a visible, associated label, retain a clear focus style, and update the play button’s label so its action remains clear. A custom player should provide an equivalent usable interface rather than simply hiding native controls.
Rank #4
- Podcast, Record, Live Stream, This Portable Audio Interface Covers it All - USB sound card for Mac or PC delivers 48kHz audio resolution for pristine recording every time
- Be ready for anything with this versatile M-AUDIO interface - Record guitar, vocals or line input signals with two combo XLR / Line / Instrument Inputs with phantom power
- Everything you Demand from an Audio Interface for Fuss-Free Monitoring - 1/4" headphone output and stereo 1/4" outputs for total monitoring flexibility; USB/Direct switch for zero latency monitoring
- Get the best out of your Microphones - M-Track Duo’s transparent Crystal Preamps guarantee optimal sound from all your microphones including condenser mics
- The MPC Production Experience - Includes MPC Beats Software complete with the essential production tools from Akai Professional
If the audio contains spoken dialogue, provide captions and a transcript that accurately describe the recording. Keep the download link available as an alternate way to access the audio. For a detailed accessibility reference, see MDN’s audio element guidance.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Test before publishing
- Test in the browsers and devices your visitors use, including keyboard-only operation.
- Confirm that each audio URL loads, that the server returns a suitable content type, and that the browser can play at least one supplied format.
- Check the play/pause label, elapsed time, duration, seek behavior, volume, repeat state, and end-of-track behavior.
- Test with a slow connection and with audio unavailable so the fallback text and download link remain useful.
For the relevant browser APIs and format details, consult MDN’s audio element reference, its browser compatibility information, and MDN’s audio codec guide. For media events, see MDN’s HTMLMediaElement reference.
Quick Recap
Best Value
- The new generation of the artist's interface: Connect your mic to Scarlett's 4th Gen mic pres. Plug in your guitar. Fire up the included software. Start making your first big hit
- Studio-quality sound: With a huge 120dB dynamic range, the newest generation of Scarlett uses the same converters as Focusrite’s flagship interfaces, found in the world's biggest studios
- Never lose a great take: Scarlett 4th Gen's Auto Gain sets the perfect level for your mic or guitar, and Clip Safe prevents clipping, so you can focus on the music
- Find your signature sound: Air mode lifts vocals and guitars to the front of the mix, adding musical presence and rich harmonic drive to your recordings
- With Scarlett 4th Gen, you have all you need to record, mix and master your music: Includes industry-leading recording software and a full collection of record-making plugins
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

