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.
<h1>Our Model Scroll-to-top Component</h1>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Animi neque dolor magni quaerat, consequuntur quidem ducimus, fugit ex laborum fugiat illum explicabo debitis assumenda quas modi voluptas sit? Nobis, corrupti. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum sapiente hic voluptate libero. Veritatis vitae voluptates praesentium pariatur, quas laboriosam eos molestias nisi maiores mollitia consequatur aliquam obcaecati laudantium amet. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Unde repellendus veniam corrupti ipsam impedit excepturi quae voluptatum laboriosam. Quos, accusantium ipsum dignissimos iusto accusamus laudantium nam ratione repudiandae quibusdam quisquam. Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime doloremque excepturi eos consequuntur, iure, assumenda officiis quae nihil voluptas animi ducimus atque dolores fugit, sed debitis aliquid cum libero dolore!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Error perspiciatis odit porro facilis architecto, magnam enim delectus ducimus nobis, blanditiis eaque beatae! Nostrum libero delectus illo sapiente sed, earum culpa! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Neque nam placeat cupiditate quidem, omnis laudantium eaque voluptates delectus nisi animi ea quo rem reiciendis iste optio tenetur itaque expedita. Itaque! Lorem ipsum dolor sit, amet consectetur adipisicing elit. Similique repudiandae modi accusantium ad dolores sequi fugiat aperiam vero maiores perspiciatis reprehenderit sapiente, officiis praesentium assumenda soluta ducimus, rem consectetur tempore? Lorem ipsum, dolor sit amet consectetur adipisicing elit. Tempora expedita ipsam maiores, voluptate alias id vitae illum earum praesentium ex beatae, labore culpa ducimus voluptatum aliquam ab sit similique esse!</p>
<h2>Well, Here's Another Heading</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel ad commodi accusamus labore. Veniam deleniti impedit sit repudiandae corrupti, beatae quisquam id eos blanditiis consequuntur eum optio repellendus recusandae rem. Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque, voluptas! Sequi saepe quaerat quod amet sunt voluptatem at rem? Adipisci vero quaerat incidunt asperiores eius eligendi assumenda sint iure illo. Lorem ipsum dolor sit amet consectetur adipisicing elit. Alias ratione eligendi debitis odit possimus atque facilis nam eveniet, voluptates ad, eos aliquid cum! Doloribus vero repellat ut voluptate corporis accusamus. Lorem ipsum dolor sit amet consectetur adipisicing elit. Molestias adipisci autem ut illum, commodi incidunt aut earum at deserunt dolores, quo ea doloribus quae unde expedita id alias, necessitatibus explicabo! Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quasi modi necessitatibus, earum non distinctio hic praesentium quia, voluptatibus, excepturi consectetur saepe eligendi mollitia laboriosam repudiandae fugit dolorem perferendis cum maxime. Lorem ipsum dolor sit amet consectetur adipisicing elit. Odit delectus assumenda autem? Cum minus, id reprehenderit illo eaque maxime facilis praesentium repellat cumque adipisci inventore ab, corrupti, consequuntur culpa soluta.</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ex in eum dolorum sequi. Ut neque tempora facere dolorum? Officia beatae in ex sapiente iusto. Sequi eligendi aliquid voluptate iure mollitia! Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos, officiis impedit rerum dolorem at incidunt molestias explicabo voluptatibus! Dolorum rem quas atque cumque quos dolores aliquid. Aperiam, necessitatibus totam. Iusto! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Repellat tenetur molestiae incidunt accusantium necessitatibus animi deserunt vel dolor tempora ipsam repudiandae, fugit eaque minima, exercitationem fugiat, laboriosam non quam nulla. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Officiis soluta iure nesciunt non et modi aut qui nam dignissimos ab. Nostrum esse, ratione modi quia ut odio nobis perferendis sapiente. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Esse, fugit, facere voluptatum architecto incidunt minus commodi debitis qui ea dolorem illum itaque rem, aliquam eligendi quasi. Quibusdam labore eos sed.</p>
<h2>And Our Penultimate Heading, Everyone</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ratione quis ab ex rem ullam dolorem cupiditate eaque dolores officiis aut, velit excepturi voluptatem sed eligendi? Id fuga quibusdam consequatur officiis. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Neque mollitia esse quo at dolores distinctio vitae, eligendi deserunt dicta porro quibusdam. Laudantium iure reiciendis excepturi ipsa sed, maiores perspiciatis minima? Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero quas veniam sed eius nemo dignissimos a magnam architecto perspiciatis sunt sapiente, beatae nihil, sint odio. Enim vero reiciendis est! Eius. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Enim libero possimus in aperiam harum recusandae ullam explicabo architecto beatae id tempora earum, doloribus dolorum tenetur consectetur sed repellat iste nobis! Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusamus dolorem repudiandae totam. Illum quaerat autem ex, suscipit dolores possimus error vero eveniet, nostrum facere similique explicabo totam quis vitae beatae! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta distinctio ab fugit eum repellendus amet reprehenderit alias esse, ea explicabo a molestias aliquam maiores. Molestias facere mollitia sint magnam accusamus!</p>
<h2>Here Goes Our Last Heading</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vero esse unde aspernatur! Nemo deserunt quia, id ducimus rem fugiat maxime in magni quas provident incidunt tempora distinctio rerum adipisci qui! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorem iure quam officia, voluptatum numquam commodi quos assumenda asperiores saepe corrupti quibusdam similique nemo? Quas, earum vero! Corporis reprehenderit ad earum! Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque aliquid atque, distinctio ad magnam quae amet consequatur harum, perspiciatis culpa fugit praesentium. Eveniet nesciunt perferendis corporis sapiente soluta sint et? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere voluptatem porro excepturi! Nesciunt doloribus quisquam reprehenderit, libero ut nulla sequi laborum iste a voluptatibus adipisci tenetur esse, praesentium quo architecto! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id, sit laborum deleniti quo cum enim, molestias omnis facilis et ipsum est aliquam vitae quos iusto vel dolores ratione sint! Eos! Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, molestias. Exercitationem, rem cupiditate! Saepe, aliquam dolorem. Illum labore commodi eveniet optio explicabo sint facere minima, officiis assumenda quia, quasi voluptate. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Earum sint repellat amet tempore? Id quisquam eum iste expedita praesentium, maiores dolorum quos consequuntur voluptates suscipit vel et corporis dicta ullam.</p>
<footer>
<button class="stt">scroll to top</button>
</footer>
body {
padding: 1em 2em;
max-width: 1024px;
margin-inline: auto;
font-family: monospace;
font-size: 1em;
line-height: 1.5;
}
.stt {
display: none;
position: fixed;
bottom: 1em;
right: 1em;
width: 3.5em;
height: 3.5em;
line-height: 0;
text-indent: 5em;
white-space: nowrap;
overflow: hidden;
background: #aaa;
border: none;
border-radius: 50%;
cursor: pointer;
}
.stt::before {
position: absolute;
display: block;
text-indent: 0;
left: -0.15em;
top: -0.2em;
content: url("https://img.icons8.com/sf-ultralight/50/000000/chevron-up.png");
}
const scrollToTop = document.querySelector(".stt");
document.addEventListener("scroll", (e)=> {
if(window.pageYOffset >= 500) {
scrollToTop.style.display = "block";
}else {
scrollToTop.style.display = "none";
}
});
scrollToTop.addEventListener("click", (e) => {
window.scrollTo({left: 0, top: 0, behavior: "smooth"});
});
Also see: Tab Triggers