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.
<div id="container">
<!-- The container basically just limits the size of the player, which expands to fill the width of its parent. In the real world, the container would probably be an iframe, used to embed the player somewhere else. -->
<div id="player">
<audio id="song">
<source src="http://audio.ngfiles.com/551000/551191_Pressure.mp3" type="audio/mp3" />
</audio>
<div id="info">
<h1>Pressure</h1>
<h2>by Pahgawk</h2>
</div>
<div id="controls">
<div class="group" id="r1">
<a class="big" id="play" href="" title="">
<i class="icon-play"></i>
</a>
</div>
<div class="group" id="time">
<div class="static">
<label></label>
<span id="currentTime">00:00</span>
<span id="totalTime">00:00</span>
</div>
</div>
<div class="group" id="seekHolder">
<div id="timeLabel">00:00</div>
<div class="static rangeContainer">
<label></label>
<div class="rangeHorizontal stripes" id="seek"></div>
<div id="seekFill" class="stripes"></div>
<div id="seekDrag"></div>
</div>
</div>
<div class="group" id="right">
<a id="mute" href="" title="">
<label class="expandable">VOL</label>
<i class="icon-volume-up" id="volumeIcon"></i>
</a>
<a id="loop" href="" title="">
<label class="expandable">LOOP</label>
<i class="icon-ban-circle" id="loopIcon"></i>
</a>
</div>
</div>
</div>
</div>
@import url(https://fonts.googleapis.com/css?family=Voltaire);
@import url(https://fonts.googleapis.com/css?family=Prosto+One);
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
@-webkit-keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}
}
@-moz-keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}
}
@-ms-keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}
}
@-o-keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}
}
@keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 40px 0;
}
}
body {
background-color:#000;
}
#container {
margin:20px auto;
width:900px;
height:75px;
}
#player {
background-color:#000;
font-family:'Voltaire', Arial, Helvetica, sans-serif;
font-size:0;
background-color:#111;
position:relative;
width:100%;
height:100%;
}
#info {
position:absolute;
bottom:50px;
left:10px;
font-family:'Prosto One', Arial, Helvetica, sans-serif;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
}
#info h1 {
font-size:15px;
line-height:15px;
color:#FFF;
display:inline;
margin-right:6px;
}
#info h2 {
font-size:11px;
line-height:11px;
color:#7D7575;
display:inline;
}
#player a {
text-decoration:none;
}
#controls {
padding:0 10px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
position:absolute;
display:table;
bottom:10px;
width:100%;
height:35px;
color:#FFF;
border-spacing:0;
}
td, tr {
padding:0;
border-spacing:0;
border-collapse:collapse;
}
.last {
-webkit-border-radius: 0px 5px 5px 0px;
border-radius: 0px 5px 5px 0px;
margin-right:0;
}
.buttonGroup {
height:30px;
border-bottom:5px solid rgba(0, 0,0,0.6);
margin-right:1px;
padding:0;
position:relative;
top:0;
}
.static {
margin-bottom:0;
margin-top:6px;
height:23px;
line-height:23px;
background-color:rgba(0,0,0,0.6);
text-align:center;
position:relative;
bottom:0;
margin-right:1px;
font-size:0;
padding:0;
}
.static span {
font-size:10px;
}
a {
font-size:15px;
display:inline-block;
color:#EEB211;
margin-bottom:0;
margin-top:6px;
height:23px;
line-height:23px;
position:relative;
background-color:rgba(0,0,0,0.6);
text-align:center;
margin-right:1px;
padding:0;
}
a:hover {
color:#000;
background-color:#EEB211;
}
a.big {
height:35px;
line-height:35px;
font-size:20px;
margin-top:0;
margin-bottom:0;
display:block;
}
label {
display:block;
position:absolute;
top:-6px;
left:0;
right:0;
height:0;
line-height:20px;
font-size:10px;
color:#FFF;
width:100%;
padding-top:5px;
padding-bottom:0;
background-color:rgba(0,0,0,0.6);
overflow:hidden;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
a:hover label.expandable, label.expandable:hover {
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
margin-top:-20px;
padding-bottom:5px;
height:15px;
}
.rangeContainer {
padding:0 7px 0 5px;
}
.rangeHorizontal {
display:block;
height:10px;
position:relative;
top:6px;
padding:0;
background-color: rgba(185, 111, 16, 0.5);
border: 1px solid rgba(185, 111, 16, 0.5);
cursor:pointer;
}
#seekFill {
height:10px;
background-color:#EEB211;
border:1px solid #FFE544;
position:absolute;
top:6px;
cursor:pointer;
-webkit-box-shadow: 0px 0px 5px 1px rgba(255, 255, 150, 0.3);
box-shadow: 0px 0px 5px 1px rgba(255, 255, 150, 0.3);
}
#seekDrag {
height:14px;
width:4px;
background-color:#999;
position:absolute;
top:4px;
margin-left:2px;
border:1px solid #000;
cursor:pointer;
opacity:0;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
cursor:pointer;
}
#seekHolder:hover #seekDrag {
opacity:1;
}
#timeLabel {
height:0;
top:-6px;
margin-top:6px;
text-align:center;
width:50px;
line-height:15px;
padding-top:0;
color:#FFF;
font-size:10px;
overflow:hidden;
background-color:rgba(0, 0, 0, 0.6);
-webkit-border-radius: 5px 5px 0px 0px;
border-radius: 5px 5px 0px 0px;
position:absolute;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}
#seekHolder:hover #timeLabel {
height:15px;
top:-26px;
padding-top:5px;
}
.stripes {
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(0, 0, 0, 0.1)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(0, 0, 0, 0.1)), color-stop(0.75, rgba(0, 0, 0, 0.1)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(-45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%, transparent 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(-45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%, transparent 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(-45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%, transparent 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1) 75%, transparent 75%, transparent);
background-image: linear-gradient(-45deg, rgba(0, 0, 0, 0.1) 25%, transparent 25%, transparent 50%, rgba(0, 0, 0, 0.1) 50%, rgba(0, 0, 0, 0.1) 75%, transparent 75%, transparent);
-webkit-animation: progress-bar-stripes 3s linear infinite;
-moz-animation: progress-bar-stripes 3s linear infinite;
-ms-animation: progress-bar-stripes 3s linear infinite;
-o-animation: progress-bar-stripes 3s linear infinite;
animation: progress-bar-stripes 3s linear infinite;
-webkit-background-size: 40px 40px;
-moz-background-size: 40px 40px;
-o-background-size: 40px 40px;
background-size: 40px 40px;
}
.group {
display:table-cell;
position:relative;
vertical-align:top;
}
.group:after {
content:" ";
display:block;
height:5px;
background-color:rgba(0, 0,0,0.6);
margin-top:1px;
margin-right:1px;
}
.group:first-child:after {
display:none;
}
.group:last-child:after {
-webkit-border-radius: 0 0 5px 0;
border-radius: 0 0 5px 0;
}
.group:last-child a:last-child {
margin-right:0;
}
.group:first-child > * {
-webkit-border-radius: 5px 0px 0px 5px;
border-radius: 5px 0px 0px 5px;
}
#play, #r1 {
width:50px;
}
#time {
font-size:10px;
width:90px;
}
#r2 {
width:90px;
}
#currentTime {
border-right:2px solid #7D7575;
padding-right:4px;
}
#totalTime {
color:#B96F10;
padding-left:4px;
}
#seekHolder {
width:auto;
position:relative;
}
#seek {
width:100%;;
}
#mute, #loop {
width:40px;
}
#mute:hover #volumeFill, #mute:hover #volumeOverlay {
bottom:7px;
}
#volumeFill {
height:70px
}
#volumeLabel {
font-size:0;
}
#volumeLabel span {
font-size:9px;
}
#right {
width:82px;
}
var AudioModel = function (_song) {
var isPlaying = false;
var song = _song;
var a = {};
a.getSong = function() {
return song;
};
a.currentTime = function() {
return song.currentTime;
};
a.duration = function() {
return song.duration;
};
a.setTime = function(time) {
song.currentTime = time;
};
a.play = function() {
isPlaying = true;
song.play();
};
a.pause = function() {
isPlaying = false;
song.pause();
};
a.playing = function() {
return isPlaying;
};
a.getLoop = function() {
return song.loop;
};
a.setLoop = function(loop) {
song.loop = loop;
};
a.setVolume = function(vol) {
song.volume = vol;
};
a.getVolume = function() {
return song.volume;
};
a.seekTo = function(time) {
song.currentTime = time;
};
var reset = function() {
if (!song.loop) {
a.seekTo(0);
a.pause();
}
};
song.addEventListener("ended", function(event) { reset() }, false);
return a;
}(document.getElementById("song"));
var AudioView = function(model) {
var playBtn = document.getElementById("play");
var currentTime = document.getElementById("currentTime");
var totalTime = document.getElementById("totalTime");
var seekBg = document.getElementById("seek");
var seekHolder = document.getElementById("seekHolder");
var seekFill = document.getElementById("seekFill");
var seekDrag = document.getElementById("seekDrag");
var volumeIcon = document.getElementById("volumeIcon");
var loopIcon = document.getElementById("loopIcon");
var timeLabel = document.getElementById("timeLabel");
var formatTime = function(i) {
var minutes = Math.floor(i/60);
var seconds = Math.floor(i%60);
return ((minutes < 10) ? ("0" + minutes) : minutes) + ":" + ((seconds < 10) ? ("0" + seconds) : seconds);
};
var play = function() {
playBtn.innerHTML = "<i class='icon-pause'></i>";
};
var pause = function() {
pauseBtn.innerHTML = "<i class='icon-play'></i>";
};
var updateTime = function() {
currentTime.innerHTML = formatTime(model.currentTime());
timeLabel.innerHTML = currentTime.innerHTML;
if (Math.round((1-(model.currentTime()/model.duration()))*(seekBg.offsetWidth))+3<timeLabel.offsetWidth/2) {
timeLabel.style.left = (seekHolder.offsetWidth-timeLabel.offsetWidth) + "px";
} else if (Math.round(((model.currentTime()/model.duration()))*(seekBg.offsetWidth)+3)<timeLabel.offsetWidth/2) {
timeLabel.style.left="0px";
} else {
timeLabel.style.left = Math.round(((model.currentTime()/model.duration()))*(seekBg.offsetWidth)+3-timeLabel.offsetWidth/2) + "px";
}
seekFill.style.width = Math.round((model.currentTime()/model.duration())*(seekBg.offsetWidth-2))+"px";
seekDrag.style.left = Math.round((model.currentTime()/model.duration())*(seekBg.offsetWidth-2))+"px";
};
var updateVolume = function() {
if (model.getVolume() === 0) {
volumeIcon.className = "icon-volume-off";
} else if (Math.round(model.getVolume()) === 0) {
volumeIcon.className = "icon-volume-down";
} else {
volumeIcon.className = "icon-volume-up";
}
};
var a = {};
var timeProxy = function(event) {
updateTime(this);
}
a.updateLoop = function() {
if (model.getLoop()) {
loopIcon.className = "icon-refresh icon-flip-horizontal";
} else {
loopIcon.className = "icon-ban-circle";
}
};
a.listen = function() {
model.getSong().addEventListener("timeupdate", timeProxy, false);
};
a.stopListening = function() {
model.getSong().removeEventListener("timeupdate", timeProxy, false);
}
a.dragSeek = function(mousePos) {
var dragTime = (mousePos.x/seekBg.offsetWidth)*model.duration();
timeLabel.innerHTML = formatTime(dragTime);
if (Math.round((1-(dragTime/model.duration()))*(seekBg.offsetWidth))+3<timeLabel.offsetWidth/2) {
timeLabel.style.left = (seekHolder.offsetWidth-timeLabel.offsetWidth) + "px";
} else if (Math.round(((dragTime/model.duration()))*(seekBg.offsetWidth)+3)<timeLabel.offsetWidth/2) {
timeLabel.style.left="0px";
} else {
timeLabel.style.left = Math.round(((dragTime/model.duration()))*(seekBg.offsetWidth)+3-timeLabel.offsetWidth/2) + "px";
}
seekFill.style.width = Math.round((dragTime/model.duration())*(seekBg.offsetWidth-2))+"px";
seekDrag.style.left = Math.round((dragTime/model.duration())*(seekBg.offsetWidth-2))+"px";
};
var init = function() {
totalTime.innerHTML = formatTime(song.duration);
if (this.autoPlay) {
this.play();
}
model.getSong().addEventListener("play", function(event) { play(); }, false);
model.getSong().addEventListener("pause", function(event) { pause(); }, false);
model.getSong().addEventListener("ended", function(event) { if (!model.loop()) pause(); }, false);
model.getSong().addEventListener("volumechange", function(event) { updateVolume(); }, false);
a.listen();
};
model.getSong().addEventListener("canplaythrough", function(event) { init(); }, false);
return a;
}(AudioModel);
var AudioControl = function(model, view) {
var playBtn = document.getElementById("play");
var seekBg = document.getElementById("seek");
var seekHolder = document.getElementById("seekHolder");
var seekFill = document.getElementById("seekFill");
var seekDrag = document.getElementById("seekDrag");
var muteBtn = document.getElementById("mute");
var volumeIcon = document.getElementById("volumeIcon");
var loopBtn = document.getElementById("loop");
var loopIcon = document.getElementById("loopIcon");
var timeLabel = document.getElementById("timeLabel");
var togglePlay = function(event) {
event.preventDefault();
if (model.playing()) {
model.pause();
} else {
model.play();
}
};
var toggleLoop = function(event) {
event.preventDefault();
model.setLoop(!model.getLoop());
view.updateLoop();
};
var toggleVolume = function(event) {
event.preventDefault();
if (model.getVolume()==1) {
model.setVolume(0.49);
} else if (model.getVolume()==0.49) {
model.setVolume(0);
} else {
model.setVolume(1);
}
};
var getMousePos = function(evt, element) {
var rect = element.getBoundingClientRect();
var root = document.documentElement;
var mouseX = evt.clientX - rect.left - root.scrollLeft;
var mouseY = evt.clientY - rect.top - root.scrollTop;
return {x:mouseX, y:mouseY};
};
var startSeek = function(event) {
event.preventDefault();
view.stopListening();
document.addEventListener("mousemove", seekProxy, false);
document.addEventListener("mouseup", endSeekProxy, false);
};
var seekProxy = function(event) {
seek(event);
};
var endSeekProxy = function(event) {
endSeek(event);
};
var seek = function(event) {
event.preventDefault();
view.dragSeek(getMousePos(event, seekBg));
};
var endSeek = function(event) {
event.preventDefault();
view.listen();
document.removeEventListener("mousemove", seekProxy, false);
document.removeEventListener("mouseup", endSeekProxy, false);
var mousePos = getMousePos(event, seekBg);
model.seekTo((mousePos.x/seekBg.offsetWidth)*model.duration());
};
playBtn.addEventListener("click", function(event) { togglePlay(event); }, false);
loopBtn.addEventListener("click", function(event) { toggleLoop(event); }, false);
muteBtn.addEventListener("click", function(event) { toggleVolume(event); }, false);
seekBg.addEventListener("mousedown", function(event) { startSeek(event); }, false);
seekFill.addEventListener("mousedown", function(event) { startSeek(event); }, false);
seekDrag.addEventListener("mousedown", function(event) { startSeek(event); }, false);
return {};
}(AudioModel, AudioView);
Also see: Tab Triggers