HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html>
<head>
<!-----
multiple song music player by adilene @ adilene.net. free to use and edit as you like! credit is not necessary, but it is appreciated! <3
if you need any help feel free to reach out to me at adilene.net!
source code: https://github.com/sayantanm19/js-music-player
----->
<script src="https://kit.fontawesome.com/f936906ae0.js" crossorigin="anonymous"></script> <!-- add this to the head!! -->
</head>
<style>
#musicplayer{
background:white; /* background color of player */
border:2px solid #e74492; /* border around player */
width:200px; /* width of the player */
}
.songtitle{
padding:5px; /* padding around song title */
border-bottom:2px solid #e74492; /* border under song title */
display:block;
}
.controls{
font-size:18px !important; /* size of controls */
background-color:#dbfcff; /* background color of controls */
text-align:center;
width:100%;
}
.controls td{
padding:8px 5px 0px 5px; /* padding around controls */
}
.seeking{
background-color:#dbfcff; /* background color of seeking bar */
display:flex;
justify-content: space-evenly;
padding:5px; /* padding around seeking bar */
}
.current-time{
padding-right:5px;
}
.total-duration{
padding-left:5px;
}
i.fas:hover{
cursor:help;
}
i.fas.fa-pause, i.fas.fa-play, i.fas.fa-forward, i.fas.fa-backward{
color:#e74492; /* color of controls */
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
background-color:#dbfcff; /* background color of seeking bar - make the color same as .seeking background color */
}
input[type=range]:focus {
outline: none;
}
/* settings for chrome browsers */
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 2px; /* thickness of seeking track */
cursor: help;
background: #E74492; /* color of seeking track */
}
input[type=range]::-webkit-slider-thumb {
height: 10px; /* height of seeking square */
width: 10px; /* width of seeking square */
border-radius: 0px; /* change to 5px if you want a circle seeker */
background: #E74492; /* color of seeker square */
cursor: help;
-webkit-appearance: none;
margin-top: -4.5px;
}
/* settings for firefox browsers */
input[type=range]::-moz-range-track {
width: 100%;
height: 2px; /* thickness of seeking track */
cursor: help;
background: #E74492; /* color of seeking track */
}
input[type=range]::-moz-range-thumb {
height: 10px; /* height of seeking square */
width: 10px; /* width of seeking square */
border-radius: 0px; /* change to 5px if you want a circle seeker */
background: #E74492; /* color of seeker square */
cursor: help;
border:none;
}
</style>
<body>
<div id="musicplayer">
<div>
<marquee scrollamount="8" class="songtitle"></marquee>
</div>
<table class="controls">
<tr>
<td>
<div class="prev-track" onclick="prevTrack()"><i class="fas fa-backward"></i></div>
</td>
<td>
<div class="playpause-track" onclick="playpauseTrack()" ><i class="fas fa-play"></i></div>
</td>
<td>
<div class="next-track" onclick="nextTrack()"><i class="fas fa-forward"></i></div>
</td>
</tr>
</table>
<div class="seeking">
<div class="current-time">00:00</div>
<input type="range" min="1" max="100" value="0" class="seek_slider" onchange="seekTo()">
<div class="total-duration">0:00</div>
</div>
<audio id="music" src=""></audio>
</div>
<script>
// initiate variables
let track_name = document.querySelector(".songtitle");
let playpause_btn = document.querySelector(".playpause-track");
let next_btn = document.querySelector(".next-track");
let prev_btn = document.querySelector(".prev-track");
let seek_slider = document.querySelector(".seek_slider");
let curr_time = document.querySelector(".current-time");
let total_duration = document.querySelector(".total-duration");
let track_index = 0;
let isPlaying = false;
let updateTimer;
// create new audio element
let curr_track = document.getElementById("music");
//
// DEFINE YOUR SONGS HERE!!!!!
// MORE THAN FOUR SONGS CAN BE ADDED!!
// JUST ADD ANOTHER BRACKET WITH NAME AND PATH
// CATBOX.MOE IS RECOMMENDED FOR UPLOADING MP3 FILES
let track_list = [
{
name:"inabakumori feat. kaai yuki - lagtrain",
path:"https://files.catbox.moe/9ywkki.mp3"
},
{
name:"inabakumori feat. kaai yuki - kimi ni kaikisen",
path:"https://files.catbox.moe/1pxdnw.mp3"
},
{
name:"pinocchio-p feat. hatsune miku - god-ish",
path:"https://files.catbox.moe/xv3vdj.mp3"
},
{
name: "syudou feat. hatsune miku - her boyfriend, jude",
path: "https://files.catbox.moe/49iuxl.mp3",
},
];
//
//
//
//
//
function loadTrack(track_index) {
clearInterval(updateTimer);
resetValues();
// load a new track
curr_track.src = track_list[track_index].path;
curr_track.load();
// update details of the track
track_name.textContent = "playing " + (track_index + 1) + " of " + track_list.length + ": " + track_list[track_index].name;
// set an interval of 1000 milliseconds for updating the seek slider
updateTimer = setInterval(seekUpdate, 1000);
// move to the next track if the current one finishes playing
curr_track.addEventListener("ended", nextTrack);
}
// reset values
function resetValues() {
curr_time.textContent = "0:00";
total_duration.textContent = "0:00";
seek_slider.value = 0;
}
// checks if song is playing
function playpauseTrack() {
if (!isPlaying) playTrack();
else pauseTrack();
}
// plays track when play button is pressed
function playTrack() {
curr_track.play();
isPlaying = true;
// replace icon with the pause icon
playpause_btn.innerHTML = '<i class="fas fa-pause"></i>';
}
// pauses track when pause button is pressed
function pauseTrack() {
curr_track.pause();
isPlaying = false;
// replace icon with the play icon
playpause_btn.innerHTML = '<i class="fas fa-play"></i>';
}
// moves to the next track
function nextTrack() {
if (track_index < track_list.length - 1)
track_index += 1;
else track_index = 0;
loadTrack(track_index);
playTrack();
}
// moves to the previous track
function prevTrack() {
if (track_index > 0)
track_index -= 1;
else track_index = track_list.length;
loadTrack(track_index);
playTrack();
}
// seeker slider
function seekTo() {
seekto = curr_track.duration * (seek_slider.value / 100);
curr_track.currentTime = seekto;
}
function seekUpdate() {
let seekPosition = 0;
// check if the current track duration is a legible number
if (!isNaN(curr_track.duration)) {
seekPosition = curr_track.currentTime * (100 / curr_track.duration);
seek_slider.value = seekPosition;
// calculate the time left and the total duration
let currentMinutes = Math.floor(curr_track.currentTime / 60);
let currentSeconds = Math.floor(curr_track.currentTime - currentMinutes * 60);
let durationMinutes = Math.floor(curr_track.duration / 60);
let durationSeconds = Math.floor(curr_track.duration - durationMinutes * 60);
// adding a zero to the single digit time values
if (currentSeconds < 10) { currentSeconds = "0" + currentSeconds; }
if (durationSeconds < 10) { durationSeconds = "0" + durationSeconds; }
if (currentMinutes < 10) { currentMinutes = currentMinutes; }
if (durationMinutes < 10) { durationMinutes = durationMinutes; }
curr_time.textContent = currentMinutes + ":" + currentSeconds;
total_duration.textContent = durationMinutes + ":" + durationSeconds;
}
}
// load the first track in the tracklist
loadTrack(track_index);
</script>
</body>
</html>
Also see: Tab Triggers