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.
main
.accordion
.accordion-item
.accordion-header
h2 Lorem ipsum dolor sit amet 1
.accordion-body
p 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
.accordion-item
.accordion-header
h2 Lorem ipsum dolor sit amet 2
.accordion-body
p 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
.accordion-item
.accordion-header
h2 Lorem ipsum dolor sit amet 3
.accordion-body
p 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
.credits
p Animation inspired by:
a(href="https://dribbble.com/hellobaha" target="_blank") Bakhtiyar 😱 Sattarov
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500')
*
box-sizing: border-box
$blue: #2b42b6
$border-radius: 5px
body, html
width: 100%
height: 100%
font-family: 'Roboto', sans-serif
main
width: 100%
min-height: 100%
display: flex
justify-content: center
align-items: flex-start
background-color: $blue
padding: 150px 30px
.accordion
max-width: 550px
&-item
background-color: transparent
margin-bottom: 15px
border-radius: $border-radius
box-shadow: 0 2px 9px 0 rgba(black, .1)
transition: background-color .2s ease-in .3s
&.active
background-color: white
transition: background-color .2s ease-in 0s
.accordion
&-header
color: black
background-color: white
transition: background-color .2s ease-in 0s, color .2s ease-in .2s
h2
&:before, &:after
background-color: black
transition: background-color .2s ease-in .2s, transform .2s ease .1s
&:before
display: none
&:after
transform: rotate(90deg)
&-body
max-height: 900px
padding: 0 15px 15px
transition: max-height .3s ease-in 0s, padding .2s ease-in 0s
p
opacity: 1
transition: opacity .2s ease-in .2s
&-header
color: white
background-color: lighten($blue, 15%)
border-radius: $border-radius
padding: 25px 15px
cursor: pointer
transition: background-color .2s ease-out .3s, color .2s ease-out 0s
h2
position: relative
font-size: 1rem
font-weight: 500
letter-spacing: .025em
margin: 0
&:before, &:after
content: ""
position: absolute
background-color: white
transition: background-color .2s ease-in 0s, transform .2s ease 0s
&:before
width: 10px
height: 2px
right: 0
top: calc(50% - 1px)
&:after
width: 2px
height: 10px
right: 4px
top: calc(50% - 5px)
transform: none
&-body
max-height: 0
padding: 0 15px
overflow: hidden
transition: max-height .2s ease-out 0s, padding .1s ease-out .2s
p
font-size: .875rem
line-height: 1.6
opacity: 0
margin: 0
transition: opacity .2s ease-in 0s
.credits
position: absolute
bottom: 30px
right: 30px
font-size: 14px
p
color: lighten($blue, 30%)
margin: 0
a
color: white
const accordionItem = document.querySelectorAll('.accordion-item');
const onClickAccordionHeader = e => {
if (e.currentTarget.parentNode.classList.contains('active')) {
e.currentTarget.parentNode.classList.remove("active");
} else {
Array.prototype.forEach.call(accordionItem, e => e.classList.remove('active'));
e.currentTarget.parentNode.classList.add("active");
}
};
const init = () => {
Array.prototype.forEach.call(accordionItem, e => e.querySelector('.accordion-header').addEventListener('click', onClickAccordionHeader, false));
};
document.addEventListener('DOMContentLoaded', init);
Also see: Tab Triggers