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 class="loading">
<p id="play-me">While loading, please adjust your volume.</p>
</div>
<div class="foreground"></div>
<div class="midground">
<div class="tuna"></div>
</div>
<div class="background">
</div>
<audio id="audio" preload="auto">
<source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/byakkoya_ep.mp3" type="audio/mp3" />
<source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/byakkoya_ep.ogg" type="audio/ogg" />
</audio>
* {
/* Nov 25, 2013: !important required to override selectors' implied state of running. */
animation-play-state: paused !important;
}
.playing * {
animation-play-state: running !important;
}
.tuna {
animation:
walk-cycle 1s steps(12) 24,
walk-to-run .75s steps(12) 24s 1,
run-cycle .5s steps(13) 24.75s infinite;
background: url(http://stash.rachelnabors.com/24ways2012/cat_sprite.png) 0 0 no-repeat;
height: 200px;
width: 400px;
position: absolute;
bottom: 1px;
left: 50%;
margin-left: -200px;
translate3d(0,0,0);
}
@keyframes walk-cycle {
0% {background-position: 0 0; }
100% {background-position: 0 -2391px; }
}
@keyframes walk-to-run {
0% {background-position: -400px 0; }
100% {background-position: -400px -2391px; }
}
@keyframes run-cycle {
0% {background-position: -800px 0; }
100% {background-position: -800px -2591px; }
}
.foreground, .midground, .background {
width: 100%;
height: 100%;
position: absolute;
top: 0; left: 0;
translate3d(0,0,0);
}
.foreground {
animation:
parallax_fg 10s linear infinite,
parallax_fg_fast 2s linear 24.75s infinite;
background: url(http://stash.rachelnabors.com/24ways2012/foreground_grass.png) 0 100% repeat-x;
z-index: 3;
}
@keyframes parallax_fg {
0% { background-position: -3584px 100%;}
100% {background-position: 0 100%; }
}
@keyframes parallax_fg_fast {
0% { background-position: 8870.4px 100%;}
100% {background-position: 12454.4px 100%; }
}
.midground {
animation:
parallax_mg 20s linear infinite,
parallax_mg_fast 5s linear 24.75s infinite;
background: url(http://stash.rachelnabors.com/24ways2012/midground_grass.png) 0 100% repeat-x;
z-index: 2;
}
@keyframes parallax_mg {
0% { background-position: -3000px 100%;}
100% {background-position: 0 100%; }
}
@keyframes parallax_mg_fast {
0% { background-position: 3712.5px 100%;}
100% {background-position: 6712.5px 100%; }
}
.background {
background-image:
url(http://stash.rachelnabors.com/24ways2012/background_mountain5.png),
url(http://stash.rachelnabors.com/24ways2012/background_mountain4.png),
url(http://stash.rachelnabors.com/24ways2012/background_mountain3.png),
url(http://stash.rachelnabors.com/24ways2012/background_mountain2.png),
url(http://stash.rachelnabors.com/24ways2012/background_mountain1.png);
background-repeat: repeat-x;
background-position: 0 100%;
z-index: 1;
animation:
parallax_bg 40s linear infinite,
parallax_bg_fast 10s linear 24.75s infinite;
}
@keyframes parallax_bg {
0% { background-position: -2400px 100%, -2000px 100%, -1800px 100%, -1600px 100%, -1200px 100%;}
100% {background-position: 0 100%, 0 100%, 0 100%, 0 100%, 0 100%; }
}
@keyframes parallax_bg_fast {
0% { background-position: 1485px 100%, 1237.5px 100%, 1113.75px 100%, 990px 100%, 742.5px 100%;}
100% {background-position: 3885px 100%, 3237.5px 100%, 2913.75px 100%, 2590px 100%, 1942.5px 100%; }
}
body {
background: linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%),
#d2d2d2 url(http://stash.rachelnabors.com/24ways2012/background_clouds.png);
}
// Play and loop music
// Get the audio element
var byakkoya = document.querySelector('audio');
// create function to play and loop audio
function song(a){
//start playing at 0
a.currentTime = 0;
a.play();
//when we hit 64 seconds...
setTimeout(function(){
// skip back to 24.5 seconds and keep playing...
a.currentTime = 24.55;
// then loop back when we hit 64 again, or every 59.5 seconds.
setInterval(function(){
a.currentTime = 24.55;
},39450);
},64000);
}
// Wait till the music loads (or get a nasty error!)
byakkoya.addEventListener("canplaythrough", function () {
setTimeout(function(){
// add a class to the body tag so we know we're playable...
$("body").addClass("playable");
$("#play-me").html("Play me.").click(function(){
song(byakkoya);
$("body").addClass("playing");
});
},3000); //a wee bit of a delay to make sure peeps see the PSA
}, false);
Also see: Tab Triggers