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="container">
<h2>CSS Tab</h2>
<p>
This pen uses radio buttons with opacity set to 0 as the toggles for the tabs.
</p>
<ul class="tabs">
<!-- Tab 1 -->
<li class="tab-item">
<div class="tab">
<!-- Tab switcher -->
<input type="radio" name="tab" value="tab1" checked>
<h3 class="label orange">Tab 1</h3>
<div class="tab-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus commodo gravida est. Proin mattis tristique tortor, quis ultrices ante condimentum quis. Duis mattis ultrices urna, sed aliquam neque suscipit vitae. Maecenas non interdum tortor. Integer ac nunc malesuada, viverra tortor quis, viverra dui. Etiam quis elementum eros. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus convallis suscipit risus non accumsan. Aenean quis nulla vehicula, lacinia orci ut, commodo massa.</p>
</div>
</div>
</li>
<!-- END Tab 1 -->
<!-- Tab 2 -->
<li class="tab-item">
<div class="tab">
<!-- Tab switcher -->
<input type="radio" name="tab" value="tab1">
<h3 class="label blue">Tab 2</h3>
<div class="tab-content">
<p>Nullam massa turpis, sollicitudin et fringilla sed, vestibulum sed justo. Fusce vel congue metus. Vivamus dapibus imperdiet leo, eu scelerisque risus sagittis eu. Nulla faucibus sed nunc quis sollicitudin. Curabitur tempor justo vitae sem volutpat placerat. Duis eu lorem id eros accumsan sollicitudin. Nullam eleifend vulputate est, id dapibus ligula aliquet vel. Nam mi lorem, fermentum non eros sit amet, aliquam volutpat nisl. Aliquam quis mi id dolor pharetra vulputate id ut lectus. Fusce ac ultricies nisi. Aliquam elementum eros a massa malesuada ultrices. Vestibulum feugiat tellus sit amet dui scelerisque, vitae dictum dui malesuada. Mauris tempor volutpat bibendum. Curabitur malesuada risus at lobortis porttitor. Cras sollicitudin bibendum turpis, nec dapibus mi.</p>
</div>
</div>
</li>
<!-- END Tab 2 -->
<!-- Tab 3 -->
<li class="tab-item">
<div class="tab">
<!-- Tab switcher -->
<input type="radio" name="tab" value="tab1">
<h3 class="label yellow">Tab 3</h3>
<div class="tab-content">
<p>Sed tempus mauris et metus tempus suscipit id eu leo. Phasellus in risus posuere, condimentum arcu quis, molestie lacus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus sit amet orci convallis turpis tincidunt elementum eget venenatis lorem. Nunc faucibus dictum magna vel imperdiet. Maecenas fermentum condimentum leo sed eleifend. Phasellus tristique porta venenatis. Donec sit amet suscipit odio. Cras vel tempus felis, eget accumsan turpis. Nam ultrices enim ac placerat porttitor.</p>
</div>
</div>
</li>
<!-- END Tab 3 -->
<!-- Tab 4 -->
<li class="tab-item">
<div class="tab">
<!-- Tab switcher -->
<input type="radio" name="tab" value="tab1">
<h3 class="label green">Tab 4</h3>
<div class="tab-content">
<p>Ut nec elit magna. Mauris turpis mi, iaculis quis sapien interdum, bibendum aliquam diam. Etiam blandit id tellus sit amet laoreet. Proin a cursus ante. Nullam rhoncus mauris rhoncus, fringilla turpis at, suscipit lorem. Curabitur dolor justo, aliquet eu vulputate ac, faucibus in mi. Morbi malesuada id nisl eu porttitor. Nunc nisl diam, gravida vitae feugiat ac, dictum eu tortor. Quisque id sem ornare, ullamcorper nisl at, aliquet turpis. In at magna in justo porta convallis. Vivamus in neque tortor. Cras bibendum ante quis ligula gravida, et ultrices erat consequat. Nunc sed turpis urna. Vivamus tempus molestie enim et lacinia. Nullam porttitor, mi elementum gravida euismod, est lorem gravida libero, quis ornare metus tellus ac elit.</p>
</div>
</div>
</li>
<!-- END Tab 4 -->
</ul>
</div>
/* Import the Google Font 'Open Sans' */
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
/* All widths and heights are calculated using the border box */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Positioning and layout of containers */
body {
background-color: #333333;
}
.container {
font-family: Open Sans, Helvetica, Arial, sans-serif;
font-size: 16px;
width: 800px;
height: 500px;
padding: 25px 50px;
margin: 50px auto;
box-shadow: 1px 1px 1px 1px rgba(100, 100, 100, 0.25);
background-color: white;
}
.tabs {
list-style: none;
padding: 0;
width: 650px;
margin: 0 auto;
}
.tab-item {
display: inline-block;
margin-left: -5px;
}
.tab {
position: absolute;
}
.tab > input[type=radio] {
opacity: 0;
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 50px;
margin: 0;
background-color: transparent;
outline: none;
z-index: 1;
}
.label {
display: inline-block;
position: absolute;
top: 0;
left: 0;
width: 150px;
margin: 0;
border-left: 1px solid rgba(100, 100, 100, 0.5);
text-align: center;
line-height: 50px;
background-position: 0 3px;
background-repeat: no-repeat;
background-size: 25px;
transition: background-position 250ms, color 250ms;
z-index: 0;
}
.label::before {
content: '';
position: absolute;
top: 0;
left: -1px;
width: 150px;
height: 3px;
}
.label::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
width: 147px;
height: 2px;
background-color: transparent;
}
.tabs .tab-item:last-child .label::after {
width: 146px;
}
/* In Firefox some width values need to be slightly different */
@-moz-document url-prefix() {
.label::before {
width: 155px;
}
.label::after {
width: 152px;
}
.tabs .tab-item:last-child .label::before {
width: 150px;
}
.tabs .tab-item:last-child .label::after {
width: 146px;
}
}
/* END Positioning and layout of containers */
/* Colors, graphics and positioning for tabs */
.label.orange {
background-image: url(https://dl.dropboxusercontent.com/s/68gv23q4y5qyq52/html5.svg);
}
.label.blue {
background-image: url(https://dl.dropboxusercontent.com/s/gftbpqje9h2jvlv/css3.svg);
}
.label.yellow {
background-image: url(https://dl.dropboxusercontent.com/s/jsp3rsberc4q650/javascript.svg);
}
.label.green {
background-image: url(https://dl.dropboxusercontent.com/s/v28zws1p38tjph2/node.png);
}
.label.orange::before {
background-color: #e34f26;
}
.label.blue::before {
background-color: #0d84ce;
}
.label.yellow::before {
background-color: #f0e040;
}
.label.green::before {
background-color: #83cd29;
}
.tabs .tab-item:last-child .label {
border-right: 1px solid rgba(100, 100, 100, 0.5);;
}
.tabs .tab-item:nth-child(2) input[type=radio],
.tabs .tab-item:nth-child(2) .label{
left: 150px;
}
.tabs .tab-item:nth-child(2) .tab-content {
left: 1px;
}
.tabs .tab-item:nth-child(3) input[type=radio],
.tabs .tab-item:nth-child(3) .label{
left: 300px;
}
.tabs .tab-item:nth-child(3) .tab-content {
left: 2px;
}
.tabs .tab-item:nth-child(4) input[type=radio],
.tabs .tab-item:nth-child(4) .label{
left: 450px;
}
.tabs .tab-item:nth-child(4) .tab-content {
left: 3px;
}
.tab > input[type=radio]:checked ~ .label::after {
background-color: white;
}
.tab > input[type=radio]:checked ~ .label {
color: #975997;
background-position: 12.5px 50%;
}
.tab > input[type=radio]:checked ~ .label.orange {
color: #e34f26;
background-image: url(https://dl.dropboxusercontent.com/s/68gv23q4y5qyq52/html5.svg);
}
.tab > input[type=radio]:checked ~ .label.blue {
color: #0d84ce;
}
.tab > input[type=radio]:checked ~ .label.yellow {
color: #f0e040;
}
.tab > input[type=radio]:checked ~ .label.green {
color: #83cd29;
}
.tab > input[type=radio]:checked ~ .tab-content p {
top: 0;
}
.tab > input[type=radio]:not(:checked) ~ .tab-content p {
top: 300px;
}
.tab-content {
position: absolute;
top: 50px;
width: 650px;
height: 265px;
padding: 0 20px;
overflow: hidden;
}
.tabs .tab-item:first-child .tab-content{
border: 1px solid rgba(100, 100, 100, 0.5);;
}
.tab-content p {
position: relative;
top: 300px;
transition: top 500ms;
}
/* END Colors, graphics and positioning for tabs */
Also see: Tab Triggers