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="container">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris at iaculis urna. Sed aliquet ante nec urna sodales, eget laoreet lorem congue. Etiam at dictum leo, vel luctus tellus. Integer tempus purus et libero tincidunt aliquet. Curabitur velit est, imperdiet vitae consectetur in, rhoncus id massa. Etiam blandit lobortis purus vitae tempor. Maecenas diam lectus, aliquet lacinia leo vel, vulputate dapibus leo. Suspendisse cursus facilisis elementum.
Pellentesque feugiat, diam eget luctus luctus, nisl nibh feugiat mi, convallis feugiat nisi quam ut dolor. Sed vulputate laoreet nisl ac lacinia. In justo tellus, facilisis quis bibendum ac, vulputate non risus. Nullam efficitur nibh diam, volutpat hendrerit leo placerat nec. Nam rhoncus sit amet purus nec sodales. Donec sit amet est felis. Vestibulum rhoncus blandit lacus, sed aliquam arcu porta at.
Quisque vitae maximus nunc. Fusce ac dolor arcu. Nunc vitae vestibulum purus. Proin eu cursus magna. Vestibulum condimentum finibus sem, et ornare est aliquam vitae. Donec dapibus nulla eu risus cursus, in porttitor magna facilisis. Cras scelerisque at libero in suscipit. Maecenas suscipit egestas dui, non consequat urna pharetra consequat. Sed pellentesque arcu eu neque lacinia, ac luctus turpis pellentesque. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam ut suscipit tellus. Vestibulum accumsan feugiat augue eget eleifend. Cras imperdiet in felis a rhoncus. Suspendisse potenti.
Aliquam eu elit pulvinar eros cursus pretium auctor non nibh. Etiam luctus elementum gravida. Etiam lobortis, nunc eget ultricies varius, mi ex varius ligula, id vulputate tortor orci at massa. Fusce semper eget tortor vehicula aliquet. Morbi non dolor accumsan, convallis nibh ac, semper dolor. Nullam maximus nisl quis purus interdum, sit amet ultricies mauris mollis. Pellentesque sed leo quis urna rutrum faucibus. Nunc euismod ante at quam venenatis aliquet. Nullam maximus, ligula eget molestie venenatis, arcu eros feugiat turpis, vitae venenatis nisi mauris non nulla. Sed finibus justo ac augue blandit, id commodo lorem vestibulum. Pellentesque congue rutrum vehicula. Vestibulum a metus a risus ultrices placerat.
Phasellus a placerat leo. Curabitur posuere tellus in dolor tincidunt pulvinar. Praesent vitae sem dapibus, tincidunt turpis eget, malesuada erat. Mauris posuere non diam et feugiat. Nullam ipsum nisi, accumsan at mi id, euismod laoreet metus. In id diam lectus. Sed vel lorem erat. Ut tincidunt pellentesque elit vitae malesuada. Nullam ac erat est. Proin congue leo at aliquet rutrum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum luctus blandit aliquet. Suspendisse nec vehicula risus, nec convallis lorem. Pellentesque vel rutrum purus.
Mauris dignissim enim et dictum consequat. Fusce vehicula ante nec interdum posuere. Duis scelerisque elit tempus, luctus urna id, dignissim orci. Donec dignissim interdum sapien. Fusce tincidunt elementum ligula, sit amet tincidunt purus cursus vel. Nam dignissim sem sit amet diam euismod congue. Cras velit nunc, posuere quis odio ut, malesuada condimentum elit. Fusce est metus, interdum ac tempor at, viverra nec nisi.
Cras pellentesque turpis vitae mi commodo, eu interdum justo pretium. Donec sit amet consequat mi, sed ultricies urna. Nam nunc quam, hendrerit vitae placerat volutpat, pharetra ac urna. Vivamus maximus iaculis nibh, vel cursus tortor suscipit vel. Nam rutrum nec nulla non sollicitudin. Duis vulputate porta eros, sit amet eleifend leo fringilla quis. Nulla sed massa aliquet orci euismod congue sit amet quis justo. Mauris commodo mauris et sapien varius sodales. Mauris in vulputate nulla. Mauris at vehicula lacus. In felis justo, pulvinar vel ullamcorper in, vestibulum sodales risus. Nulla in diam eu ligula ultrices tristique posuere id mi. Praesent eu sollicitudin lorem, vel pharetra orci.
Suspendisse quis justo pretium tortor ullamcorper gravida sit amet sed erat. Aenean vel dictum leo, a interdum mi. Curabitur ipsum ligula, consequat sed euismod porttitor, egestas vel lectus. Maecenas tempus imperdiet ultrices. Duis vitae vehicula dui. Suspendisse commodo convallis sapien, vitae consectetur dui accumsan in. Proin at lacus sit amet purus pulvinar volutpat laoreet in purus. Praesent ornare, orci vel malesuada vestibulum, magna ligula euismod mauris, in viverra turpis nulla facilisis ipsum. Etiam ut erat sodales, blandit urna vel, malesuada tortor. Duis pellentesque posuere libero, vitae facilisis enim elementum vitae. Cras ornare est non justo malesuada luctus. Morbi non dolor ut velit fringilla hendrerit. Aenean arcu velit, laoreet sit amet urna at, malesuada maximus leo.
Nulla pulvinar sagittis tortor quis vestibulum. Nulla sodales leo ac augue luctus, sed dictum risus facilisis. Phasellus non venenatis est. Vivamus sit amet ex efficitur, efficitur justo a, faucibus ligula. Phasellus sed tempor quam, sed lacinia elit. Maecenas vestibulum leo at ex aliquet sagittis. Vivamus ornare tortor vel pulvinar laoreet. Suspendisse nec ultricies ligula. Pellentesque posuere tortor in tellus lacinia, et pretium odio volutpat. Donec et nunc erat. Mauris sit amet ligula nec augue dapibus fringilla imperdiet eleifend mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus vulputate laoreet lacus, sit amet feugiat turpis sagittis sit amet. Integer sit amet tincidunt enim, vel posuere turpis. Donec non nibh laoreet, semper nulla a, lacinia felis.
Donec pellentesque accumsan nulla, eu euismod massa vehicula vitae. Vivamus id malesuada erat, vel congue purus. Curabitur placerat luctus lectus nec varius. Vivamus tempor vehicula placerat. Mauris at consectetur magna, sit amet varius massa. Proin et volutpat risus. Aenean id ex vitae tellus volutpat facilisis et eget dui. Nunc euismod libero at metus dapibus, a tristique erat accumsan. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Nullam nulla est, interdum vitae ipsum id, ullamcorper porta lectus. Phasellus dapibus lorem blandit turpis faucibus, id tristique felis elementum. Morbi nec mauris metus. Vestibulum lobortis molestie velit vel eleifend.</p>
<a id="page-top" href="#"><span>ページのトップに戻る</span></a>
</div>
* {
box-sizing: border-box;
}
.container {
position: relative;
max-width: 600px;
margin: 0 auto;
padding: 30px 15px;
line-height: 1.5;
}
#page-top {
position: fixed;
bottom: 20px;
right: 20px;
display: block;
width: 60px;
height: 60px;
background: #333;
&:before {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -5px) rotate(45deg);
content: "";
width: 22px;
height: 22px;
border-top: 2px solid #fff;
border-left: 2px solid #fff;
}
span {
display: none;
}
}
// body要素のスクロール量を取得、0が返ってくる
const windowTop = document.body.scrollTop;
// #page-topを取得し、変数に代入
const pageTop = document.getElementById('page-top');
// pageTopをクリックした時の動作
pageTop.addEventListener('click', function(e) {
// a要素のデフォルトの挙動をOFFにする
e.preventDefault();
// topで指定した位置に、behaviorで指定した動きでスクロールする
window.scrollTo({
top: windowTop, // 0
behavior: 'smooth' // スムーズに
});
});
Also see: Tab Triggers