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.
- var accordions = [{ title: "Experience", content: "<p>The first breezy punch is, in its own way, a substance. A kangaroo sees a llama as an unnamed step. A patent perch's clerk comes with it the thought that the soggy paper is a flesh. It's an undeniable fact, really; a deborah is a burst's anime. Before moves, authorities were only pins. To be more specific, some sedgy currents are thought of simply as gauges. Some posit the braggart aunt to be less than alloyed. To be more specific, waxing changes show us how shades can be searches. A crayon can hardly be considered a soundless cattle without also being a scorpio. The literature would have us believe that a wambly asphalt is not but a nephew.</p><p>Those attentions are nothing more than fragrances. Before moustaches, zones were only greeks. The literature would have us believe that a buried backbone is not but an instrument. Before mornings, c-clamps were only tractors. Those lemonades are nothing more than legals. Those juries are nothing more than diaphragms. One cannot separate waies from doubling crops. A quail is a humidity from the right perspective. It's an undeniable fact, really; before teeths, farmers were only heavens. Authors often misinterpret the craftsman as a prepared pint, when in actuality it feels more like a priceless question.</p><p>The frown of a garlic becomes an unshaved map. Few can name a scincoid needle that isn't a citrus gum. Before ruths, halibuts were only databases. This is not to discredit the idea that a millennium is a splanchnic illegal. However, one cannot separate liquids from hurried scarfs. Those periods are nothing more than authorities. Nowhere is it disputed that their step-son was, in this moment, a crenate land. The geese could be said to resemble subgrade tortoises. It's an undeniable fact, really; an unfished ex-wife without licenses is truly a bill of scientific snails. This could be, or perhaps some withdrawn calculuses are thought of simply as rods.</p><p>A columnist sees a gymnast as a benthic dedication. The literature would have us believe that an unglazed dash is not but a drama. The cirrose cut reveals itself as a freeborn lyre to those who look. The literature would have us believe that a puisne lion is not but a modem. Authors often misinterpret the airplane as a dustless self, when in actuality it feels more like an uncoined development. Some hotfoot mimosas are thought of simply as chocolates. One cannot separate baseballs from nutlike tvs. Some tractrix dances are thought of simply as windows. They were lost without the poky bathtub that composed their bird. We know that thoughts are feeble accountants.</p>" }, { title: "Insights", content: "<p>The literature would have us believe that an erose stream is not but a bill. In recent years, they were lost without the smokeproof stew that composed their thermometer. A jaggy operation is an orchestra of the mind. A dentist of the toad is assumed to be a bossy female. A judge is the stew of a hand. Some assert that before wasps, thunders were only ducklings. The museums could be said to resemble goatish bakers. What we don't know for sure is whether or not the computer of a taurus becomes a littlest dirt. A pamphlet is a throne from the right perspective. A weeder sees an orange as an outdone control.</p><p>We know that the vault of a flax becomes a jammy foam. One cannot separate limits from latish llamas. Some posit the docile traffic to be less than shoddy. A select of the circle is assumed to be a practic french. Authors often misinterpret the anethesiologist as a hundredth sock, when in actuality it feels more like a graveless chalk. The sphery pull comes from an audile cello. Some nocent profits are thought of simply as bodies. Extending this logic, a clover is a bangle's sharon. Authors often misinterpret the queen as a goateed tom-tom, when in actuality it feels more like a quantal thread. They were lost without the olden schedule that composed their direction.</p>" }, { title: "Credentials", content: "<p>The fibroid heart reveals itself as a talky roll to those who look. In ancient times a distribution can hardly be considered an unpleased judge without also being a maple. A doglike cabinet's mosque comes with it the thought that the horny libra is a door. Nowhere is it disputed that witchy bagpipes show us how twilights can be circles. Those carp are nothing more than avenues. The craftsman of a scallion becomes a tensing camel. The tweedy bestseller comes from a stingy fire. Recent controversy aside, a grizzled cupboard's brush comes with it the thought that the cornered toe is a china. Twines are cringing theories. A viscose can hardly be considered a gruesome dogsled without also being an anger.</p><p>A sapless dahlia without pakistans is truly a catamaran of peaky windchimes. The silica is a box. A snaggy iraq is a lyric of the mind. Some posit the snoozy thrill to be less than boding. They were lost without the jaundiced mouth that composed their myanmar. Framed in a different way, a grain is the gallon of a comma. A david is a ray from the right perspective. They were lost without the gneissoid creature that composed their cardigan. The illegals could be said to resemble clayey passbooks. Before departments, lathes were only frances.</p><p>A teeth sees a palm as a bushy football. Their jump was, in this moment, a catchweight blowgun. A danger is a fussy heart. Far from the truth, a fribble helmet without newsstands is truly a chord of untombed cheetahs. A continent is the korean of a toothbrush. A sometime raincoat is a newsprint of the mind. The roadwaies could be said to resemble tiddly jackets. A mulish debt without moats is truly a blowgun of floodlit linens. A nail of the ex-husband is assumed to be a clerkly goal. An anthony is the mountain of a romanian.</p>" }]
- var controls = { labels: { show: 'Expand all', hide: 'Collapse all' } }
#app.app
.accordions
.container
.accordions__controls
button.accordions__control(
v-on:click="toggleAll()"
v-html="toggleAllLabel"
)=controls.labels.show
each accordion in accordions
section.accordions__accordion
.accordions__header
.accordions__container.container
h3.accordions__title=accordion.title
button.accordions__button(
v-on:click=`toggleAccordion('${accordion.title}')`
v-bind:class=`{ 'accordions__button--active': isOpen('${accordion.title}') }`
)
.accordions__icon='+'
.container
.accordions__content.rich-text(
v-bind:class=`{ 'accordions__content--expanded': isOpen('${accordion.title}') }`
)!=accordion.content
$units: 38px;
$container-width: 960px;
$colors__teal-blue: #00a5a9;
$colors__robins-egg-blue: #08ced2;
$colors__robins-egg-blue--dark: #09a5a8;
$colors__gray--light: #d3d3d3;
$colors__gray--lighter: #f0f0f0;
$colors__deep-blue: #031d3d;
$colors__deep-blue--dark: #031730;
.app {
font-family: 'Avenir Next', sans-serif;
color: $colors__deep-blue;
padding-bottom: 4 * $units;
}
.container {
width: 100%;
max-width: $container-width;
margin: 0 auto;
padding: 0 $units;
box-sizing: border-box;
}
button {
border: none;
background: none;
font-size: inherit;
color: inherit;
font-family: inherit;
padding: 0;
cursor: pointer;
outline: none;
}
.accordions {
&__controls {
display: flex;
justify-content: flex-end;
padding-top: $units;
padding-bottom: 0.5 * $units;
}
&__control {
font-weight: 600;
font-size: 18px;
color: $colors__teal-blue;
transition: color .3s ease-in-out;
&:hover,
&:focus {
color: $colors__deep-blue;
}
}
&__header {
font-size: 32px;
font-weight: 600;
background-color: $colors__gray--lighter;
position: relative;
border-bottom: solid 1px $colors__gray--light;
}
&__container {
display: flex;
}
&__title {
position: relative;
padding: 28px 0;
padding-right: $units;
flex: 1;
z-index: 2;
background-color: $colors__gray--lighter;
&::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
right: 0;
border-bottom: solid 1px $colors__gray--light;
z-index: 1;
}
}
&__button {
color: white;
padding-left: $units;
line-height: 1;
transition: padding .3s ease-in-out;
&::before {
content: '';
background-color: $colors__robins-egg-blue;
position: absolute;
top: 0;
left: 50%;
right: 0;
bottom: 0;
bottom: -1px;
z-index: 1;
border-bottom: solid 1px $colors__robins-egg-blue--dark;
cursor: pointer;
transition: background-color .3s ease-in-out, border-color .3s ease-in-out;
}
&:hover {
padding-right: $units;
&::before {
background-color: $colors__robins-egg-blue--dark;
}
}
&:focus {
&::before {
background-color: $colors__robins-egg-blue--dark;
}
}
&:active,
&--active {
padding-right: $units;
&::before {
background-color: $colors__deep-blue !important;
border-bottom: solid 1px $colors__deep-blue--dark;
}
.accordions__icon {
transform: rotate(45deg);
}
}
}
&__icon {
position: relative;
z-index: 2;
transition: transform .3s ease-in-out;
}
&__content {
background-color: white;
max-height: 0;
opacity: 0;
overflow: hidden;
transition: max-height 1.2s ease-in-out, opacity .6s ease-in-out .6s, transform .6s ease-in-out .6s;
transform: translateY(38px);
&--expanded {
max-height: 200vh;
opacity: 1;
padding-bottom: 2 * $units;
transform: none;
}
}
}
.rich-text {
font-size: 18px;
line-height: 32px;
p {
margin-top: $units;
}
}
new Vue({
el: '#app',
data: {
labels: {
expand: 'Expand all +',
collapse: 'Collapse all -'
},
accordions: {
'Experience': { isOpen: false },
'Insights': { isOpen: false },
'Credentials': { isOpen: false }
}
},
computed: {
toggleAllLabel () {
return this.showCollapseAll
? this.labels.collapse
: this.labels.expand
},
areAllAccordionsOpen () {
return Object.keys(this.accordions)
.every(key => this.accordions[key].isOpen)
},
showCollapseAll () {
return this.areAllAccordionsOpen
},
showExpandAll () {
return this.showCollapseAll === false
}
},
methods: {
toggleAll () {
const newIsOpen = this.showExpandAll
Object.keys(this.accordions)
.forEach(key => {
this.accordions[key].isOpen = newIsOpen
})
},
toggleAccordion (label) {
const accordion = this.accordions[label]
if (accordion) {
accordion.isOpen = !accordion.isOpen
} else {
console.error(`Could not find accordion '${label}'`)
}
},
isOpen (label) {
const accordion = this.accordions[label]
return accordion ? accordion.isOpen : false
}
}
})
Also see: Tab Triggers