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">
<div id="background" class="page-background">
<div style="width: 100%; text-align: center;">
<p>-- END --</p>
<p>Thanks for reading.</p>
</div>
</div>
<div id="page3" data-page-number="3" class="cssanimation page" onClick="hidePageByNumber(3)">
Third page.
</div>
<div id="page2" data-page-number="2" class="cssanimation page" onClick="hidePageByNumber(2)">
Second page.
</div>
<div id="page1" data-page-number="1" class="cssanimation page" onClick="hidePageByNumber(1)">
<p>Dear Friends,</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent euismod porta tempor. Donec pulvinar turpis nec velit pellentesque quis rhoncus sapien facilisis. Mauris quis massa dui, rhoncus viverra quam. Nulla tempus, augue ut consectetur facilisis, arcu elit pellentesque arcu, sed rutrum orci turpis pulvinar augue. Donec eget arcu mauris. Vestibulum tristique consequat lacus eget laoreet. Integer sed nisl sed nibh pulvinar ornare quis nec quam. Aenean rhoncus ligula ut lectus placerat a commodo quam vulputate. In eu metus turpis.</p>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus facilisis erat in nibh auctor at aliquet velit vestibulum. Curabitur turpis diam, malesuada eu consequat eget, ultricies sed nunc. Aenean sed odio massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ornare vulputate congue. Quisque leo metus, condimentum nec molestie et, egestas luctus libero.</p>
<p>Mauris porta odio augue. Nam turpis dui, volutpat id feugiat vitae, sagittis a justo. Nam iaculis aliquet erat non varius. Suspendisse justo arcu, tincidunt sed auctor sit amet, fermentum id turpis. Suspendisse sed enim quis lorem vestibulum fermentum a ut nulla.</p>
<p>Nullam tincidunt elit quis nibh blandit interdum. Duis ullamcorper pellentesque pretium. Nulla facilisi. Morbi semper nisi et justo varius non fermentum metus ornare. Proin vehicula, mi vel volutpat accumsan, libero lacus euismod massa, id feugiat velit enim nec ligula. Aliquam ipsum est, volutpat aliquam tincidunt id, sagittis et velit. Nunc vitae massa vel dui facilisis consectetur vel id sem.</p>
<p>Aenean pulvinar, lacus ultrices euismod viverra, nulla diam interdum ligula, id mollis mi erat quis lectus. Morbi quis felis ut turpis condimentum dictum porttitor id mauris. Nam non tincidunt mauris. Donec viverra eleifend pharetra. Nulla eu ipsum et elit consectetur rutrum. Integer lorem purus, ultricies ac laoreet quis, feugiat vel dolor. Donec eu turpis neque. Nullam molestie sapien eu nibh semper sed convallis est pretium.</p>
</div>
</div>
body {
background: linear-gradient(#ccc, #fff);
font: 14px sans-serif;
padding: 20px;
min-height: 700px;
}
.container
{
position: relative;
margin: 26px auto 0;
max-width: 600px;
width: 80%;
}
.page,
.page-background {
position: relative;
background: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
min-height: 600px;
padding: 24px;
width: 90%; /* 100% throws the div out over the right-side of .container */
}
.page-background
{
z-index: 1;
position: absolute;
}
.page
{
z-index: 2;
position: absolute;
cursor: grab;
}
.page-background:before,
.page-background:after {
content: "";
height: 98%;
position: absolute;
width: 100%;
z-index: -1;
}
.page-background:before {
background: #fafafa;
box-shadow: 0 0 8px rgba(0,0,0,0.2);
left: -5px;
top: 4px;
transform: rotate(-2.5deg);
}
.page-background:after {
background: #f6f6f6;
box-shadow: 0 0 3px rgba(0,0,0,0.2);
right: -3px;
top: 1px;
transform: rotate(1.4deg);
}
.cssanimation, .cssanimation span {
animation-duration: 1s;
animation-fill-mode: both;
}
.cssanimation span { display: inline-block }
.fadeOutLeft { animation-name: fadeOutLeft }
@keyframes fadeOutLeft {
from { opacity: 1 }
to {
opacity: 0;
transform: translateX(-100%);
}
}
var pageStack = {
//TODO: Implement.
visiblePageNumber: 1, // The currently visible page.
allPages: [1, 2, 3] // Ordered list of all pages.
};
/*
* Remove/hide the selected page from view for a given element ID.
*
* @param string pageID - ID of the element representing
* the page to hide.
*/
function hidePageById(pageId)
{
var pageElement = document.getElementById(pageId);
pageElement.classList.add("fadeOutLeft");
}
/*
* Remove/hide the selected page from view for a
* given data-page-number.
*
* @param int pageNumber - value of a data-page-number attribute
* for the page to hide.
*/
function hidePageByNumber(pageNumber)
{
var pageElement = document.querySelector("[data-page-number='" + pageNumber + "']");
pageElement.classList.add("fadeOutLeft");
pageStack.visiblePageNumber = getNextPageNumber(pageNumber);
console.log("Hiding page: " + pageNumber + ". Next page is: " + pageStack.visiblePageNumber);
}
/*
* Return the page in the stack after the specified page.
*
* @param int currentPage - Number of the current page.
* Looks for the page after this page.
*
* @return int Number of the next page.
* 0 (zero) if not found or currentPage is last page.
*/
function getNextPageNumber(currentPage)
{
let nextPageNumber = 0;
for (let i = 0; i < pageStack.allPages.length; i++)
{
let pageNumber = pageStack.allPages[i];
if (pageNumber == currentPage)
{
if (i == pageStack.allPages.length - 1)
{
// Current page is the final page.
nextPageNumber = 0;
}
else
{
// Get the next page
nextPageNumber = pageStack.allPages[i + 1];
break;
}
}
}
return nextPageNumber;
}
Also see: Tab Triggers