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.
.container
.cc
.cc-container
.brand-chip
.chip
i.fas.fa-microchip.fa-lg.fa-rotate-90
.brand
p Card Info
.info-container
.number
input.input(
placeholder="0000"
type="number"
tabindex="0"
onKeyPress="if(this.value.length==4) return false;")
input.input(
placeholder="0000"
type="number"
tabindex="1"
onKeyPress="if(this.value.length==4) return false;")
input.input(
placeholder="0000"
type="number"
tabindex="2"
onKeyPress="if(this.value.length==4) return false;")
input.input(
placeholder="0000"
type="number"
tabindex="3"
onKeyPress="if(this.value.length==4) return false;")
.bottom-info
.info-input
.date
input.input(
placeholder="00"
type="number"
tabindex="4"
onKeyPress="if(this.value.length==2) return false;")
p /
input.input(
placeholder="00"
type="number"
min="0"
max="99"
tabindex="5"
onKeyPress="if(this.value.length==2) return false;")
.type
.visa.hidden
i.fab.fa-cc-visa(style="font-size: 1.8em")
.master.hidden
i.fab.fa-cc-mastercard(style="font-size: 1.8em")
.amex.hidden
i.fab.fa-cc-amex(style="font-size: 1.8em")
.discover.hidden
i.fab.fa-cc-discover(style="font-size: 1.8em")
.default-card
i.fas.fa-credit-card(style="font-size: 1.8em")
.name
input.input(
placeholder="FIRST"
maxlength="13"
tabindex="6")
input.input(
placeholder="LAST"
maxlength="13"
tabindex="7")
.cvc-button-container
p CVC
.cvc-button
i.fas.fa-sort-down.fa-lg
.cvc
input.input.cvc-input(
placeholder="000"
type="number"
tabindex="8"
onKeyPress="if(this.value.length==3) return false;")
$radius: 15px
@keyframes inputValid
0%
z-index: -1
99%
z-index: -1
100%
z-index: 4
@keyframes inputInvalid
0%
z-index: 4
1%
z-index: -1
100%
z-index: -1
@keyframes slideDown
0%
transform: translateY(-30px)
100%
transform: translateY(0px)
@keyframes slideUp
0%
transform: translateY(0px)
100%
transform: translateY(-30px)
@keyframes rotateDown
0%
transform: rotate(-90deg)
100%
transform: rotate(0deg)
@keyframes rotateUp
0%
transform: rotate(0deg)
100%
transform: rotate(-90deg)
.cvc-hidden
animation: slideUp 1s cubic-bezier(.03,.71,.7,.94) forwards
.cvc-show
animation: slideDown 1s cubic-bezier(.03,.71,.7,.94) forwards
.cvc-button-down
animation: rotateDown 1s cubic-bezier(.03,.71,.7,.94) forwards
.cvc-button-up
animation: rotateUp 1s cubic-bezier(.03,.71,.7,.94) forwards
.cvc-input-show
animation: inputValid 1s cubic-bezier(.03,.71,.7,.94) forwards
.cvc-input-hide
animation: inputInvalid 1s cubic-bezier(.03,.71,.7,.94) forwards
input[type='number']
-moz-appearance:textfield
input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button
-webkit-appearance: none
margin: 0
.input
border: none
outline: none
background-color: rgba(0,0,0,0)
color: white
.input::placeholder
color: white
.number
.input
width: 20%
font-size: 22px
input:focus
border-bottom: 2px solid white
.date
.input
width: 24px
margin-left: 3px
font-size: 18px
p
padding-top: 3px
.name
.input
width: 50%
margin-left: 10px
font-size: 16px
text-transform: uppercase
.info-container
height: 60%
width: 100%
.number
width: 100%
height: 35%
display: flex
flex-direction: row
justify-content: space-around
align-items: center
.bottom-info
width: 100%
height: 50%
display: flex
flex-direction: row
.type
height: 100%
width: 40%
display: flex
align-items: center
justify-content: center
.info-input
height: 100%
width: 100%
display: flex
flex-direction: column
align-items: flex-end
justify-content: center
.date
width: 100%
height: 50%
display: flex
justify-content: flex-end
align-items: center
.name
width: 100%
height: 50%
display: flex
flex-direction: row
justify-content: center
align-items: center
margin-left: 20%
.brand-chip
border-top-left-radius: $radius
border-top-right-radius: $radius
height: 40%
width: 100%
display: flex
flex-direction: row
.chip
display: flex
justify-content: flex-start
padding-left: 15px
align-items: center
width: 50%
.brand
display: flex
width: 50%
height: 100%
justify-content: center
align-items: flex-start
.cvc
position: absolute
z-index: -1
width: 50px
height: 20px
position: relative
background-color: rgb(100,100,200)
display: flex
flex-direction: row
align-items: center
justify-content: center
font-size: 14px
margin-right: 20px
border-bottom-right-radius: 8px
border-bottom-left-radius: 8px
padding: 4px 0px
.input
width: 100%
padding-left: 9px
font-size: 16px
margin-bottom: 2px
.input::placeholder
font-size: 16px
.cvc-button-container:hover
cursor: pointer
.cvc-button-container
position: absolute
width: 50px
height: 10px
padding-bottom: 12px
padding-right: 20px
background-color: rgba(0,0,0,0)
border-bottom-right-radius: $radius
bottom: 35px
right: 0px
display: flex
align-items: center
justify-content: space-around
p
font-size: 14px
margin-bottom: 4px
margin-right: 5px
.cvc-button
margin-top: 10px
.cc-container
display: flex
flex-direction: column
box-shadow: 0px 1px 3px 0px rgba(0,0,0,0.4)
background: linear-gradient(35deg, red -100%, blue 100%)
border-radius: $radius
height: 175px
.cc
width: 300px
height: 210px
position: relative
background-color: rgba(0,0,0,0)
border-radius: $radius
margin-top: 20px
display: flex
flex-direction: column
align-items: flex-end
color: white
.hidden
display: none
.container
display: flex
align-self: center
justify-content: center
width: 350px
height: 400px
margin-top: 100px
body
display: flex
justify-content: center
align-items: center
width: 100%
height: 100vh
font-family: Helvetica
background: white
const cvcButtonListener = () => {
cvcButtonContainer.addEventListener('click', () => slideCvc(cvc, cvcButton, cvcInput));
}
const show = (cvc, button, input) => {
cvc.classList.remove('cvc-hidden');
cvc.classList.add('cvc-show');
input.classList.remove('cvc-input-show-hide');
input.classList.add('cvc-input-show');
button.classList.remove('cvc-button-up');
button.classList.add('cvc-button-down');
$('.cvc .input').focus();
}
const hide = (cvc, button, input) => {
cvc.classList.remove('cvc-show');
button.classList.remove('cvc-button-down');
input.classList.remove('cvc-input-show-show');
input.classList.add('cvc-input-hide');
cvc.classList.add('cvc-hidden');
button.classList.add('cvc-button-up');
$('.cvc .input').blur();
}
const slideCvc = (cvc, button, input) => {
let hidden = false;
const classList = Object.values(cvc.classList);
for( let i = 0; i < classList.length; i++) {
if(classList[i] === "cvc-hidden")
hidden = true
}
if(hidden === true) {
show(cvc, button, input)
} else {
hide(cvc, button, input)
}
}
const tabNumbers = () => {
const max = 4;
const numberInputs = document.querySelectorAll('.number .input');
numberInputs[0].focus();
$('.number .input').on('keyup', (e) => {
cardType(numberInputs[0]);
const length = e.currentTarget.value.length;
const curIndex = e.currentTarget.tabIndex;
if(length >= max) {
for(let i = 0; i < max; i++){
const index = parseInt(numberInputs[i].attributes.tabIndex.value, 10);
if(curIndex+1 == 4) {
const date = document.querySelectorAll('.date input')[0];
date.focus();
break;
}
if(index == (curIndex+1)) {
numberInputs[i].focus();
break;
}
}
}
});
}
const tabDates = () => {
const max = 2;
const dateInputs = document.querySelectorAll('.date .input');
$('.date .input').on('keyup', (e) => {
const length = e.currentTarget.value.length;
const curIndex = e.currentTarget.tabIndex;
if(length >= max) {
for(let i = 0; i < max; i++){
const index = parseInt(dateInputs[i].attributes.tabIndex.value, 10);
if(curIndex+1 == 6) {
const name = document.querySelectorAll('.name .input')[0];
name.focus();
break;
}
if(index == (curIndex+1)) {
dateInputs[i].focus();
break;
}
}
}
});
}
const nameEnter = () => {
const nameInputs = document.querySelectorAll('.name .input');
$('.name .input').on('keydown', (e) => {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
} else {
const key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
e.preventDefault();
}
}
const curIndex = e.currentTarget.tabIndex;
if(e.which === 13) {
if(curIndex === 6) {
nameInputs[1].focus();
}
if(curIndex === 7) {
document.querySelector('.cvc .input').focus();
show(cvc, cvcButton, cvcInput);
}
}
});
}
const cvcEnter = () => {
$('.cvc .input').on('keydown', (e) => {
if(e.which === 13) {
hide(cvc, cvcButton, cvcInput);
}
});
}
const cardType = (e) => {
const num = parseInt(e.value[0]);
if(num === 4){
// Visa
$('.visa').removeClass('hidden');
$('.discover').addClass('hidden');
$('.amex').addClass('hidden');
$('.master').addClass('hidden');
$('.default-card').addClass('hidden');
} else if(num === 5){
// MasterCard
$('.master').removeClass('hidden');
$('.discover').addClass('hidden');
$('.amex').addClass('hidden');
$('.visa').addClass('hidden');
$('.default-card').addClass('hidden');
} else if(num === 3){
// Amex
$('.amex').removeClass('hidden');
$('.discover').addClass('hidden');
$('.visa').addClass('hidden');
$('.master').addClass('hidden');
$('.default-card').addClass('hidden');
} else if(num === 6){
// Discover
$('.discover').removeClass('hidden');
$('.visa').addClass('hidden');
$('.amex').addClass('hidden');
$('.master').addClass('hidden');
$('.default-card').addClass('hidden');
} else {
$('.default-card').removeClass('hidden');
$('.discover').addClass('hidden');
$('.amex').addClass('hidden');
$('.master').addClass('hidden');
$('.visa').addClass('hidden');
}
}
const cvcButtonContainer = document.getElementsByClassName('cvc-button-container')[0];
const cvc = document.getElementsByClassName('cvc')[0];
const cvcButton = document.getElementsByClassName('cvc-button')[0];
const cvcInput = document.getElementsByClassName('cvc-input')[0];
const numberInputs = document.querySelectorAll('.number .input');
window.onload = () => {
hide(cvc, cvcButton, cvcInput);
cvcButtonListener();
tabNumbers();
tabDates();
nameEnter();
cvcEnter();
cvcClick();
}
Also see: Tab Triggers