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="wrapper">
<div class="tabs">
<div role="tablist" aria-label="FAQ">
<button role="tab" aria-selected="true" id="what">What?</button>
<button role="tab" aria-selected="false" id="when">When?</button>
<button role="tab" aria-selected="false" id="how">How?</button>
</div>
<div role="tabpanel" aria-labelledby="what">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Officia modi similique tenetur, itaque nam tempora, facilis porro vel nemo, illo eum inventore autem numquam cum delectus aperiam repudiandae! Porro delectus provident accusamus. Odit doloremque modi optio praesentium, saepe eius natus veniam inventore ipsam incidunt animi, iure, ex accusantium quis velit.</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias eum blanditiis praesentium nemo magni. Soluta harum magnam perspiciatis numquam porro dignissimos, dicta atque aut eius quasi iure quidem nulla velit sapiente cupiditate ipsa, exercitationem recusandae repudiandae. Velit excepturi aliquam maiores.</p>
</div>
<div role="tabpanel" aria-labelledby="when" hidden>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Non, quam dolorum sit delectus molestias id consectetur perferendis ipsum voluptatum reiciendis, reprehenderit, iste quibusdam quisquam? Ad tempora cum quae, quisquam perferendis modi explicabo eligendi quis repellendus, vero non cumque eos autem!</p>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Deleniti exercitationem dolorum et blanditiis distinctio? A recusandae molestias repellat quo ipsum asperiores illo possimus voluptates suscipit saepe maxime fuga ea non corrupti voluptatum, rem accusantium fugiat nihil, ducimus modi aliquam est.</p>
</div>
<div role="tabpanel" aria-labelledby="how" hidden>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur dignissimos fuga explicabo. Modi hic, minima odit nostrum cum illo, cupiditate, similique sequi delectus excepturi placeat non qui nemo sed facere adipisci. Quibusdam incidunt reprehenderit unde optio eligendi, voluptatem illum necessitatibus!</p>
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Numquam dicta amet iusto ipsum sed enim impedit eius rem necessitatibus ad voluptate harum perspiciatis ut, perferendis ratione provident earum velit corrupti. Voluptate provident iure perspiciatis, aperiam odio consequatur necessitatibus deserunt tempore alias iusto cupiditate sint quam corrupti in, eligendi laboriosam blanditiis.</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus, culpa nam quia possimus magni minus voluptatibus ab.</p>
</div>
</div>
</div>
@import url('https://fonts.googleapis.com/css2?family=Oxygen+Mono&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@300&display=swap');
/* Variables */
:root {
--bg-selected: rgba(0,0,0,0.03);
--bt-text: #3F1D35;
--bt-text-selected: #663399;
--bt-focus: rgba(0,0,0,0.06);
--text: #454746;
--border-color: grey;
font-size: 62.5%;
box-sizing: border-box;
}
/* Global */
html {
/* vendor prefixes for box-sizing */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
/* for gradient backgounds */
min-height: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
}
*, *:before, *:after {
-webkit-box-sizing: inherit;
-moz-box-sizing: inherit;
box-sizing: inherit;
}
body {
font-family: 'Oswald', sans-serif;
font-size: 1.8rem;
line-height: 1.6;
background: linear-gradient(to right, #eefcff, #fff9fa);
}
/* TABS */
.wrapper {
max-width: 1000px;
margin: 4rem auto;
padding: 2rem;
}
.tabs {
display: grid;
position: relative;
}
[role="tablist"] {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
[role="tabpanel"] {
background: var(--bg-selected);
padding: 2rem;
min-height: 50vh;
color: var(--text);
border-right: 2px solid var(--border-color);
border-left: 2px solid var(--border-color);
border-bottom: 2px solid var(--border-color);
}
button {
font-family: 'Oxygen Mono', monospace;
font-weight: 600;
font-size: 2rem;
letter-spacing: 0.9rem;
padding: 1rem;
background: transparent;
color: var(--bt-text);
border: 0;
border-radius: 5px 5px 0 0;
border-bottom: 2px solid var(--border-color);
cursor: pointer;
/* remove the default margin on buttons in Safari */
margin: 0;
}
button[aria-selected="true"] {
background: var(--bg-selected);
color: var(--bt-text-selected);
border-top: 2px solid var(--border-color);
border-left: 2px solid var(--border-color);
border-right: 2px solid var(--border-color);
border-bottom: 0;
outline: 0;
}
button[aria-selected="false"]:hover {
font-size: 2.1rem;
}
/* replace the dotted outline for tab users with a semi-transparent background */
button:focus {
outline: 0;
background: var(--bt-focus);
}
button::-moz-focus-inner {
border:0;
background: var(--bt-focus);
}
/* Media queries */
@media (max-width: 660px) {
.wrapper {
margin: 4rem auto;
padding: 1rem;
}
button {
border: 0;
border-radius: 5px 5px 5px 5px;
}
button[aria-selected="true"] {
border: 2px solid var(--border-color);
}
[role="tablist"] {
grid-template-columns: repeat(1, minmax(200px, 1fr));
}
[role="tabpanel"] {
margin-top: 10px;
border: 2px solid var(--border-color);
}
}
const tabs = document.querySelector('.tabs');
const tabButtons = tabs.querySelectorAll('[role="tab"]');
const tabPanels = Array.from(tabs.querySelectorAll('[role="tabpanel"]'));
function handleTabClick(event) {
// hide all tab panels
tabPanels.forEach(panel => {
panel.hidden = true;
});
// mark all tab buttons as unselected
tabButtons.forEach(tab => {
tab.setAttribute('aria-selected', false);
});
// mark the clicked tab as selected
event.currentTarget.setAttribute('aria-selected', true);
// find the associated tab panel and show it - associated by "aria-labelledby"
const { id } = event.currentTarget;
const tabPanel = tabPanels.find(
panel => panel.getAttribute('aria-labelledby') === id
);
tabPanel.hidden = false;
}
tabButtons.forEach(button => button.addEventListener('click', handleTabClick));
Also see: Tab Triggers