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="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div>
<div class="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
</div><!-- end of sub accordion -->
</div
</div><!-- end of accordion body -->
</div><!-- end of accordion item -->
<div class="accordion__item js-accordion-item active">
<div class="accordion-header js-accordion-header">Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div>
<div class="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
</div><!-- end of sub accordion -->
</div><!-- end of accordion body -->
</div><!-- end of accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Panel 3</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div>
<div class="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
</div><!-- end of sub accordion -->
</div><!-- end of accordion body -->
</div><!-- end of accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Panel 4</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Explicabo maiores eos eveniet numquam, ut doloribus provident vero blanditiis iure fugit deserunt libero dolorem. Quos hic incidunt aperiam sapiente accusantium, fugit error aliquam iusto alias saepe ducimus, in reprehenderit dolor nulla velit blanditiis enim vero rerum eveniet nostrum ut labore! Magnam vero quas sed, tenetur dolore nulla ea sapiente. Dolore cupiditate dicta possimus molestias modi! Ullam veritatis facilis expedita blanditiis consequuntur, quam dolore a, voluptas asperiores alias eum maxime sequi debitis qui autem laborum. At consequuntur soluta possimus sapiente porro perspiciatis pariatur aut qui labore, reprehenderit, nemo et reiciendis unde aspernatur officiis magni odit rem voluptates accusamus dolores eius, maxime ea. Aliquid, vero quod laborum eius iure fugit repudiandae quibusdam numquam eos ratione officia autem doloribus sit. Quaerat ullam minus placeat. Quisquam corporis sequi eius modi recusandae nostrum, beatae illo voluptatibus quia cumque quos atque natus nobis cupiditate. Error, amet voluptas consequatur facilis nobis magni sapiente quae sint earum. Sapiente ipsum assumenda deleniti, eum debitis neque molestias similique voluptate minima. Pariatur aliquid voluptatibus facere placeat vel, exercitationem delectus voluptates animi ipsam sed provident quas nesciunt enim, optio autem culpa quam dolorem maiores molestiae? Modi adipisci reiciendis molestias expedita quo ullam. Porro!
</div>
<div class="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
</div><!-- end of sub accordion -->
</div><!-- end of accordion body -->
</div><!-- end of accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Panel 5</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquid aperiam rem doloremque debitis culpa! Exercitationem suscipit quasi, ipsum nulla ipsa error vitae quibusdam distinctio sit aliquid tempora veniam porro doloribus dolorum fugit ex eligendi sunt enim quae laboriosam odio. Beatae nisi harum nihil alias tempora assumenda explicabo. Perferendis, numquam nesciunt? Atque ullam quidem laborum nostrum neque quis! Possimus modi repellendus aut totam blanditiis molestiae vel et nostrum doloribus beatae, at voluptatem illum. Numquam quos consectetur et iste, aspernatur possimus, fugit tempora corporis quas quasi vel fuga. Eum minima laborum inventore architecto, explicabo minus consectetur quaerat molestiae sed, quam alias, sint cumque. Unde dicta ad illum porro eos deserunt debitis perspiciatis asperiores tenetur ex ipsam aperiam ullam, aliquid neque explicabo dolorum recusandae, laboriosam sapiente ratione hic minus pariatur modi incidunt minima! Consequuntur assumenda quidem natus veniam? Quam blanditiis aspernatur molestiae quas hic animi maxime ea nostrum officia velit dolorum ipsum, beatae natus, eius iste voluptas accusamus eum, repellendus dolor eligendi. Delectus, expedita! Debitis fugiat reprehenderit aliquam nihil, officia molestiae soluta, odit ratione iusto vel consequuntur omnis libero? Nisi magnam quaerat obcaecati iusto, cupiditate sapiente voluptas doloremque sunt, nobis labore itaque facere similique sed est ratione cum tempore autem vel corrupti. Ducimus.
</div>
<div class="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
</div><!-- end of sub accordion -->
</div><!-- end of accordion body -->
</div><!-- end of accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Panel 6</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div>
<div class="accordion js-accordion">
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 1</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
<div class="accordion__item js-accordion-item">
<div class="accordion-header js-accordion-header">Sub Panel 2</div>
<div class="accordion-body js-accordion-body">
<div class="accordion-body__contents">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos sequi placeat distinctio dolor, amet magnam voluptatibus eos ex vero, sunt veritatis esse. Nostrum voluptatum et repudiandae vel sed, explicabo in?
</div><!-- end of sub accordion item body contents -->
</div><!-- end of sub accordion item body -->
</div><!-- end of sub accordion item -->
</div><!-- end of sub accordion -->
</div><!-- end of accordion body -->
</div><!-- end of accordion item -->
</div><!-- end of accordion -->
body {
font-size: 62.5%;
background: #dadada;
font-family: 'Open Sans', sans-serif;
line-height: 2;
padding: 5em;
}
.accordion {
font-size: 1rem;
width: 30vw;
margin: 0 auto;
border-radius: 5px;
}
.accordion-header,
.accordion-body {
background: white;
}
.accordion-header {
padding: 1.5em 1.5em;
background: #3F51B5;
color: white;
cursor: pointer;
font-size: .7em;
letter-spacing: .1em;
transition: all .3s;
text-transform: uppercase;
}
.accordion__item {
border-bottom: 1px solid #3a4ba4;
}
.accordion__item .accordion__item {
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.accordion-header:hover {
background: #2D3D99;
position: relative;
z-index: 5;
}
.accordion-body {
background: #fcfcfc;
color: #353535;
display: none;
}
.accordion-body__contents {
padding: 1.5em 1.5em;
font-size: .85em;
}
.accordion__item.active:last-child .accordion-header {
border-radius: none;
}
.accordion:first-child > .accordion__item > .accordion-header {
border-bottom: 1px solid transparent;
}
.accordion__item > .accordion-header:after {
content: "\f3d0";
font-family: IonIcons;
font-size: 1.2em;
float: right;
position: relative;
top: -2px;
transition: .3s all;
transform: rotate(0deg);
}
.accordion__item.active > .accordion-header:after {
transform: rotate(-180deg);
}
.accordion__item.active .accordion-header {
background: #2D3D99;
}
.accordion__item .accordion__item .accordion-header {
background: #f1f1f1;
color: #353535;
}
@media screen and (max-width: 1000px) {
body {
padding: 1em;
}
.accordion {
width: 100%;
}
}
var accordion = (function(){
var $accordion = $('.js-accordion');
var $accordion_header = $accordion.find('.js-accordion-header');
var $accordion_item = $('.js-accordion-item');
// default settings
var settings = {
// animation speed
speed: 400,
// close all other accordion items if true
oneOpen: false
};
return {
// pass configurable object literal
init: function($settings) {
$accordion_header.on('click', function() {
accordion.toggle($(this));
setTimeout(() => {
$('body, html').animate({
scrollTop: $(this).offset().top
}, 500)
}, 400)
});
$.extend(settings, $settings);
// ensure only one accordion is active if oneOpen is true
if(settings.oneOpen && $('.js-accordion-item.active').length > 1) {
$('.js-accordion-item.active:not(:first)').removeClass('active');
}
// reveal the active accordion bodies
$('.js-accordion-item.active').find('> .js-accordion-body').show();
},
toggle: function($this) {
if(settings.oneOpen && $this[0] != $this.closest('.js-accordion').find('> .js-accordion-item.active > .js-accordion-header')[0]) {
$this.closest('.js-accordion')
.find('> .js-accordion-item')
.removeClass('active')
.find('.js-accordion-body')
.slideUp()
}
// show/hide the clicked accordion item
$this.closest('.js-accordion-item').toggleClass('active');
$this.next().stop().slideToggle(settings.speed);
}
}
})();
$(document).ready(function(){
accordion.init({ speed: 300, oneOpen: true });
});
Also see: Tab Triggers