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="tab-example">
<h1>TAB - HORIZONTAL</h1>
<ul class="tabs tabs-horizontal">
<li>
<input type="radio" id="tab-1" name="tab-h" checked>
<label class="tab-label tab-label-horizontal" for="tab-1">Tab 1</label>
<div id="tab-content-1 tab-content-horizontal">
<p>Praesent venenatis ultrices sapien nec aliquam. Aenean gravida nunc lacinia quam semper, sit amet sodales elit consequat. Suspendisse volutpat, lacus finibus vulputate tincidunt, dui ipsum laoreet nulla, sed ultrices lectus orci vel lacus. Pellentesque vitae lobortis orci. Ut vel tortor urna. Maecenas leo dolor, maximus accumsan convallis sed, dapibus vel metus. Pellentesque vitae neque porttitor, consequat ipsum eu, malesuada ante.</p>
</div>
</li>
<li>
<input type="radio" id="tab-2" name="tab-h">
<label class="tab-label tab-label-horizontal" for="tab-2">Tab 2</label>
<div id="tab-content-2 tab-content-horizontal">
<p>Morbi blandit metus sit amet ipsum blandit tincidunt. Sed semper pharetra ultricies. Proin sem urna, congue non ligula eget, vestibulum ullamcorper ipsum. Vivamus ipsum justo, egestas eget sapien in, mattis luctus augue. Curabitur aliquet eros eu aliquet accumsan. Aenean eget orci eleifend ligula lacinia fermentum. Nulla quis porttitor ex. Donec eleifend eros ut pharetra blandit.</p>
</div>
</li>
<li>
<input type="radio" id="tab-3" name="tab-h">
<label class="tab-label tab-label-horizontal" for="tab-3">Tab 3</label>
<div id="tab-content-3 tab-content-horizontal">
<p>Proin dapibus euismod arcu eget tempor. Proin eget porttitor est. Pellentesque mollis viverra nunc, vitae congue metus facilisis id. Ut elementum a ex a ultricies. Sed faucibus dolor a tortor porta congue. In quis rutrum enim, id tempus turpis. Phasellus risus orci, pharetra id dui ut, porta aliquam est. Curabitur ex leo, bibendum quis dolor sit amet, placerat mattis diam. Nulla ac malesuada justo. Vestibulum dictum aliquet augue. Donec vitae ultricies ipsum. Curabitur egestas nec dolor a tincidunt. Proin ac ligula vulputate, consequat neque ac, efficitur lacus. Etiam et consequat nisi, eget placerat nulla.</p>
</div>
</li>
</ul>
</div>
<div class="tab-example">
<h1>TAB - VERTICAL</h1>
<ul class="tabs tabs-vertical">
<li>
<input type="radio" id="tab-4" name="tab-v" checked>
<label class="tab-label tab-label-vertical" for="tab-4">Tab 4</label>
<div id="tab-content-4 tab-content-vertical">
<p>Praesent venenatis ultrices sapien nec aliquam. Aenean gravida nunc lacinia quam semper, sit amet sodales elit consequat. Suspendisse volutpat, lacus finibus vulputate tincidunt, dui ipsum laoreet nulla, sed ultrices lectus orci vel lacus. Pellentesque vitae lobortis orci. Ut vel tortor urna. Maecenas leo dolor, maximus accumsan convallis sed, dapibus vel metus. Pellentesque vitae neque porttitor, consequat ipsum eu, malesuada ante.</p>
</div>
</li>
<li>
<input type="radio" id="tab-5" name="tab-v">
<label class="tab-label tab-label-vertical" for="tab-5">Tab 5</label>
<div id="tab-content-5 tab-content-vertical">
<p>Morbi blandit metus sit amet ipsum blandit tincidunt. Sed semper pharetra ultricies. Proin sem urna, congue non ligula eget, vestibulum ullamcorper ipsum. Vivamus ipsum justo, egestas eget sapien in, mattis luctus augue. Curabitur aliquet eros eu aliquet accumsan. Aenean eget orci eleifend ligula lacinia fermentum. Nulla quis porttitor ex. Donec eleifend eros ut pharetra blandit.</p>
</div>
</li>
<li>
<input type="radio" id="tab-6" name="tab-v">
<label class="tab-label tab-label-vertical" for="tab-6">Tab 6</label>
<div id="tab-content-6 tab-content-vertical">
<p>Proin dapibus euismod arcu eget tempor. Proin eget porttitor est. Pellentesque mollis viverra nunc, vitae congue metus facilisis id. Ut elementum a ex a ultricies. Sed faucibus dolor a tortor porta congue. In quis rutrum enim, id tempus turpis. Phasellus risus orci, pharetra id dui ut, porta aliquam est. Curabitur ex leo, bibendum quis dolor sit amet, placerat mattis diam. Nulla ac malesuada justo. Vestibulum dictum aliquet augue. Donec vitae ultricies ipsum. Curabitur egestas nec dolor a tincidunt. Proin ac ligula vulputate, consequat neque ac, efficitur lacus. Etiam et consequat nisi, eget placerat nulla.</p>
</div>
</li>
</ul>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.tab-example {
max-width: 960px;
margin: 0 auto;
padding: 10px 50px;
background: #fc6;
}
h1 {
margin-bottom: 10px;
}
.tabs {
display: flex;
justify-content: flex-start; /* position of the tab */
align-items: stretch; /* for <li> to occupy the full height (horizontal) / width (vertical) */
position: relative;
list-style: none;
width: 100%;
min-height: 200px; /* height of the tab area */
color: #fff;
}
.tabs-horizontal {
flex-direction: row;
}
.tabs-vertical {
flex-direction: column;
}
[type="radio"] {
display: none; /* hide the radio button */
}
.tab-label {
display: inline-block;
padding: 5px 10px;
text-align: center;
cursor: pointer;
background: #9cf;
white-space: nowrap; /* prevent label from wrapping */
}
.tab-label-horizontal {
width: 80px;
height: 15%;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.tab-label-vertical {
width: 10%;
height: 30px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.tab-label:hover {
background: #39f;
}
.tab-label:active {
background: #fff;
color: #06f;
}
[id^="tab-content-"] {
display: none; /* hide the content of all tabs (not selected) */
padding: 5px 10px;
background: #06f;
width: 100%;
height: 100%;
overflow: scroll; /* able to scroll to see all content */
}
[id*="tab-content-horizontal"] {
position: absolute; /* layout as the content area for all tabs */
top: 15%; /* height of label */
left: 0; /* relative to <ul>, independent of how <li> is positioned */
height: 85%; /* adjust according to height of label */
}
[id*="tab-content-vertical"] {
position: absolute; /* layout as the content area for all tabs */
top: 0;
left: 10%; /* width of label */
width: 90%; /* adjust according to width of label */
}
[type="radio"]:checked + label {
background: #06f;
}
[type="radio"]:checked ~ [id^="tab-content-"] {
display: block; /* display the content of selected tab */
}
@media only screen and (max-width: 425px) {
.tabs {
display: block;
}
.tab-label {
width: 100%;
border-radius: 0;
border: 1px solid #006;
}
[id^="tab-content-"] {
position: static;
width: 100%;
border: 1px solid #006;
border-top: none;
}
}
Also see: Tab Triggers