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.
<section class="container">
<h1>CSS Accordions</h1>
<h3>Because we can.</h3>
<div class="ac">
<input class="ac-input" id="ac-1" name="ac-1" type="checkbox" />
<label class="ac-label" for="ac-1">Item 1</label>
<article class="ac-text">
<div class="ac-sub">
<input class="ac-input" id="ac-2" name="ac-2" type="checkbox" />
<label class="ac-label" for="ac-2">I love jelly donuts</label>
<article class="ac-sub-text">
<p>But not only is the sea such a foe to man who is an alien to it, but it is also a fiend to its own off-spring; worse than the Persian host who murdered his own guests; sparing not the creatures which itself hath spawned. Like a savage tigress that tossing in the jungle overlays her own cubs, so the sea dashes even the mightiest whales against the rocks, and leaves them there side by side with the split wrecks of ships. No mercy, no power but its own controls it. Panting and snorting like a mad battle steed that has lost its rider, the masterless ocean overruns the globe.</p>
<p>Consider the subtleness of the sea; how its most dreaded creatures glide under water, unapparent for the most part, and treacherously hidden beneath the loveliest tints of azure. Consider also the devilish brilliance and beauty of many of its most remorseless tribes, as the dainty embellished shape of many species of sharks. Consider, once more, the universal cannibalism of the sea; all whose creatures prey upon each other, carrying on eternal war since the world began.</p>
</article>
</div>
<div class="ac-sub">
<input class="ac-input" id="ac-3" name="ac-3" type="checkbox" />
<label class="ac-label" for="ac-3">They are so delicious</label>
<article class="ac-sub-text">
<p>My younger brother was in London when the Martians fell at Woking. He was a medical student working for an imminent examination, and he heard nothing of the arrival until Saturday morning. The morning papers on Saturday contained, in addition to lengthy special articles on the planet Mars, on life in the planets, and so forth, a brief and vaguely worded telegram, all the more striking for its brevity.</p>
<p>The Martians, alarmed by the approach of a crowd, had killed a number of people with a quick-firing gun, so the story ran. The telegram concluded with the words: "Formidable as they seem to be, the Martians have not moved from the pit into which they have fallen, and, indeed, seem incapable of doing so. Probably this is due to the relative strength of the earth's gravitational energy." On that last text their leader-writer expanded very comfortingly.</p>
</article>
</div>
</article><!--/ac-text-->
</div><!--/ac-->
<div class="ac">
<input class="ac-input" id="ac-4" name="ac-4" type="checkbox" />
<label class="ac-label" for="ac-4">Item 2</label>
<article class="ac-text">
<div class="ac-sub">
<input class="ac-input" id="ac-5" name="ac-5" type="checkbox" />
<label class="ac-label" for="ac-5">I also love regular donuts</label>
<article class="ac-sub-text">
<p>But not only is the sea such a foe to man who is an alien to it, but it is also a fiend to its own off-spring; worse than the Persian host who murdered his own guests; sparing not the creatures which itself hath spawned. Like a savage tigress that tossing in the jungle overlays her own cubs, so the sea dashes even the mightiest whales against the rocks, and leaves them there side by side with the split wrecks of ships. No mercy, no power but its own controls it. Panting and snorting like a mad battle steed that has lost its rider, the masterless ocean overruns the globe.</p>
<p>Consider the subtleness of the sea; how its most dreaded creatures glide under water, unapparent for the most part, and treacherously hidden beneath the loveliest tints of azure. Consider also the devilish brilliance and beauty of many of its most remorseless tribes, as the dainty embellished shape of many species of sharks. Consider, once more, the universal cannibalism of the sea; all whose creatures prey upon each other, carrying on eternal war since the world began.</p>
</article>
</div>
<div class="ac-sub">
<input class="ac-input" id="ac-6" name="ac-6" type="checkbox" />
<label class="ac-label" for="ac-6">They are also delicious</label>
<article class="ac-sub-text">
<p>My younger brother was in London when the Martians fell at Woking. He was a medical student working for an imminent examination, and he heard nothing of the arrival until Saturday morning. The morning papers on Saturday contained, in addition to lengthy special articles on the planet Mars, on life in the planets, and so forth, a brief and vaguely worded telegram, all the more striking for its brevity.</p>
<p>The Martians, alarmed by the approach of a crowd, had killed a number of people with a quick-firing gun, so the story ran. The telegram concluded with the words: "Formidable as they seem to be, the Martians have not moved from the pit into which they have fallen, and, indeed, seem incapable of doing so. Probably this is due to the relative strength of the earth's gravitational energy." On that last text their leader-writer expanded very comfortingly.</p>
</article>
</div>
</article><!--/ac-text-->
</div><!--/ac-->
</section>
@import "compass/css3";
// only for presentation purposes
body {
font-family: 'Source Sans Pro', sans-serif;
}
h1 {
padding-bottom: 0;
margin-bottom: 0;
}
h3 {
margin-top: 0;
font-weight: 300;
}
.container {
max-width: 40em;
margin: 10px auto;
}
// main level
.ac-label {
font-weight: 700;
position: relative;
padding: .5em 1em;
margin-bottom: .5em;
display: block;
cursor: pointer;
background-color: whiteSmoke;
transition: background-color .15s ease-in-out;
}
.ac-input:checked + label, .ac-label:hover {
background-color: #999;
}
.ac-label:after, .ac-input:checked + .ac-label:after {
content: "+";
position: absolute;
display: block;
right: 0;
top: 0;
width: 2em;
height: 100%;
line-height: 2.25em;
text-align: center;
background-color: #e5e5e5;
transition: background-color .15s ease-in-out;
}
.ac-label:hover:after, .ac-input:checked + .ac-label:after {
background-color: #b5b5b5;
}
.ac-input:checked + .ac-label:after {
content: "-";
}
.ac-input {
display: none;
}
// the magic
.ac-text, .ac-sub-text {
opacity: 0;
height: 0;
margin-bottom: .5em;
transition: opacity .5s ease-in-out;
overflow: hidden;
}
.ac-input:checked ~ .ac-text, .ac-sub .ac-input:checked ~ .ac-sub-text {
opacity: 1;
height: auto;
}
// sub-level
.ac-sub .ac-label {
background: none;
font-weight: 600;
padding: .5em 2em;
margin-bottom: 0;
}
.ac-sub .ac-label:checked {
background: none;
border-bottom: 1px solid whitesmoke;
}
.ac-sub .ac-label:after, .ac-sub .ac-input:checked + .ac-label:after {
left: 0;
background: none;
}
.ac-sub .ac-input:checked + label, .ac-sub .ac-label:hover {
background: none;
}
.ac-sub-text {
padding: 0 1em 0 2em;
}
Also see: Tab Triggers