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.
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.
.ctrl
.ctrl__button.ctrl__button--decrement –
.ctrl__counter
%input.ctrl__counter-input{type: "text", value: "0", maxlength: "10"}
.ctrl__counter-num 0
.ctrl__button.ctrl__button--increment +
*
user-select: none
box-sizing: border-box
html,
body
height: 100%
body
display: flex
align-items: center
justify-content: center
background-color: #EDF1F6
appearance: none !important
backface-visibility: hidden
-webkit-font-smoothing: antialiased
-moz-font-smoothing: antialiased
-moz-osx-font-smoothing: grayscale
-webkit-overflow-scrolling: touch
text-rendering: optimizelegibility
.ctrl
flex: 0 0 auto
display: flex
align-items: center
border-bottom: 1px solid #D5DCE6
background-color: #fff
border-radius: 5px
font-size: 30px
&__counter
position: relative
width: 200px
height: 100px
color: #333C48
text-align: center
overflow: hidden
&.is-input
.ctrl__counter-num
visability: hidden
opacity: 0
transition: opacity 100ms ease-in
.ctrl__counter-input
visability: visible
opacity: 1
transition: opacity 100ms ease-in
&-input
width: 100%
margin: 0
padding: 0
position: relative
z-index: 2
box-shadow: none
outline: none
border: none
color: #333C48
font-size: 30px
line-height: 100px
text-align: center
visability: hidden
opacity: 0
transition: opacity 100ms ease-in
&-num
position: absolute
z-index: 1
top: 0
left: 0
right: 0
bottom: 0
line-height: 100px
visability: visible
opacity: 1
transition: opacity 1000ms ease-in
&.is-increment-hide
opacity: 0
transform: translateY(-50px)
animation: increment-prev 100ms ease-in
&.is-increment-visible
opacity: 1
transform: translateY(0)
animation: increment-next 100ms ease-out
&.is-decrement-hide
opacity: 0
transform: translateY(50px)
animation: decrement-prev 100ms ease-in
&.is-decrement-visible
opacity: 1
transform: translateY(0)
animation: decrement-next 100ms ease-out
&__button
width: 100px
line-height: 100px
text-align: center
color: #fff
cursor: pointer
background-color: #8498a7
transition: background-color 100ms ease-in
&:hover
background-color: mix(#8498a7, #fff, 90%)
transition: background-color 100ms ease-in
&:active
background-color: mix(#8498a7, #000, 90%)
transition: background-color 100ms ease-in
&--decrement
border-radius: 5px 0 0 5px
&--increment
border-radius: 0 5px 5px 0
// keyframes
@keyframes decrement-prev
from
opacity: 1
transform: translateY(0)
@keyframes decrement-next
from
opacity: 0
transform: translateY(-50px)
@keyframes increment-prev
from
opacity: 1
transform: translateY(0)
@keyframes increment-next
from
opacity: 0
transform: translateY(50px)
(function() {
'use strict';
function ctrls() {
var _this = this;
this.counter = 0;
this.els = {
decrement: document.querySelector('.ctrl__button--decrement'),
counter: {
container: document.querySelector('.ctrl__counter'),
num: document.querySelector('.ctrl__counter-num'),
input: document.querySelector('.ctrl__counter-input')
},
increment: document.querySelector('.ctrl__button--increment')
};
this.decrement = function() {
var counter = _this.getCounter();
var nextCounter = (_this.counter > 0) ? --counter : counter;
_this.setCounter(nextCounter);
};
this.increment = function() {
var counter = _this.getCounter();
var nextCounter = (counter < 9999999999) ? ++counter : counter;
_this.setCounter(nextCounter);
};
this.getCounter = function() {
return _this.counter;
};
this.setCounter = function(nextCounter) {
_this.counter = nextCounter;
};
this.debounce = function(callback) {
setTimeout(callback, 100);
};
this.render = function(hideClassName, visibleClassName) {
_this.els.counter.num.classList.add(hideClassName);
setTimeout(function() {
_this.els.counter.num.innerText = _this.getCounter();
_this.els.counter.input.value = _this.getCounter();
_this.els.counter.num.classList.add(visibleClassName);
}, 100);
setTimeout(function() {
_this.els.counter.num.classList.remove(hideClassName);
_this.els.counter.num.classList.remove(visibleClassName);
}, 1100);
};
this.ready = function() {
_this.els.decrement.addEventListener('click', function() {
_this.debounce(function() {
_this.decrement();
_this.render('is-decrement-hide', 'is-decrement-visible');
});
});
_this.els.increment.addEventListener('click', function() {
_this.debounce(function() {
_this.increment();
_this.render('is-increment-hide', 'is-increment-visible');
});
});
_this.els.counter.input.addEventListener('input', function(e) {
var parseValue = parseInt(e.target.value);
if (!isNaN(parseValue) && parseValue >= 0) {
_this.setCounter(parseValue);
_this.render();
}
});
_this.els.counter.input.addEventListener('focus', function(e) {
_this.els.counter.container.classList.add('is-input');
});
_this.els.counter.input.addEventListener('blur', function(e) {
_this.els.counter.container.classList.remove('is-input');
_this.render();
});
};
};
// init
var controls = new ctrls();
document.addEventListener('DOMContentLoaded', controls.ready);
})();
Also see: Tab Triggers