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.
Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.
Upgrade to PROIf 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.
Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.
Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:
Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.
This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.
Upgrade to PRO
<div id="menu">
<div id="top"> <!-- "viewport" for menu -->
<div class="swipecontainer"> <!-- Moving part for menu items -->
<ul class="swipemenu">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Very long Six</li>
<li>Seven</li>
<li>Eight</li>
</ul>
<div id="menumarker"></div>
</div>
</div>
<div id="viewport"> <!-- "viewport" for content -->
<div id="content">
<div class="box one">
<h2>#1</h2>
<p>Hello there!<br/>
This pen shows how to recreate Android's "sliding tabs" (from the Play store for example) in pure Javascript and HTML.</p>
</div>
<div class="box two">
<h2>#2</h2>
<p>Hello there! this is number two</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
<div class="box three">
<h2>#3</h2>
<p>Hello there! this is number three, an example form:</p>
<form action="#" method="post">
<div>
<label for="name">Text Input:</label>
<input type="text" name="name" id="name" value="" tabindex="1" />
</div>
<div>
<h4>Radio Button Choice</h4>
<label for="radio-choice-1">Choice 1</label>
<input type="radio" name="radio-choice-1" id="radio-choice-1" tabindex="2" value="choice-1" />
<label for="radio-choice-2">Choice 2</label>
<input type="radio" name="radio-choice-2" id="radio-choice-2" tabindex="3" value="choice-2" />
</div>
<div>
<label for="select-choice">Select Dropdown Choice:</label>
<select name="select-choice" id="select-choice">
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
<option value="Choice 3">Choice 3</option>
</select>
</div>
<div>
<label for="textarea">Textarea:</label>
<textarea cols="40" rows="8" name="textarea" id="textarea"></textarea>
</div>
<div>
<label for="checkbox">Checkbox:</label>
<input type="checkbox" name="checkbox" id="checkbox" />
</div>
<div>
<input type="submit" value="Submit" />
</div>
</form>
</div>
<div class="box four">
<h2>#4</h2>
<ul>
<li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.</li>
<li>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</li>
<li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li>
<li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li>
</ul>
</div>
<div class="box ">
<h2>#5</h2>
<p>Hello there! this is number five</p>
</div>
<div class="box ">
<h2>#6</h2>
<p>Hello there! this is number six</p>
</div>
<div class="box ">
<h2>#7</h2>
<p>Hello there! this is number seven</p>
</div>
<div class="box ">
<h2>#8</h2>
<p>Final Destination! this is number eight</p>
</div>
</div>
</div>
</div>
#menu {
width:auto;
height:100%;
overflow:hidden;
background-color:#eee;
}
#top {
height:75px;
border-bottom:5px solid #eee;
background-color:white;
overflow:hidden;
position:relative;
}
div.swipecontainer {
position:absolute;
top:0;
left:0;
height:100%;
}
ul.swipemenu {
list-style:none;
display:block;
clear:both;
padding:0;
margin:0;
width:9000px;
overflow-x:hidden;
overflow-y:auto;
height:100%;
}
ul.swipemenu li {
float:left;
display:block;
padding:25px 50px;
margin:0;
cursor:pointer;
text-align:center;
border-right:2px solid #eee;
}
div#menumarker {
width:200px;
height:5px;
display:block;
position:absolute;
left:0px;
bottom:0px;
background-color:rgba(191, 64, 64, 1);
}
div #viewport {
position:relative;
width:auto;
height:900px;
overflow:hidden;
}
div#content {
width:9000px;
height:100%;
overflow-x:auto;
overflow-y:hidden;
position:absolute;
top:0px;
left:0px;
}
#content .box {
height:100%;
float:left;
padding:20px;
margin:0;
margin-right:100px;
box-shadow:0px 0px 10px #ccc;
background:white;
}
/*optional styling thingies */
body {
font-family:"Open Sans",sans-serif;
}
p,li,input,label,select {
font-size:14px;
line-height:1.5em;
}
var viewPort = document.getElementById('viewport');
//global variables
boxes = $(".box");
viewPortW = $(viewPort).outerWidth(true);
boxes.width(viewPortW-40);
boxW = $(boxes[0]).outerWidth(true);
menuItems = $(".swipemenu li").length;
menuItemW = $(".swipemenu li:first").outerWidth(true);
$("#menumarker").width(menuItemW);
activeIndex = 0;
//OPTIONS
animationOptions = {duration: 500, easing:"easeInOutCubic"}; //menu animations
swipeTreshold = 150; //activates swipe
//Actually Changing tabs
function setActive(i) {
current = $(boxes[i]);
current.addClass("active");
var marker = $("#menumarker");
var scrollBoundaryRight = viewPortW*0.6; //fraction of real viewport
var scrollBoundaryLeft = viewPortW*0.4;
//check if menumarker goes out of screen (on either side)
var dx=null;
if((marker.offset().left+marker.width()) > scrollBoundaryRight && (i>activeIndex)) {
dx = (marker.offset().left+marker.width()) - scrollBoundaryRight;
}
if (marker.offset().left < scrollBoundaryLeft && (i<activeIndex)) {
dx = marker.offset().left - scrollBoundaryLeft;
}
if(dx) { $(".swipecontainer").animate({left: "-="+dx+"px" }, animationOptions); }
//Change content
$("#content").animate({left: -(boxW*i) }, animationOptions);
//Update the colored box in the menu
var menuItem = $(".swipemenu li:eq("+i+")");
marker.animate({ left: menuItem.position().left,
width: menuItem.outerWidth()
}, animationOptions);
activeIndex = i;
}
//inital setting
setActive(0);
//EVENT listeners
//---------------
$(".swipemenu li").on("click",function(e){
var i = $(".swipemenu li").index($(e.currentTarget));
setActive(i);
});
//Hammer JS for all touch related magic
var mc = new Hammer(viewPort);
mc.add(new Hammer.Pan({ threshold: 0, pointers: 0, direction: Hammer.DIRECTION_HORIZONTAL }));
startX = $("#content").position().left;
//listen to events
mc.on("panstart panmove pancancel panend", function(ev){
if(ev.type=="panstart"){
startX = $("#content").position().left;
}
//update content position during touch event
else if(ev.type=="panmove") {
$("#content").css('left',startX + ev.deltaX+'px');
$("#menumarker").css('left',(menuItemW*activeIndex) + (-0.2*ev.deltaX)+'px');
}
else if(ev.type=="panend" || ev.type=="pancancel") {
if(ev.deltaX > swipeTreshold && activeIndex > 0) { //bigger than treshold, so next slide
setActive(activeIndex-1); console.log("previous!");
}
else if(ev.deltaX < swipeTreshold && activeIndex < menuItems-1 ) {
setActive(activeIndex+1); console.log("next!");
}
else {
//bounce effect
$("#content").animate({left: startX }, animationOptions);
$("#menumarker").animate({left: (menuItemW*activeIndex)}, animationOptions);
}
}
});
perspective
.
Also see: Tab Triggers