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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<header>
<p>
<a target="_blank" href="https://tabpanelwidget.com">
<img decoding="async" src="https://tabpanelwidget.com/icon.eff9d2cc.png" alt="TabPanelWidget" width="72" height="72"></a>
</p>
</header>
<!--
Check the list of available classes in the Usage section
And then add classes to the Widget to change its styling
i.e: <div class="tpw-widget tpw-bar tpw-centered">
-->
<p>
<button id="mount-toggle">mount/unmount</button>
</p>
<div id="widget" class="tpw-widget tpw-fancy tpw-rounded">
<h3 class="tpw-selected">Markup</h3>
<p>Here is the bare minimum:</p>
<pre><code>
<div class="tpw-widget">
<h3>FUBAR</h3>
<p>Lorem...</p>
<h3>SNAFU</h3>
<p>Ipsum...</p>
<h3>FUMTU</h3>
<p>Dolor...</p>
<h3>FUAFUP</h3>
<p>Sit Amet...</p>
</div>
</code></pre>
<p>Note:</p>
<ul>
<li>The wrapper can be ANYTHING (an <code>article</code>, a <code>div</code>, a <code>dl</code>, whatever)</li>
<li>You can use ANY, and as many, same-level headings within the Widget</li>
<li>You can have ANYTHING between the headings</li>
<li>If you use a Definition List it must ONLY contains <code>dt</code>/<code>dd</code> pairs</li>
</ul>
<h3>Stylesheet</h3>
<p>Insert the following inside the <code><head></code> of your document:</p>
<pre><code>
<link href="//cdn.jsdelivr.net/npm/tabpanelwidget@1.0.2/dist/tabpanelwidget.min.css" rel="stylesheet" /></code></pre>
<h3>Script</h3>
<p>Insert the following before <code></body></code>:</p>
<pre><code>
<script src="//cdn.jsdelivr.net/npm/tabpanelwidget@1.0.2/dist/tabpanelwidget.min.js"></script>
<script>
// remove this if you do not want to serve the polyfill
if (!window.ResizeObserver) {
const script = document.createElement("script")
script.src = "//cdn.jsdelivr.net/npm/tabpanelwidget@1.0.2/dist/tabpanelwidget-polyfill.min.js"
document.head.appendChild(src)
}
// instantiate the script
Tabpanelwidget.autoinstall();
</script></code></pre>
<h3>Usage</h3>
<p>You can apply the following classes to the Widget to change its styling:</p>
<ul>
<li>
<p><strong><code>tpw-widget</code></strong> (REQUIRED):</p>
<ul>
<li>this will style the widget as a TabPanel as long as there is enough room for the tabs to be displayed side-by-side</li>
<li>this will style the widget as an Accordion if there is <em>not</em> enough room for the tabs to be displayed side-by-side</li>
</ul>
</li>
<li>
<p>Optional classes:</p>
<ul>
<li>
<p>For TabPanel:</p>
<ul>
<li>
<code>tpw-tabpanel</code>: this will <em>force</em> the Widget to display as a TabPanel <em>no matter what</em>
</li>
<li>
<code>tpw-fancy</code>: this will style all the tabs (unlike the default styling that only styles the active heading as a tab)</li>
<li>
<code>tpw-pills</code>: this will display the tabs as pills ("à la Bootstrap")</li>
<li>
<code>tpw-bar</code>: this will not style the "tabs" as tabs. Instead, it will display a border below the text/headings</li>
<li>
<code>tpw-centered</code>: this will center the tabs above the panel</li>
<li>
<code>tpw-rounded</code>: this will add a border-radius to the tabs and panel</li>
</ul>
</li>
<li>
<p>For Accordion:</p>
<ul>
<li>
<code>tpw-accordion</code>: this will force the widget to display as an Accordion (regardless of its width)</li>
<li>
<code>tpw-disconnected</code>: this will create space between the headers and style them with rounded corners</li>
<li>tpw-icons-at-the-end: this will display the icons (chevrons, +/-, etc.) on the opposite side of the headers's text</li>
<li>
<code>tpw-chevrons-east-south</code>: this will overwrite the default orientation of the chevrons (South/North) to make them point East/South (West/South in RTL scripts)</li>
<li>
<code>tpw-plus-minus</code>: this will replace the "chevron" icons with "+" and "-" signs</li>
<li>
<code>tpw-animate</code>: this will "animate" the "chevron" icons between their state</li>
</ul>
</li>
<li>
<p>For the headings</p>
<ul>
<li>
<code>tpw-selected</code>: this class, once applied to a heading (or a <code>dt</code>), will open the panel associated with that heading
<ul>
<li>in case <code>tpw-selected</code> is not present on any heading then no panel is open in Accordions and the 1st panel is open in TabPanels</li>
<li>TabPanels can only have one instance of <code>tpw-selected</code>, but Accordions do not have that restriction (more than one panel can be open at once)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>
<strong>Note</strong>: some of the above classes can be mixed, for example:</p>
<pre><code><div class="tpw-widget tpw-pills tpw-rounded tpw-centered"></code></pre>
</div>
<!-- /.tpw-widget -->
/**
PREVENTING FOUC
html:not(.no-js):not(.tpw-\!fouc) .tpw-widget {
visibility: hidden;
}
> this only works if calling autoinstall
-- tj
*/
/* WIDTH of the widget */
.tpw-widget {
width: 80%;
}
/**
See FAQ:
https://github.com/tabpanelwidget/tabpanelwidget/wiki/FAQ#how-can-i-remove-the-focus-ring-from-the-panels
*/
:focus:not(:focus-visible),
:focus:not(:focus-visible) .tpw-panel {
box-shadow: none !important;
outline: none !important;
}
/*
*************************
NOT RELATED TO THE WIDGET
*************************
*/
html {
overflow-y: scroll;
line-height: 1.6;
background: #f2f2f2;
}
body {
padding: 1rem;
font-size: 18px;
}
header p {
text-align: center;
font-size: 1.3rem;
padding: 1rem;
margin: 0 0 2rem;
}
header img {
width: 6rem;
height: 6rem;
display: block;
margin: auto;
}
header + p {
text-align: center;
}
ul {
margin-left: 0;
padding-left: 1rem;
}
/* PRE */
pre {
padding: 0 0 0;
overflow-x: auto;
margin-bottom: 3rem;
}
code {
background: #bcdffb;
color: #000;
border-radius: 3px;
padding: 2px 5px;
}
pre code {
display: block;
background: #fff;
color: #000;
border-radius: 3px;
}
button {
position: relative;
display: inline-block;
letter-spacing: 1px;
margin: 1.5rem 0;
border-radius: 3px;
font-weight: 700;
background: rgb(116, 242, 130);
padding: 0.7rem 1.5rem;
text-decoration: none;
border: none;
box-shadow: rgb(153, 153, 153) 0px 0px 0px 2px,
rgb(116, 242, 130) 0px 0px 0px 5px;
transition: all 200ms ease-in 0s;
color: rgb(0, 0, 0) !important;
}
button:hover {
box-shadow: rgb(116, 242, 130) 0px 0px 0px 10px;
}
// remove the class "no-js" from <html>
document.documentElement.classList.remove("no-js");
// remove this if you do not want to serve the polyfill
if (!window.ResizeObserver) {
const script = document.createElement("script");
script.src =
"//cdn.jsdelivr.net/npm/tabpanelwidget@1.0.0/dist/tabpanelwidget-polyfill.min.js";
document.head.appendChild(src);
}
const widget = document.querySelector("#widget");
let uninstall;
function toggle() {
if (uninstall) {
uninstall();
uninstall = null;
} else {
Tabpanelwidget.install(widget).then((_) => (uninstall = _));
}
}
document.querySelector("#mount-toggle").addEventListener("click", toggle);
toggle();
Also see: Tab Triggers