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.
<div class="page">
<header class="header">
<div class="container">
<div class="header-wrapper">
<div class="logo">Logo</div>
</div>
</div>
</header>
<main class="main">
<div class="container">
<p class="subtitle">GreenSock</p>
<h1 class="title">
Accordion
</h1>
<div class="accordion">
<div class="accordion__title">
<h2>Lacus sed turpis tincidunt id aliquet</h2>
<div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
</div>
<div class="accordion__content">
<div class="accordion__content-wrapper">
Risus feugiat in ante. Cursus metus aliquam eleifend mi in nulla. Scelerisque mauris pellentesque pulvinar pellentesque habitant. Suspendisse ultrices gravida dictum fusce ut placerat orci. Adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus. Vivamus arcu felis bibendum ut tristique et egestas quis. Eu consequat ac felis donec. Eu turpis egestas pretium aenean pharetra magna ac. Velit ut tortor pretium viverra suspendisse potenti nullam. Donec enim diam vulputate ut pharetra sit. Quisque sagittis purus sit amet volutpat consequat mauris nunc congue. Massa sapien faucibus et molestie ac feugiat sed lectus. Quis commodo odio aenean sed. Morbi leo urna molestie at elementum eu facilisis sed odio.
</div>
</div>
</div>
<div class="accordion">
<div class="accordion__title">
<h2>Tellus orci ac auctor augue mauris</h2>
<div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
</div>
<div class="accordion__content">
<div class="accordion__content-wrapper">
Sit amet consectetur adipiscing elit ut aliquam. Arcu non odio euismod lacinia. In hac habitasse platea dictumst quisque sagittis purus sit amet. Auctor augue mauris augue neque gravida in. Pretium vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae. Sit amet dictum sit amet justo donec. Odio euismod lacinia at quis risus sed vulputate odio ut. Aliquam eleifend mi in nulla. Maecenas sed enim ut sem viverra aliquet eget sit. Tristique magna sit amet purus.
</div>
</div>
</div>
<div class="accordion">
<div class="accordion__title">
<h2>Amet consectetur adipiscing elit</h2>
<div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
</div>
<div class="accordion__content">
<div class="accordion__content-wrapper">
Ut aliquam purus sit amet luctus. Sit amet consectetur adipiscing elit pellentesque habitant morbi. Cursus in hac habitasse platea dictumst quisque sagittis purus sit. Fames ac turpis egestas integer eget aliquet nibh praesent tristique. In est ante in nibh mauris cursus. Tincidunt vitae semper quis lectus nulla at volutpat diam ut. Morbi quis commodo odio aenean sed adipiscing. Massa eget egestas purus viverra accumsan in nisl. Tristique magna sit amet purus gravida quis. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Urna porttitor rhoncus dolor purus non enim praesent elementum. Lorem sed risus ultricies tristique nulla. Sit amet consectetur adipiscing elit duis tristique sollicitudin nibh. Orci nulla pellentesque dignissim enim sit amet venenatis. Ut lectus arcu bibendum at.
</div>
</div>
</div>
<div class="accordion">
<div class="accordion__title">
<h2>Aliquet nibh praesent tristique magna sit amet purus</h2>
<div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
</div>
<div class="accordion__content">
<div class="accordion__content-wrapper">
Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed. Mauris in aliquam sem fringilla ut morbi tincidunt augue. Ut placerat orci nulla pellentesque dignissim enim sit. Ultricies tristique nulla aliquet enim tortor at auctor. Leo vel fringilla est ullamcorper eget nulla facilisi etiam dignissim. Odio tempor orci dapibus ultrices. Duis at tellus at urna condimentum mattis pellentesque id nibh. Nisl pretium fusce id velit ut tortor pretium viverra. Nisl nunc mi ipsum faucibus vitae aliquet.
</div>
</div>
</div>
<div class="accordion">
<div class="accordion__title">
<h2>Fermentum leo vel orci porta non pulvinar</h2>
<div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
</div>
<div class="accordion__content">
<div class="accordion__content-wrapper">
Vel eros donec ac odio tempor orci dapibus ultrices. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh sed. Ornare arcu dui vivamus arcu felis bibendum ut tristique et. Lorem donec massa sapien faucibus et molestie ac. Quisque non tellus orci ac auctor augue mauris augue. Volutpat consequat mauris nunc congue nisi vitae. Pretium quam vulputate dignissim suspendisse in est ante in nibh. Mauris a diam maecenas sed enim ut sem. Elementum integer enim neque volutpat ac tincidunt vitae semper. Malesuada bibendum arcu vitae elementum curabitur vitae nunc. Eu sem integer vitae justo eget magna fermentum iaculis. Nibh sed pulvinar proin gravida. Sit amet nulla facilisi morbi tempus iaculis urna id. Magna fermentum iaculis eu non diam phasellus vestibulum lorem sed. In mollis nunc sed id semper risus in. Nec dui nunc mattis enim ut tellus elementum sagittis vitae. Posuere morbi leo urna molestie at elementum eu facilisis sed. Nullam ac tortor vitae purus faucibus ornare suspendisse. A scelerisque purus semper eget duis at.
</div>
</div>
</div>
</div>
</main>
</div>
*,
*::after,
*::before {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
font-family: sans-serif;
font-size: 20px;
line-height: 1.4;
height: 100%;
}
.page {
display: flex;
flex-direction: column;
height: 100%;
}
.container {
margin: 0 auto;
padding: 0 24px;
max-width: 80%;
height: 100%;
}
main {
flex: 1 0 auto;
padding: 32px 0 64px 0;
background: #ebebeb;
}
.header {
height: 80px;
flex-shrink: 0;
color: #fff;
background: indigo;
}
.header-wrapper {
height: 100%;
display: flex;
align-items: center;
}
.logo {
text-transform: uppercase;
font-weight: bold;
font-size: 24px;
}
.title {
margin-top: -12px;
}
.subtitle {
text-align: left;
margin: 0;
}
.accordion {
margin-bottom: 24px;
border-radius: px;
overflow: hidden;
}
.accordion__title {
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
background: #4b0082; /* indigo */
color: white;
padding: 16px 24px;
}
.accordion__title h2 {
margin: 0;
padding-right: 48px;
}
.accordion__icon i {
font-size: 24px;
}
.accordion__content:first-child {
transform: scale(-1);
}
.accordion__content {
background: white;
/* !!! */
overflow: hidden;
height: 0;
}
.accordion__content:first-child {
height: auto;
background: indigo;
color: #000;
}
.accordion__content-wrapper {
padding: 24px;
}
const list = gsap.utils.toArray(".accordion");
list.forEach((accordion, index) => {
let isOpen = index === 0 ? true : false;
const title = accordion.getElementsByClassName("accordion__title")[0];
const icon = accordion.getElementsByClassName("accordion__icon")[0];
const content = accordion.getElementsByClassName("accordion__content")[0];
gsap.set(
title,
isOpen
? { background: "#fff", color: "#000" }
: { background: "#4b0082", color: "#fff" }
);
gsap.set(content, { height: isOpen ? "auto" : "0px" });
gsap.set(icon, { scale: isOpen ? -1 : 1 });
title.addEventListener("click", () => {
isOpen = !isOpen;
gsap.to(
title,
isOpen
? { background: "#fff", color: "#000" }
: { background: "#4b0082", color: "#fff" }
);
gsap.to(content, { height: isOpen ? "auto" : "0px" });
gsap.to(icon, { scale: isOpen ? -1 : 1 });
});
});
Also see: Tab Triggers