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="content">
<div class="tabWrapper">
<div class="tabs">
<div role="tablist" aria-label="tabs">
<button role="tab" aria-selected="true" id="tab-1">
Tab 1
</button>
<button role="tab" aria-selected="false" id="tab-2">Tab 2
</button>
<button role="tab" aria-selected="false" id="tab-3">
Tab 3
</button>
</div>
<div role="tabpanel" aria-labelledby="tab-1">
<h3>Tab 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla mattis nec nisi tempus scelerisque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ut nisl ante. Vivamus bibendum erat eu blandit congue. Mauris posuere mi eu enim finibus vestibulum. Nam lectus risus, ultricies quis libero sit amet, congue aliquam nisl. Nullam venenatis eros rhoncus venenatis faucibus. Nulla pellentesque posuere maximus. Nulla odio libero, bibendum a auctor sit amet, luctus ac mi. Praesent ipsum nunc, rhoncus sit amet malesuada quis, sollicitudin ut ante. Maecenas nec risus eleifend, tincidunt metus at, venenatis arcu. Morbi quis hendrerit magna, scelerisque euismod massa. Suspendisse sed auctor lorem. Nunc et eros tortor. Donec scelerisque nibh non dui ullamcorper, sit amet pharetra urna lobortis. Mauris pretium dolor molestie mattis porta.</p>
</div>
<div role="tabpanel" aria-labelledby="tab-2" hidden>
<h3>Tab 2</h3>
<p>Pellentesque tristique luctus eros vitae pulvinar. Nam eleifend lacus ut odio viverra mattis. Vestibulum sed sapien tellus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed convallis, nibh nec sollicitudin dignissim, tellus tortor iaculis felis, vitae tincidunt augue nibh et erat. Etiam suscipit sapien dolor, quis placerat ex iaculis tincidunt. Nam egestas semper odio, et tempus diam tincidunt eget. Aenean ac purus libero. Etiam egestas tempor lacus vel pretium. Donec in ipsum nec enim commodo pretium. Vivamus ut vulputate magna. Donec ullamcorper justo finibus, efficitur dolor a, dapibus purus. Nam malesuada gravida nisl eget placerat. Aenean diam urna, aliquet a odio ut, luctus condimentum diam. In elementum sagittis elit, sed dapibus velit congue quis. Pellentesque cursus vulputate egestas.</p>
</div>
<div role="tabpanel" aria-labelledby="tab-3" hidden>
<h3>Tab 3</h3>
<p>Cras in risus sit amet ex auctor imperdiet. Aenean posuere interdum dui sed maximus. Vivamus volutpat rutrum consequat. Aliquam lobortis ornare vehicula. Pellentesque sollicitudin ut lorem ut accumsan. Praesent in justo mattis, mattis ipsum dignissim, consectetur sem. Aliquam blandit ullamcorper maximus. Etiam facilisis ut ex vitae scelerisque. Mauris luctus libero eu diam lobortis, sed posuere ligula imperdiet. Vestibulum sem elit, rutrum vel sollicitudin nec, luctus vitae mi. Proin imperdiet finibus mauris ac eleifend. Aliquam erat volutpat. Sed hendrerit, tortor placerat efficitur pellentesque, risus nisi tincidunt quam, id cursus diam leo non ante. Quisque ac augue tortor. Cras ac felis vel neque ornare mattis a ac tortor.</p>
</div>
</div>
</div>
</div>
$lightGrey: #F2F2F2;
$white: #FFFFFF;
$blue: #1849AB;
$black: #000000;
body {
align-content: center;
background: $lightGrey;
display: flex;
justify-content: center;
line-height: 2;
min-height: 100vh;
}
.tabs {
display: grid;
}
[role="tablist"] {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 10px;
}
.tabWrapper {
display: grid;
font-family: 'Arial';
margin-top: 4rem;
padding: 1rem;
width: 1000px;
}
[role="tabpanel"] {
background: $white;
padding: 2rem;
}
button {
background: $blue;
border: 0;
border-radius: 5px 5px 0 0;
color: $white;
cursor:pointer;
font-size: 1rem;
height: 40px;
}
button[aria-selected="true"] {
background: $white;
color: $black;
}
button:focus {
box-shadow: 0 0 0 4px rgba(21, 156, 228, 0.7);
outline: none;
z-index: 5;
}
const tabs = document.querySelector('.tabs');
const tabButtons = tabs.querySelectorAll('[role="tab"]');
const tabPanels = tabs.querySelectorAll('[role="tabpanel"]');
function handleTabClick(event) {
tabPanels.forEach(function(panel) {
panel.hidden = true;
});
tabButtons.forEach(function(tab) {
tab.setAttribute('aria-selected', false);
});
event.currentTarget.setAttribute('aria-selected', true);
const {id} = event.currentTarget;
const tabPanel = tabs.querySelector(`[aria-labelledby="${id}"]`);
tabPanel.hidden = false;
}
tabButtons.forEach(button => button.addEventListener('click', handleTabClick));
Also see: Tab Triggers