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="page-content">
<p>This is my solution for css-only tabs. It's not perfect, but has some advantages, like some degree of flexibility - the CSS is id-agnostic, so the HTML can be generated by server-side scripts (for example in WordPress shortcodes).</p>
<p>All you need to generate are the radio buttons' ids and names.</p>
<div class="tabbed">
<input type="radio" id="tab1" name="css-tabs" checked>
<input type="radio" id="tab2" name="css-tabs">
<input type="radio" id="tab3" name="css-tabs">
<ul class="tabs">
<li class="tab"><label for="tab1">Gangsta lipsum</label></li>
<li class="tab"><label for="tab2">Zombie lipsum</label></li>
<li class="tab"><label for="tab3">New age bullshit</label></li>
</ul>
<div class="tab-content">
<h4>Gangsta lipsum</h4>
<p>Da bomb ipsizzle dolizzle sit amizzle, consectetuer adipiscing fo shizzle. Nullam yo velizzle, aliquet volutpizzle, fo shizzle yippiyo, for sure vizzle, arcu. Black eget fo shizzle. Sizzle erizzle. Rizzle at dolizzle dapibizzle turpis tempizzle izzle. Maurizzle crackalackin nibh et check out this. Cool check it out tortizzle. Break it down bling bling rhoncizzle my shizz. Fo hizzle rizzle platea boom shackalack. Gangsta dapibus. Owned tellus urna, pretizzle black, mattizzle ac, eleifend for sure, nunc. Owned suscipizzle. Integizzle sempizzle shiz sed purizzle.</p>
</div>
<div class="tab-content">
<h4>Zombie lipsum</h4>
<p>Zombie ipsum brains reversus ab cerebellum viral inferno, brein nam rick mend grimes malum cerveau cerebro. De carne cerebro lumbering animata cervello corpora quaeritis. Summus thalamus brains sit, morbo basal ganglia vel maleficia? De braaaiiiins apocalypsi gorger omero prefrontal cortex undead survivor fornix dictum mauris. </p>
</div>
<div class="tab-content">
<h4>New age bullshit</h4>
<p>Our conversations with other pilgrims have led to an awakening of pseudo-astral consciousness. Who are we? Where on the great myth will we be re-energized? We are at a crossroads of complexity and stagnation.</p>
<p>Eons from now, we dreamers will exist like never before as we are aligned by the cosmos. We are being called to explore the stratosphere itself as an interface between nature and complexity. We must learn how to lead infinite lives in the face of bondage.</p>
<p>Generated by the <a href="http://sebpearce.com/bullshit/">New Age Bullshit Generator</a></p>
</div>
</div>
<p>The tabs are quite easy to use as they don't need absolute positioning and min-heights.</p>
<p>They can also be used multiple times in one document without any influence on CSS.</p>
<div class="tabbed">
<input type="radio" id="tab21" name="css-tabs2" checked>
<input type="radio" id="tab22" name="css-tabs2">
<input type="radio" id="tab23" name="css-tabs2">
<ul class="tabs">
<li class="tab"><label for="tab21">Gangsta lipsum</label></li>
<li class="tab"><label for="tab22">Zombie lipsum</label></li>
<li class="tab"><label for="tab23">New age bullshit</label></li>
</ul>
<div class="tab-content">
<h4>Gangsta lipsum</h4>
<p>Da bomb ipsizzle dolizzle sit amizzle, consectetuer adipiscing fo shizzle. Nullam yo velizzle, aliquet volutpizzle, fo shizzle yippiyo, for sure vizzle, arcu. Black eget fo shizzle. Sizzle erizzle. Rizzle at dolizzle dapibizzle turpis tempizzle izzle. Maurizzle crackalackin nibh et check out this. Cool check it out tortizzle. Break it down bling bling rhoncizzle my shizz. Fo hizzle rizzle platea boom shackalack. Gangsta dapibus. Owned tellus urna, pretizzle black, mattizzle ac, eleifend for sure, nunc. Owned suscipizzle. Integizzle sempizzle shiz sed purizzle.</p>
</div>
<div class="tab-content">
<h4>Zombie lipsum</h4>
<p>Zombie ipsum brains reversus ab cerebellum viral inferno, brein nam rick mend grimes malum cerveau cerebro. De carne cerebro lumbering animata cervello corpora quaeritis. Summus thalamus brains sit, morbo basal ganglia vel maleficia? De braaaiiiins apocalypsi gorger omero prefrontal cortex undead survivor fornix dictum mauris. </p>
</div>
<div class="tab-content">
<h4>New age bullshit</h4>
<p>Our conversations with other pilgrims have led to an awakening of pseudo-astral consciousness. Who are we? Where on the great myth will we be re-energized? We are at a crossroads of complexity and stagnation.</p>
<p>Eons from now, we dreamers will exist like never before as we are aligned by the cosmos. We are being called to explore the stratosphere itself as an interface between nature and complexity. We must learn how to lead infinite lives in the face of bondage.</p>
<p>Generated by the <a href="http://sebpearce.com/bullshit/">New Age Bullshit Generator</a></p>
</div>
</div>
<p>Unfortunately, these tabs have one downside: limited tab count. The limit is set in the CSS (see comments in the CSS code). But let's get real: who uses lots of tabs?</p>
<p>And one more thing: no animation to prevent annoying page jumps.</p>
<p>Have an improvement idea? Feel free to suggest it in the comments!</p>
</div>
body {
background-image: linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
ccc;
background-repeat: no-repeat;
font: 400 16px/1.5em "Open Sans", sans-serif;
}
.page-content {
max-width: 700px;
margin: 32px auto;
padding: 32px;
background: #fff;
}
a {
color: #21D4FD;
transition: all 0.3s;
}
a:hover {
color: #B721FF;
}
.tabbed {
overflow-x: hidden; /* so we could easily hide the radio inputs */
margin: 32px 0;
padding-bottom: 16px;
border-bottom: 1px solid #ccc;
}
.tabbed [type="radio"] {
/* hiding the inputs */
display: none;
}
.tabs {
display: flex;
align-items: stretch;
list-style: none;
padding: 0;
border-bottom: 1px solid #ccc;
}
.tab > label {
display: block;
margin-bottom: -1px;
padding: 12px 15px;
border: 1px solid #ccc;
background: #eee;
color: #666;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
cursor: pointer;
transition: all 0.3s;
}
.tab:hover label {
border-top-color: #333;
color: #333;
}
.tab-content {
display: none;
color: #777;
}
/* As we cannot replace the numbers with variables or calls to element properties, the number of this selector parts is our tab count limit */
.tabbed [type="radio"]:nth-of-type(1):checked ~ .tabs .tab:nth-of-type(1) label,
.tabbed [type="radio"]:nth-of-type(2):checked ~ .tabs .tab:nth-of-type(2) label,
.tabbed [type="radio"]:nth-of-type(3):checked ~ .tabs .tab:nth-of-type(3) label,
.tabbed [type="radio"]:nth-of-type(4):checked ~ .tabs .tab:nth-of-type(4) label,
.tabbed [type="radio"]:nth-of-type(5):checked ~ .tabs .tab:nth-of-type(5) label {
border-bottom-color: #fff;
border-top-color: #B721FF;
background: #fff;
color: #222;
}
.tabbed [type="radio"]:nth-of-type(1):checked ~ .tab-content:nth-of-type(1),
.tabbed [type="radio"]:nth-of-type(2):checked ~ .tab-content:nth-of-type(2),
.tabbed [type="radio"]:nth-of-type(3):checked ~ .tab-content:nth-of-type(3),
.tabbed [type="radio"]:nth-of-type(4):checked ~ .tab-content:nth-of-type(4) {
display: block;
}
Also see: Tab Triggers