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.
//PEN HEADER
header.header
h1.header__title Multi Step Form with animations
.header__btns.btns
a.header__btn.btn(href="https://github.com/nat-davydova/multisteps-form" title="Check on Github" target="_blank") Check on Github
//PEN CONTENT
.content
//content inner
.content__inner
.container
//content title
h2.content__title.content__title--m-sm Pick animation type
//animations form
form.pick-animation.my-4
.form-row
.col-5.m-auto
select.pick-animation__select.form-control
option(value="scaleIn" selected) ScaleIn
option(value="scaleOut") ScaleOut
option(value="slideHorz") SlideHorz
option(value="slideVert") SlideVert
option(value="fadeIn") FadeIn
//content title
h2.content__title Click on steps or 'Prev' and 'Next' buttons
.container.overflow-hidden
//multisteps-form
.multisteps-form
//progress bar
.row
.col-12.col-lg-8.ml-auto.mr-auto.mb-4
.multisteps-form__progress
button.multisteps-form__progress-btn.js-active(type="button" title="User Info") User Info
button.multisteps-form__progress-btn(type="button" title="Address") Address
button.multisteps-form__progress-btn(type="button" title="Order Info") Order Info
button.multisteps-form__progress-btn(type="button" title="Comments") Comments
//form panels
.row
.col-12.col-lg-8.m-auto
form.multisteps-form__form
//single form panel
.multisteps-form__panel.shadow.p-4.rounded.bg-white.js-active(data-animation="scaleIn")
h3.multisteps-form__title Your User Info
.multisteps-form__content
.form-row.mt-4
.col-12.col-sm-6
input.multisteps-form__input.form-control(type="text" placeholder="First Name")
.col-12.col-sm-6.mt-4.mt-sm-0
input.multisteps-form__input.form-control(type="text" placeholder="Last Name")
.form-row.mt-4
.col-12.col-sm-6
input.multisteps-form__input.form-control(type="text" placeholder="Login")
.col-12.col-sm-6.mt-4.mt-sm-0
input.multisteps-form__input.form-control(type="email" placeholder="Email")
.form-row.mt-4
.col-12.col-sm-6
input.multisteps-form__input.form-control(type="password" placeholder="Password")
.col-12.col-sm-6.mt-4.mt-sm-0
input.multisteps-form__input.form-control(type="password" placeholder="Repeat Password")
.button-row.d-flex.mt-4
button.btn.btn-primary.ml-auto.js-btn-next(type="button" title="Next") Next
//single form panel
.multisteps-form__panel.shadow.p-4.rounded.bg-white(data-animation="scaleIn")
h3.multisteps-form__title Your Address
.multisteps-form__content
.form-row.mt-4
.col
input.multisteps-form__input.form-control(type="text" placeholder="Address 1")
.form-row.mt-4
.col
input.multisteps-form__input.form-control(type="text" placeholder="Address 2")
.form-row.mt-4
.col-12.col-sm-6
input.multisteps-form__input.form-control(type="text" placeholder="City")
.col-6.col-sm-3.mt-4.mt-sm-0
select.multisteps-form__select.form-control
option(selected) State...
option ...
.col-6.col-sm-3.mt-4.mt-sm-0
input.multisteps-form__input.form-control(type="text" placeholder="Zip")
.button-row.d-flex.mt-4
button.btn.btn-primary.js-btn-prev(type="button" title="Prev") Prev
button.btn.btn-primary.ml-auto.js-btn-next(type="button" title="Next") Next
//single form panel
.multisteps-form__panel.shadow.p-4.rounded.bg-white(data-animation="scaleIn")
h3.multisteps-form__title Your Order Info
.multisteps-form__content
.row
.col-12.col-md-6.mt-4
.card.shadow-sm
.card-body
h5.card-title Item Title
p.card-text Small and nice item description
a.btn.btn-primary(href="#" title="Item Link") Item Link
.col-12.col-md-6.mt-4
.card.shadow-sm
.card-body
h5.card-title Item Title
p.card-text Small and nice item description
a.btn.btn-primary(href="#" title="Item Link") Item Link
.row
.button-row.d-flex.mt-4.col-12
button.btn.btn-primary.js-btn-prev(type="button" title="Prev") Prev
button.btn.btn-primary.ml-auto.js-btn-next(type="button" title="Next") Next
//single form panel
.multisteps-form__panel.shadow.p-4.rounded.bg-white(data-animation="scaleIn")
h3.multisteps-form__title Additional Comments
.multisteps-form__content
.form-row.mt-4
textarea.multisteps-form__textarea.form-control(placeholder="Additional Comments and Requirements")
.button-row.d-flex.mt-4
button.btn.btn-primary.js-btn-prev(type="button" title="Prev") Prev
button.btn.btn-success.ml-auto(type="button" title="Send") Send
//mixins
@mixin transition-mix ($property: all, $duration: 0.2s, $timing: linear, $delay: 0s) {
transition-property: $property;
transition-duration: $duration;
transition-timing-function: $timing;
transition-delay: $delay;
}
@mixin position-absolute ($top: null, $left: null, $right: null, $bottom: null) {
position: absolute;
top: $top;
left: $left;
right: $right;
bottom: $bottom;
}
//basic variables
$theme-font-color: #2c2c2c;
//common styles
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: {
family: 'Poppins', sans-serif;
size: 16px;
}
color: $theme-font-color;
a {
color: inherit;
text-decoration: none;
}
}
.header__btn {
@include transition-mix;
padding: 10px 20px;
display: inline-block;
margin-right: 10px;
background-color: #fff;
border: 1px solid $theme-font-color;
border-radius: 3px;
cursor: pointer;
outline: none;
&:last-child {
margin-right: 0;
}
&:hover,
&.js-active{
color: #fff;
background-color: $theme-font-color;
}
}
//header styles
.header {
max-width: 600px;
margin: 50px auto;
text-align: center;
}
.header__title {
margin-bottom: 30px;
font: {
size: 2.1rem;
}
}
//content styles
.content {
width: 95%;
margin: 0 auto 50px;
}
.content__title {
margin-bottom: 40px;
font: {
size: 20px;
}
text-align: center;
}
.content__title--m-sm {
margin-bottom: 10px;
}
//multisteps variables
$color-secondary: #6c757d;
$color-primary: #007bff;
$btn-offset-vert: 20px;
$btn-circle-decor-dimensions: 13px;
//multisteps progress styles
.multisteps-form__progress {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}
.multisteps-form__progress-btn {
@include transition-mix($duration: .15s);
position: relative;
padding-top: $btn-offset-vert;
color: rgba($color-secondary, .7);
text-indent: -9999px;
border: none;
background-color: transparent;
outline: none !important;
cursor: pointer;
@media (min-width: 500px) {
text-indent: 0;
}
//circle decoration
&:before {
@include position-absolute($top: 0, $left: 50%);
display: block;
width: $btn-circle-decor-dimensions;
height: $btn-circle-decor-dimensions;
content: '';
transform: translateX(-50%);
transition: all .15s linear 0s,
transform .15s cubic-bezier(0.05, 1.09, 0.16, 1.4) 0s;
border: 2px solid currentColor;
border-radius: 50%;
background-color: #fff;
box-sizing: border-box;
z-index: 3;
}
//line decoration
&:after {
@include position-absolute($top: $btn-offset-vert/4, $left: calc(-50% - #{$btn-circle-decor-dimensions} / 2));
@include transition-mix($duration: .15s);
display: block;
width: 100%;
height: 2px;
content: '';
background-color: currentColor;
z-index: 1;
}
//last child - without line decoration
&:first-child {
&:after {
display: none;
}
}
//active styles
&.js-active {
color: $color-primary;
&:before {
transform: translateX(-50%) scale(1.2);
background-color: currentColor;
}
}
}
//multisteps form styles
.multisteps-form__form {
position: relative;
}
//multisteps panels styles
.multisteps-form__panel {
@include position-absolute($top: 0, $left: 0);
width: 100%;
height: 0;
opacity: 0;
visibility: hidden;
//active panels
&.js-active {
height: auto;
opacity: 1;
visibility: visible;
}
//scaleOut animation
&[data-animation="scaleOut"] {
transform: scale(1.1);
&.js-active {
@include transition-mix;
transform: scale(1);
}
}
//slideHorz animation
&[data-animation="slideHorz"] {
left: 50px;
&.js-active {
@include transition-mix($duration: .25s, $timing: cubic-bezier(0.2, 1.13, 0.38, 1.43));
left: 0;
}
}
//slideVert animation
&[data-animation="slideVert"] {
top: 30px;
&.js-active {
@include transition-mix();
top: 0;
}
}
//fadeIn animation
&[data-animation="fadeIn"] {
&.js-active {
@include transition-mix($duration: .3s);
}
}
//scaleOut
&[data-animation="scaleIn"] {
transform: scale(.9);
&.js-active {
@include transition-mix;
transform: scale(1);
}
}
}
//DOM elements
const DOMstrings = {
stepsBtnClass: 'multisteps-form__progress-btn',
stepsBtns: document.querySelectorAll(`.multisteps-form__progress-btn`),
stepsBar: document.querySelector('.multisteps-form__progress'),
stepsForm: document.querySelector('.multisteps-form__form'),
stepsFormTextareas: document.querySelectorAll('.multisteps-form__textarea'),
stepFormPanelClass: 'multisteps-form__panel',
stepFormPanels: document.querySelectorAll('.multisteps-form__panel'),
stepPrevBtnClass: 'js-btn-prev',
stepNextBtnClass: 'js-btn-next'
};
//remove class from a set of items
const removeClasses = (elemSet, className) => {
elemSet.forEach(elem => {
elem.classList.remove(className);
});
};
//return exect parent node of the element
const findParent = (elem, parentClass) => {
let currentNode = elem;
while(! (currentNode.classList.contains(parentClass))) {
currentNode = currentNode.parentNode;
}
return currentNode;
};
//get active button step number
const getActiveStep = elem => {
return Array.from(DOMstrings.stepsBtns).indexOf(elem);
};
//set all steps before clicked (and clicked too) to active
const setActiveStep = (activeStepNum) => {
//remove active state from all the state
removeClasses(DOMstrings.stepsBtns, 'js-active');
//set picked items to active
DOMstrings.stepsBtns.forEach((elem, index) => {
if(index <= (activeStepNum) ) {
elem.classList.add('js-active');
}
});
};
//get active panel
const getActivePanel = () => {
let activePanel;
DOMstrings.stepFormPanels.forEach(elem => {
if(elem.classList.contains('js-active')) {
activePanel = elem;
}
});
return activePanel;
};
//open active panel (and close unactive panels)
const setActivePanel = activePanelNum => {
//remove active class from all the panels
removeClasses(DOMstrings.stepFormPanels, 'js-active');
//show active panel
DOMstrings.stepFormPanels.forEach((elem, index) => {
if(index === (activePanelNum)) {
elem.classList.add('js-active');
setFormHeight(elem);
}
})
};
//set form height equal to current panel height
const formHeight = (activePanel) => {
const activePanelHeight = activePanel.offsetHeight;
DOMstrings.stepsForm.style.height = `${activePanelHeight}px`;
};
const setFormHeight = () => {
const activePanel = getActivePanel();
formHeight(activePanel);
}
//STEPS BAR CLICK FUNCTION
DOMstrings.stepsBar.addEventListener('click', e => {
//check if click target is a step button
const eventTarget = e.target;
if(!eventTarget.classList.contains(`${DOMstrings.stepsBtnClass}`)) {
return;
}
//get active button step number
const activeStep = getActiveStep(eventTarget);
//set all steps before clicked (and clicked too) to active
setActiveStep(activeStep);
//open active panel
setActivePanel(activeStep);
});
//PREV/NEXT BTNS CLICK
DOMstrings.stepsForm.addEventListener('click', e => {
const eventTarget = e.target;
//check if we clicked on `PREV` or NEXT` buttons
if(! ( (eventTarget.classList.contains(`${DOMstrings.stepPrevBtnClass}`)) || (eventTarget.classList.contains(`${DOMstrings.stepNextBtnClass}`)) ) )
{
return;
}
//find active panel
const activePanel = findParent(eventTarget, `${DOMstrings.stepFormPanelClass}`);
let activePanelNum = Array.from(DOMstrings.stepFormPanels).indexOf(activePanel);
//set active step and active panel onclick
if(eventTarget.classList.contains(`${DOMstrings.stepPrevBtnClass}`)) {
activePanelNum--;
} else {
activePanelNum++;
}
setActiveStep(activePanelNum);
setActivePanel(activePanelNum);
});
//SETTING PROPER FORM HEIGHT ONLOAD
window.addEventListener('load', setFormHeight, false);
//SETTING PROPER FORM HEIGHT ONRESIZE
window.addEventListener('resize', setFormHeight, false);
//changing animation via animation select !!!YOU DON'T NEED THIS CODE (if you want to change animation type, just change form panels data-attr)
const setAnimationType = (newType) => {
DOMstrings.stepFormPanels.forEach(elem => {
elem.dataset.animation = newType;
})
};
//selector onchange - changing animation
const animationSelect = document.querySelector('.pick-animation__select');
animationSelect.addEventListener('change', () => {
const newAnimationType = animationSelect.value;
setAnimationType(newAnimationType);
});
Also see: Tab Triggers