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.
<section>
<audio src="" id="audio"></audio>
<div class="music-player">
<div class="music-player__controls">
<button class="material-symbols-rounded" id="skip-previous">
skip_previous
</button>
<button class="material-symbols-rounded" id="fast-rewind">
fast_rewind
</button>
<button class="material-symbols-rounded" id="play">
play_circle
</button>
<button class="material-symbols-rounded" id="fast-forward">
fast_forward
</button>
<button class="material-symbols-rounded" id="skip-next">
skip_next
</button>
</div>
<div class="music-player__controls">
<button class="material-symbols-rounded button__icon" id="mute">
volume_up
</button>
</div>
<div class="music-player__info">
<div class="music-player__info-wrapper">
<div class="led__label" id="album-name-wrapper">
Artist:
</div>
<div class="led__display">
<div class="led__text" id="artist-name">████████████████████</div>
</div>
</div>
<div class="music-player__info-wrapper">
<div class="led__label" id="album-name-wrapper">
Album:
</div>
<div class="led__display">
<div class="led__text" id="album-name">████████████████████</div>
</div>
</div>
<div class="music-player__info-wrapper" id="track-name-wrapper">
<div class="led__label">
Title:
</div>
<div class="led__display">
<div class="led__text" id="track-name">████████████████████</div>
</div>
</div>
<div class="music-player__info-wrapper" id="track-number-wrapper">
<div class="led__label">
Track:
</div>
<div class="led__display" id="track-number">
██
</div>
</div>
<div class="music-player__progress-wrapper">
<div class="music-player__progress-indicator"></div>
</div>
</div>
</div>
</section>
@font-face {
font-family: Meloso;
src: url(https://assets.codepen.io/4999959/MelosoVF.ttf)
format("truetype-variations");
font-weight: 100 850;
}
@font-face {
font-family: Amboy;
src: url(https://assets.codepen.io/4999959/Parkinson+-+Amboy-Black.otf);
font-weight: 400;
}
@font-face {
font-family: Amboy;
src: url(https://assets.codepen.io/4999959/Parkinson+-+Amboy-Inline.otf);
font-weight: 600;
}
@font-face {
font-family: LED;
src: url(https://assets.codepen.io/4999959/Matthias+Luh+-+14+Segment+LED+Display.ttf);
font-weight: 400;
}
@font-face {
font-family: LED;
src: url(https://assets.codepen.io/4999959/Matthias+Luh+-+14+Segment+LED+Display+Bold.ttf);
font-weight: 600;
}
:root {
--dark-blue: #071666;
--blue: #1894e2;
--sf-blue: #3bfffd;
--white: #eafeff;
--black: #06021f;
}
body {
display: flex;
flex-direction: column;
justify-content: stretch;
background: var(--black);
color: var(--white);
line-height: 1.5;
padding: 5rem;
}
section {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 1rem;
flex-grow: 1;
/* min-height: 80vh; */
}
p {
margin: 0;
}
button {
background: none;
border: none;
color: inherit;
}
.material-symbols-rounded {
font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}
.led__label {
font-family: "hoverunit";
text-transform: uppercase;
font-size: 1rem;
font-size: 0.8rem;
line-height: 1;
}
.led__display {
font-family: "LED";
font-size: 1.5rem;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
position: relative;
overflow: hidden;
isolation: isolate;
&::before {
content: "████████████████████";
position: absolute;
inset: 0;
color: var(--blue);
opacity: 0.4;
z-index: -1;
}
}
.music-player {
display: flex;
flex-wrap: wrap;
background: var(--white);
border-radius: 5rem;
/* align-self: stretch; */
padding: 0.5rem;
gap: 0.5rem;
}
.music-player__controls {
display: flex;
gap: 0.2rem;
background: var(--dark-blue);
padding: 0.2rem;
border-radius: 3rem;
& .material-symbols-rounded {
font-size: 1.5rem;
padding: 0.75rem;
border-radius: 0.3rem;
font-variation-settings: "FILL" 0, "wght" 400, "GRAD" -25, "opsz" 24;
transition: all 400ms ease-out, color 200ms ease-out;
user-select: none;
&.play {
background: var(--sf-blue);
color: var(--black);
font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 200, "opsz" 24;
}
&:first-child {
border-radius: 3rem 0.5rem 0.5rem 3rem;
}
&:last-child {
border-radius: 0.5rem 3rem 3rem 0.5rem;
}
&.button__icon {
border-radius: 3rem;
}
&:hover {
background: var(--blue);
color: var(--black);
font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24;
transition: all 100ms ease-in;
cursor: pointer;
}
&:active {
background: var(--sf-blue);
font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 200, "opsz" 24;
}
&:disabled {
cursor: not-allowed;
color: var(--black);
&:hover {
background: var(--dark-blue);
}
}
}
}
.music-player__info {
background: var(--dark-blue);
display: flex;
gap: 0.5rem;
flex-grow: 1;
padding: 0.2rem 1.25rem;
border-radius: 3rem;
position: relative;
overflow: hidden;
flex-wrap: wrap;
& .music-player__info-wrapper {
display: flex;
flex-direction: column;
padding: 0.2rem;
gap: 0.1rem;
font-family: "LED";
font-size: 1.5rem;
line-height: 1;
text-transform: uppercase;
width: 20ch;
}
& .music-player__progress-wrapper {
position: absolute;
left: 0;
bottom: 0;
height: 0.25rem;
width: 100%;
background: var(--black);
cursor: pointer;
transition: height 400ms ease-out;
&:hover {
height: 100%;
transition: height 100ms ease-in;
}
& .music-player__progress-indicator {
appearance: none;
background: var(--sf-blue);
height: 100%;
width: 0%;
outline: none;
margin: 0;
}
}
}
.led__text {
position: relative;
}
#track-number {
width: 2ch;
animation: none;
}
#track-number-wrapper {
width: auto;
}
function musicPlayer() {
const musicContainer = document.querySelector(`.music-player`);
const playBtn = document.querySelector(`#play`);
const prevSongBtn = document.querySelector(`#fast-rewind`);
const nextSongBtn = document.querySelector(`#fast-forward`);
const prevAlbumBtn = document.querySelector(`#skip-previous`);
const nextAlbumBtn = document.querySelector(`#skip-next`);
const audio = document.querySelector(`#audio`);
const progress = document.querySelector(`.music-player__progress-indicator`);
const progressContainer = document.querySelector(
`.music-player__progress-wrapper`
);
const artistName = document.querySelector(`#artist-name`);
const albumName = document.querySelector(`#album-name`);
const songName = document.querySelector(`#track-name`);
const trackNo = document.querySelector(`#track-number`);
const muteBtn = document.querySelector(`#mute`);
const music = [
{
artist: `Star Forest`,
album: `Star Forest`,
year: 2021,
songs: [
`Star Forest`,
`Monster Flower`,
`Wildewood`,
`Starchaser Dreamgirl`,
`Play to Live`,
`Something Under That Rock`,
`Cyberschool`,
`Wishing Song`,
`Little Fancy Creek`,
`Zuggabuggaboo`,
`Everything You Do`,
`Chantey Cog`
],
songLinks: [
`https://assets.codepen.io/4999959/Star+Forest.mp3`,
`https://assets.codepen.io/4999959/Monster+Flower.mp3`,
`https://assets.codepen.io/4999959/Wildewood.mp3`,
`https://assets.codepen.io/4999959/Starchaser+Dreamgirl.mp3`,
`https://assets.codepen.io/4999959/Play+to+Live.mp3`,
`https://assets.codepen.io/4999959/Something+Under+That+Rock.mp3`,
`https://assets.codepen.io/4999959/Cyberschool.mp3`,
`https://assets.codepen.io/4999959/Wishing+Song.mp3`,
`https://assets.codepen.io/4999959/Little+Fancy+Creek.mp3`,
`https://assets.codepen.io/4999959/Zuggabuggaboo.mp3`,
`https://assets.codepen.io/4999959/Everything+You+Do.mp3`,
`https://assets.codepen.io/4999959/Chantey+Cog.mp3`
]
},
{
artist: `Straight Dope Cherry`,
album: `Traffic, Tile, and I Will See the Sun`,
year: 2004,
songs: [
`Creepin' Around`,
`Traffic, Tile, and I will See the Sun`,
`All My Blame`,
`Carver's Cathedral`,
`Give Back`,
`Union Down`,
`So Long`
],
songLinks: [
`https://assets.codepen.io/4999959/Creepin+Around.mp3`,
`https://assets.codepen.io/4999959/Traffic%2C+Tile%2C+And+I+Will+See+The.mp3`,
`https://assets.codepen.io/4999959/All+My+Blame.mp3`,
`https://assets.codepen.io/4999959/Carvers+Cathedral.mp3`,
`https://assets.codepen.io/4999959/Give+Back.mp3`,
`https://assets.codepen.io/4999959/Union+Down.mp3`,
`https://assets.codepen.io/4999959/So+Long.mp3`
]
}
];
// Keep track of album and songs
let albumIndex = 0;
let songIndex = 0;
// Initially load song info DOM
loadSong();
// FUNCTIONS
function loadSong() {
let currentArtist = music[albumIndex].artist;
let currentAlbum = music[albumIndex].album;
let currentSong = music[albumIndex].songs[songIndex];
artistName.innerText = currentArtist;
albumName.innerText = currentAlbum;
songName.innerText = currentSong;
audio.src = music[albumIndex].songLinks[songIndex];
setTrackNo(songIndex);
if (artistName.innerText.length > 20) {
overflowScroll(artistName);
}
if (albumName.innerText.length > 20) {
overflowScroll(albumName);
}
if (songName.innerText.length > 20) {
overflowScroll(songName);
}
}
function setTrackNo() {
const realNo = (parseInt(songIndex) + 1).toString().padStart(2, `0`);
trackNo.innerText = realNo;
}
function playSong() {
playBtn.classList.add(`play`);
playBtn.innerText = `pause_circle`;
audio.play();
}
function autoplaySong() {
loadSong();
playSong();
}
function pauseSong() {
playBtn.classList.remove(`play`);
playBtn.innerText = `play_circle`;
audio.pause();
}
// Changing Songs
function prevSong() {
function backSong() {
songIndex--;
let totalSongs = music[albumIndex].songs.length;
if (songIndex < 0) {
songIndex = totalSongs - 1;
}
}
function sameSong() {
audio.currentTime = 0;
updateProgress();
}
audio.currentTime > 0 ? sameSong() : backSong();
audio.paused ? loadSong() : autoplaySong();
}
function nextSong() {
songIndex++;
let totalSongs = music[albumIndex].songs.length;
if (songIndex > totalSongs - 1) {
songIndex = 0;
}
audio.paused ? loadSong() : autoplaySong();
}
// Changing Albums
function prevAlbum() {
function backAlbum() {
albumIndex--;
songIndex = 0;
let totalAlbums = music.length;
if (albumIndex < 0) {
albumIndex = totalAlbums - 1;
}
}
function sameAlbum() {
songIndex = 0;
audio.currentTime = 0;
updateProgress();
}
songIndex > 0 ? sameAlbum() : backAlbum();
audio.paused ? loadSong() : autoplaySong();
}
function nextAlbum() {
albumIndex++;
songIndex = 0;
audio.currentTime = 0;
let totalAlbums = music.length;
console.log(`totalAlbums next`, totalAlbums);
if (albumIndex > totalAlbums - 1) {
albumIndex = 0;
}
audio.paused ? loadSong() : autoplaySong();
}
// Progress Bar
function updateProgress() {
const { duration, currentTime } = audio;
const progressPercent = (currentTime / duration) * 100;
progress.style.width = `${progressPercent}%`;
}
function setProgress(e) {
const width = this.clientWidth;
const clickX = e.offsetX;
const duration = audio.duration;
audio.currentTime = (clickX / width) * duration;
}
// Selecting a song from a playlist
function changeSong() {
songIndex = this.dataset.indexNumber;
loadSong();
playSong();
}
// Volume Controls
function mute() {
muteBtn.innerText = `volume_off`;
audio.muted = true;
}
function unmute() {
muteBtn.innerText = `volume_up`;
audio.muted = false;
}
// Animations for the Info Displays
function overflowScroll(target) {
const chLength = target.innerText.length;
const trackLength = 20;
const scrollLength = chLength - trackLength;
const scrollTime = 3;
const letterSpeed = scrollTime / trackLength;
const scrollSpeed = letterSpeed * scrollLength;
var tl = gsap.timeline({ repeat: -1, yoyo: true, repeatDelay: 3 });
tl.to(target, {
duration: scrollSpeed,
x: `-${scrollLength}ch`,
ease: `steps(${scrollLength})`
});
}
//EVENT LISTENERS
//Player Listeners
playBtn.addEventListener(`click`, () => {
audio.paused ? playSong() : pauseSong();
});
prevSongBtn.addEventListener(`click`, prevSong);
nextSongBtn.addEventListener(`click`, nextSong);
prevAlbumBtn.addEventListener(`click`, prevAlbum);
nextAlbumBtn.addEventListener(`click`, nextAlbum);
audio.addEventListener(`timeupdate`, updateProgress);
progressContainer.addEventListener(`click`, setProgress);
audio.addEventListener(`ended`, nextSong);
muteBtn.addEventListener(`click`, () => {
audio.muted ? unmute() : mute();
});
//Non Player Listeners
}
musicPlayer();
Also see: Tab Triggers