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.
<p>Rank grass, waist high, grows upon the plain of Phutra—the gorgeous flowering grass of the inner world, each particular blade of which is tipped with a tiny, five-pointed blossom—brilliant little stars of varying colors that twinkle in the green foliage to add still another charm to the weird, yet lovely, landscape.</p>
<div id="sticky">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/core.jpg" alt="Visualisation of the Earth's core, showing the planet cut in half with the core bulging from the center">
<p>The Earth's inner core is a solid ball of iron–nickel alloy with a radius of approximately 1220 kilometers, or about 70% that of the Moon. It is thought to have approximately the same temperature as the surface of the Sun: around 5400°C.
</div>
<p>But then the only aspect which attracted me was the distant hills in which I hoped to find sanctuary, and so I hastened on, trampling the myriad beauties beneath my hurrying feet. Perry says that the force of gravity is less upon the surface of the inner world than upon that of the outer. He explained it all to me once, but I was never particularly brilliant in such matters and so most of it has escaped me. As I recall it the difference is due in some part to the counter-attraction of that portion of the earth's crust directly opposite the spot upon the face of Pellucidar at which one's calculations are being made. Be that as it may, it always seemed to me that I moved with greater speed and agility within Pellucidar than upon the outer surface—there was a certain airy lightness of step that was most pleasing, and a feeling of bodily detachment which I can only compare with that occasionally experienced in dreams.</p>
<p>And as I crossed Phutra's flower-bespangled plain that time I seemed almost to fly, though how much of the sensation was due to Perry's suggestion and how much to actuality I am sure I do not know. The more I thought of Perry the less pleasure I took in my new-found freedom. There could be no liberty for me within Pellucidar unless the old man shared it with me, and only the hope that I might find some way to encompass his release kept me from turning back to Phutra.</p>
<p>Just how I was to help Perry I could scarce imagine, but I hoped that some fortuitous circumstance might solve the problem for me. It was quite evident however that little less than a miracle could aid me, for what could I accomplish in this strange world, naked and unarmed? It was even doubtful that I could retrace my steps to Phutra should I once pass beyond view of the plain, and even were that possible, what aid could I bring to Perry no matter how far I wandered?</p>
<p>The case looked more and more hopeless the longer I viewed it, yet with a stubborn persistency I forged ahead toward the foothills. Behind me no sign of pursuit developed, before me I saw no living thing. It was as though I moved through a dead and forgotten world.</p>
@import url(https://fonts.googleapis.com/css?family=Source+Serif+Pro);
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
* {
box-sizing: border-box;
}
body {
width: 90%;
max-width: 900px;
margin: 0 auto;
font-family: Source Serif Pro, serif;
line-height: 1.5; font-size: 1.3rem;
> p:not(:first-of-type) {
margin-right: 50%;
// ensures that text (after the first paragraph) is readable around the sticky element
@media all and (max-width: 600px) {
margin-right: 0;
// removes this margin at small screen sizes
}
}
}
div#sticky {
font-family: Open Sans, sans-serif;
font-size: 1.1rem;
width: 50%;
padding: 2.2rem;
padding-bottom: 3rem;
padding-top: 0;
float: right;
position: -webkit-sticky;
// for Safari
position: sticky;
// for Firefox & final spec
top: 0px;
// _required_. (Alternatively, bottom, left or right, depending on direction of scroll)
@media all and (max-width: 600px) {
position: static !important;
float: none;
width: 100%;
padding-bottom: 0;
// resets the block to flow with the rest of the document at small screen widths
}
img {
width: 100%;
display: block;
margin-bottom: 1rem;
}
+div {
display: none;
// gets rid of the empty div imposed by the polyfill below the previously sticky element when the screen width is low.
}
}
/*!
* Stickyfill -- `position: sticky` polyfill for IE
* v. 1.1.2 | https://github.com/wilddeer/stickyfill
* Copyright Oleg Korsunsky | http://wd.dizaina.net/
*
* MIT License
*/! function(a, b) {
function c() {
y = D = z = A = B = C = K
}
function d(a, b) {
for (var c in b) b.hasOwnProperty(c) && (a[c] = b[c])
}
function e(a) {
return parseFloat(a) || 0
}
function f() {
F = {
top: b.pageYOffset,
left: b.pageXOffset
}
}
function g() {
return b.pageXOffset != F.left ? (f(), void z()) : void(b.pageYOffset != F.top && (f(), i()))
}
function h() {
setTimeout(function() {
b.pageYOffset != F.top && (F.top = b.pageYOffset, i())
}, 0)
}
function i() {
for (var a = H.length - 1; a >= 0; a--) j(H[a])
}
function j(a) {
if (a.inited) {
var b = F.top <= a.limit.start ? 0 : F.top >= a.limit.end ? 2 : 1;
a.mode != b && p(a, b)
}
}
function k() {
for (var a = H.length - 1; a >= 0; a--) if (H[a].inited) {
var b = Math.abs(t(H[a].clone) - H[a].docOffsetTop),
c = Math.abs(H[a].parent.node.offsetHeight - H[a].parent.height);
if (b >= 2 || c >= 2) return !1
}
return !0
}
function l(a) {
isNaN(parseFloat(a.computed.top)) || a.isCell || (a.inited = !0, a.clone || q(a), "absolute" != a.parent.computed.position && "relative" != a.parent.computed.position && (a.parent.node.style.position = "relative"), j(a), a.parent.height = a.parent.node.offsetHeight, a.docOffsetTop = t(a.clone))
}
function m(a) {
var b = !0;
a.clone && r(a), d(a.node.style, a.css);
for (var c = H.length - 1; c >= 0; c--) if (H[c].node !== a.node && H[c].parent.node === a.parent.node) {
b = !1;
break
}
b && (a.parent.node.style.position = a.parent.css.position), a.mode = -1
}
function n() {
for (var a = H.length - 1; a >= 0; a--) l(H[a])
}
function o() {
for (var a = H.length - 1; a >= 0; a--) m(H[a])
}
function p(a, b) {
var c = a.node.style;
switch (b) {
case 0:
c.position = "absolute", c.left = a.offset.left + "px", c.right = a.offset.right + "px", c.top = a.offset.top + "px", c.bottom = "auto", c.width = "auto", c.marginLeft = 0, c.marginRight = 0, c.marginTop = 0;
break;
case 1:
c.position = "fixed", c.left = a.box.left + "px", c.right = a.box.right + "px", c.top = a.css.top, c.bottom = "auto", c.width = "auto", c.marginLeft = 0, c.marginRight = 0, c.marginTop = 0;
break;
case 2:
c.position = "absolute", c.left = a.offset.left + "px", c.right = a.offset.right + "px", c.top = "auto", c.bottom = 0, c.width = "auto", c.marginLeft = 0, c.marginRight = 0
}
a.mode = b
}
function q(a) {
a.clone = document.createElement("div");
var b = a.node.nextSibling || a.node,
c = a.clone.style;
c.height = a.height + "px", c.width = a.width + "px", c.marginTop = a.computed.marginTop, c.marginBottom = a.computed.marginBottom, c.marginLeft = a.computed.marginLeft, c.marginRight = a.computed.marginRight, c.padding = c.border = c.borderSpacing = 0, c.fontSize = "1em", c.position = "static", c.cssFloat = a.computed.cssFloat, a.node.parentNode.insertBefore(a.clone, b)
}
function r(a) {
a.clone.parentNode.removeChild(a.clone), a.clone = void 0
}
function s(a) {
var b = getComputedStyle(a),
c = a.parentNode,
d = getComputedStyle(c),
f = a.style.position;
a.style.position = "relative";
var g = {
top: b.top,
marginTop: b.marginTop,
marginBottom: b.marginBottom,
marginLeft: b.marginLeft,
marginRight: b.marginRight,
cssFloat: b.cssFloat
}, h = {
top: e(b.top),
marginBottom: e(b.marginBottom),
paddingLeft: e(b.paddingLeft),
paddingRight: e(b.paddingRight),
borderLeftWidth: e(b.borderLeftWidth),
borderRightWidth: e(b.borderRightWidth)
};
a.style.position = f;
var i = {
position: a.style.position,
top: a.style.top,
bottom: a.style.bottom,
left: a.style.left,
right: a.style.right,
width: a.style.width,
marginTop: a.style.marginTop,
marginLeft: a.style.marginLeft,
marginRight: a.style.marginRight
}, j = u(a),
k = u(c),
l = {
node: c,
css: {
position: c.style.position
},
computed: {
position: d.position
},
numeric: {
borderLeftWidth: e(d.borderLeftWidth),
borderRightWidth: e(d.borderRightWidth),
borderTopWidth: e(d.borderTopWidth),
borderBottomWidth: e(d.borderBottomWidth)
}
}, m = {
node: a,
box: {
left: j.win.left,
right: J.clientWidth - j.win.right
},
offset: {
top: j.win.top - k.win.top - l.numeric.borderTopWidth,
left: j.win.left - k.win.left - l.numeric.borderLeftWidth,
right: -j.win.right + k.win.right - l.numeric.borderRightWidth
},
css: i,
isCell: "table-cell" == b.display,
computed: g,
numeric: h,
width: j.win.right - j.win.left,
height: j.win.bottom - j.win.top,
mode: -1,
inited: !1,
parent: l,
limit: {
start: j.doc.top - h.top,
end: k.doc.top + c.offsetHeight - l.numeric.borderBottomWidth - a.offsetHeight - h.top - h.marginBottom
}
};
return m
}
function t(a) {
for (var b = 0; a;) b += a.offsetTop, a = a.offsetParent;
return b
}
function u(a) {
var c = a.getBoundingClientRect();
return {
doc: {
top: c.top + b.pageYOffset,
left: c.left + b.pageXOffset
},
win: c
}
}
function v() {
G = setInterval(function() {
!k() && z()
}, 500)
}
function w() {
clearInterval(G)
}
function x() {
I && (document[L] ? w() : v())
}
function y() {
I || (f(), n(), b.addEventListener("scroll", g), b.addEventListener("wheel", h), b.addEventListener("resize", z), b.addEventListener("orientationchange", z), a.addEventListener(M, x), v(), I = !0)
}
function z() {
if (I) {
o();
for (var a = H.length - 1; a >= 0; a--) H[a] = s(H[a].node);
n()
}
}
function A() {
b.removeEventListener("scroll", g), b.removeEventListener("wheel", h), b.removeEventListener("resize", z), b.removeEventListener("orientationchange", z), a.removeEventListener(M, x), w(), I = !1
}
function B() {
A(), o()
}
function C() {
for (B(); H.length;) H.pop()
}
function D(a) {
for (var b = H.length - 1; b >= 0; b--) if (H[b].node === a) return;
var c = s(a);
H.push(c), I ? l(c) : y()
}
function E(a) {
for (var b = H.length - 1; b >= 0; b--) H[b].node === a && (m(H[b]), H.splice(b, 1))
}
var F, G, H = [],
I = !1,
J = a.documentElement,
K = function() {}, L = "hidden",
M = "visibilitychange";
void 0 !== a.webkitHidden && (L = "webkitHidden", M = "webkitvisibilitychange"), b.getComputedStyle || c();
for (var N = ["", "-webkit-", "-moz-", "-ms-"], O = document.createElement("div"), P = N.length - 1; P >= 0; P--) {
try {
O.style.position = N[P] + "sticky"
} catch (Q) {}
"" != O.style.position && c()
}
f(), b.Stickyfill = {
stickies: H,
add: D,
remove: E,
init: y,
rebuild: z,
pause: A,
stop: B,
kill: C
}
}(document, window), window.jQuery && ! function($) {
$.fn.Stickyfill = function() {
return this.each(function() {
Stickyfill.add(this)
}), this
}
}(window.jQuery);
var sticky = document.getElementById('sticky');
var screencheck = window.matchMedia("(max-width: 600px)");
Stickyfill.add(sticky);
if (screencheck.matches) {
Stickyfill.remove(sticky);
}
Also see: Tab Triggers