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="tabs-accordion">
<div class="action-group">
<div class="tab" data-tab="0">
<p>Label One</p>
</div>
<div class="tab" data-tab="1">
<p>Label Two</p>
</div>
<div class="tab" data-tab="2">
<p>Label Three</p>
</div>
<div class="tab" data-tab="3">
<p>Label Four</p>
</div>
<div class="action-content">
Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before. Many say exploration is part of our destiny, but it’s actually our duty to future generations and their quest to ensure the survival of the human species.
</div>
<div class="action-content action-content-hide">
Just say anything, George, say what ever's natural, the first thing that comes to your mind. Take that you mutated son-of-a-bitch. My pine, why you. You space bastard, you killed a pine. You do? Yeah, it's 8:00. Hey, McFly, I thought I told you never to come in here. Well it's gonna cost you. How much money you got on you?
</div>
<div class="action-content action-content-hide">
Cupcake ipsum dolor. Sit amet marshmallow topping cheesecake muffin. Halvah croissant candy canes bonbon candy. Apple pie jelly beans topping carrot cake danish tart cake cheesecake. Muffin danish chocolate soufflé pastry icing bonbon oat cake. Powder cake jujubes oat cake. Lemon drops tootsie roll marshmallow halvah carrot cake.
</div>
<div class="action-content action-content-hide">
Bacon ipsum dolor amet short ribs brisket venison rump drumstick pig sausage prosciutto chicken spare ribs salami picanha doner. Kevin capicola sausage, buffalo bresaola venison turkey shoulder picanha ham pork tri-tip meatball meatloaf ribeye. Doner spare ribs andouille bacon sausage. Ground round jerky brisket pastrami shank.
</div>
</div>
</div>
html,
body {
margin: 0;
}
.tabs-accordion {
font: normal 12pt/23px "Arial";
max-width: 700px;
margin: 20px auto;
display: flex;
position: relative;
}
.tabs-accordion p {
margin: 0;
}
.action-group {
width: 100%;
display: grid;
background-color: lightgrey;
grid-template-areas:
"tabOne tabTwo tabThree tabFour"
"contentOne contentTwo contentThree contentFour";
}
.action-group > div:nth-child(1) {
grid-area: tabOne;
}
.action-group > div:nth-child(2) {
grid-area: tabTwo;
}
.action-group > div:nth-child(3) {
grid-area: tabThree;
}
.action-group > div:nth-child(4) {
grid-area: tabFour;
}
.action-group > div:nth-child(5) {
grid-area: contentOne;
}
.action-group > div:nth-child(6) {
grid-area: contentTwo;
}
.action-group > div:nth-child(7) {
grid-area: contentThree;
}
.action-group > div:nth-child(8) {
grid-area: contentFour;
}
.action-group > div:nth-of-type(-n + 3) {
margin-right: 5px;
}
.action-group p {
background-color: rgb(150,150,150);
padding: 10px 15px;
text-align: center;
}
.active-tab {
background-color: rgb(110,110,110) !important;
}
.action-content {
padding: 10px;
grid-column: 1 / span 4 !important;
}
.tab {
cursor: pointer;
}
.action-content-hide {
display: none;
}
@media only screen and (max-width: 992px) {
.tabs-accordion {
display: block;
}
.action-group {
margin-bottom: 20px;
}
.action-group {
grid-template-areas:
"tabOne" "contentOne"
"tabTwo" "contentTwo"
"tabThree" "contentThree"
"tabFour" "contentFour";
}
.action-group > div {
grid-column: 1 / span 4 !important;
}
.action-group > div:nth-of-type(-n + 3) {
margin-right: 0;
}
}
var actionContent = document.querySelectorAll(".action-content"),
actionTab = document.getElementsByClassName("tab"),
actionContentArr = Array.from(actionContent),
actionTabArr = Array.from(actionTab);
// Hide sections
function hideSections() {
for (var i = 0; i < actionContentArr.length; i++) {
actionContentArr[i].classList.add("action-content-hide");
}
}
// Tab click events
for (var i = 0; i < actionTabArr.length; i++) {
actionTabArr[i].addEventListener("click", function (e) {
hideSections();
actionContentArr[this.dataset.tab].classList.remove("action-content-hide");
});
}
window.onresize = function () {
if (window.innerWidth < 993) {
for (var i = 0; i < actionContentArr.length; i++) {
actionContentArr[i].classList.add("action-content-hide");
}
} else {
hideSections();
}
actionContentArr[0].classList.remove("action-content-hide");
};
Also see: Tab Triggers