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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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>
<h2>AUBREY</h2>
<p>And Aubrey was her name<br />
A not so very ordinary girl or name<br />
But who's to blame?<br />
For a love that wouldn't bloom<br />
For the hearts that never played in tune<br />
Like a lovely melody that everyone can sing<br />
Take away the words that rhyme, it doesn't mean a thing</p>
<p>And Aubrey was her name<br />
We tripped the light and danced together to the moon<br />
But where was June?<br />
No, it never came around<br />
If it did it never made a sound<br />
Maybe I was absent or was listening too fast<br />
Catching all the words but then the meaning going past</p>
<p>But God I miss the girl<br />
And I'd go a thousand times around the world just to be<br />
Closer to her than to me</p>
<p>And Aubrey was her name<br />
I never knew her but I loved her just the same<br />
I loved her name<br />
Wish that I had found the way<br />
And the reasons that would make her stay<br />
I have learned to lead a life apart from all the rest<br />
If I can't have the one I want, I'll do without the best</p>
<p>But how I miss the girl<br />
And I'd go a million times around the world just to say<br />
She had been mine for a day</p>
</div>
body {
margin: 15px;
font-family: Georgia, serif;
}
h2 {
font-size: 168px;
text-align: center;
}
p {
font-size: 112px;
text-align: center;
}
nav {
background-color: #fefefe;
border: 1px solid #999;
position: fixed;
top: 0;
left: 0;
padding: 20px 20px 10px;
}
nav a {
display: block;
margin: 4px 0;
}
.block {
font-family: sans-serif;
padding: 15px;
background-color: seagreen;
border: 0px solid #555;
margin-bottom: 15px;
height: calc(100vh - 60px);
}
.block-target {
color: #eee;
font-size: 30px;
height: 200px;
height: 50%;
max-width: 50%;
}
.flex {
display: flex;
align-items: center;
justify-content: center;
}
.flex-item {
flex: 1;
}
$(function() {
var $document = $(document);
var $window = $(window);
var height = $document.height() - $window.height();
var timeline = new TimelineMax();
var scrolling = false;
// TimeScale value when Ctrl is pressed
// https://greensock.com/docs/#/HTML5/GSAP/TweenLite/timeScale/
var ctrlSpeed = 3;
// Set your speed constant here for how many pixels you want
// it to scroll / second
var scrollSpeed = 200;
var totalTime = height / scrollSpeed;
var duration;
var ratio;
var timeScale;
var keyboard = {
DOWN : 40,
UP : 38,
CTRL : 17
};
// ===========================================================================
// KEY DOWN
// ===========================================================================
$document.on("keydown", function(event) {
// IF 'CTRL' is pressed, speed up the timeScale to the ctrlSpeed
if (event.ctrlKey) {
event.preventDefault();
timeline.timeScale(ctrlSpeed);
}
// DOWN KEY
if (event.keyCode === keyboard.DOWN) {
event.preventDefault();
if (!scrolling) {
ratio = $window.scrollTop() / height;
duration = totalTime * (1 - ratio);
scrolling = true;
// IF the 'CTRL' key is pressed, change the timeScale to the ctrlSpeed
// ELSE set the timeScale to 1
timeScale = event.ctrlKey ? ctrlSpeed : 1;
timeline
.to($window, duration, { scrollTo: "max", ease: Power0.easeNone })
.timeScale(timeScale);
}
}
// UP KEY
if (event.keyCode === keyboard.UP) {
event.preventDefault();
if (!scrolling) {
ratio = $window.scrollTop() / height;
duration = totalTime - (totalTime * (1 - ratio));
scrolling = true;
timeScale = event.ctrlKey ? ctrlSpeed : 1;
timeline
.to($window, duration, { scrollTo: 0, ease: Power0.easeNone })
.timeScale(timeScale);
}
}
});
// ===========================================================================
// KEY UP
// ===========================================================================
$document.on("keyup", function(event) {
// Set the timeScale back to 1 when 'CTRL' is released
if (event.keyCode === keyboard.CTRL) {
event.preventDefault();
timeline.timeScale(1);
}
if (event.keyCode === keyboard.UP || event.keyCode === keyboard.DOWN) {
event.preventDefault();
timeline.clear();
scrolling = false;
}
});
});
Also see: Tab Triggers