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.
<h1 class="title">
Topcoat Button Bar
</h1>
<p>
Default style for Topcoat Button Bar.
<br>
Requirements are portable and accessible markup with flexible and performant css.
<br>
No javascript required
</p>
<h2>Normal Button Bar</h2>
<div class="topcoat-button-bar">
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button">One</button>
</div>
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button">Two</button>
</div>
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button">Three</button>
</div>
</div>
<br>
<h2>Select Button Bar</h2>
<div class="topcoat-button-bar">
<label class="topcoat-button-bar__item">
<input type="radio" name="topcoat">
<button class="topcoat-button-bar__button">One</button>
</label>
<label class="topcoat-button-bar__item">
<input type="radio" name="topcoat">
<button class="topcoat-button-bar__button">Two</button>
</label>
<label class="topcoat-button-bar__item">
<input type="radio" name="topcoat">
<button class="topcoat-button-bar__button">Three</button>
</label>
</div>
<br>
<h2>Toggle Button Bar</h2>
<div class="topcoat-button-bar">
<label class="topcoat-button-bar__item">
<input type="checkbox">
<button class="topcoat-button-bar__button">One</button>
</label>
<label class="topcoat-button-bar__item">
<input type="checkbox">
<button class="topcoat-button-bar__button">Two</button>
</label>
<label class="topcoat-button-bar__item">
<input type="checkbox">
<button class="topcoat-button-bar__button">Three</button>
</label>
</div>
<div class="spacer">
<hr>
</div>
<h2>Accessibility</h2>
<p>
The stateful button bars use inputs and the :checked pseudo style to add functionality without needing Javascript.
</p>
<p>
These stateful button bars rely on implicit ( or nested ) input labels instead of each needing an `id` and a matching `for` attribute on the corresponding label. This makes them more portable since each `id` on a page needs to be unique.
</p>
<p>
If you need to support legacy browsers and accessibility devices you can easily support these by adding the `id` and `for` attributes.
</p>
<div class="topcoat-button-bar">
<label for="one" class="topcoat-button-bar__item">
<input id="one" type="radio" name="topcoat">
<button class="topcoat-button-bar__button">One</button>
</label>
<label for="two" class="topcoat-button-bar__item">
<input id="two" type="radio" name="topcoat">
<button class="topcoat-button-bar__button">Two</button>
</label>
<label for="three" class="topcoat-button-bar__item">
<input id="three" type="radio" name="topcoat">
<button class="topcoat-button-bar__button">Three</button>
</label>
</div>
<p>
*look at HTML source
</p>
<div class="spacer">
<hr>
</div>
<h2>Semantic variations</h2>
<p>
This is where the CSS classes start to show their true benefit. You can use different semantic mark up to reflect your specific use case while maintiaing the same CSS classes.
</p>
<p>
If you are using this button bar as your primary navigation you could change the markup to reflect this semantically by using a nav element. Component looks the same with different mark up.
</p>
<nav class="topcoat-button-bar">
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button">One</button>
</div>
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button">Two</button>
</div>
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button">Three</button>
</div>
</nav>
<p>
*look at HTML source
</p>
<p>
If you are using this button bar as a list of links you could change the markup to semantically reflect this by using an unorderd list with anchor tags. Again, component looks the same with different mark up.
</p>
<ul class="topcoat-button-bar">
<li class="topcoat-button-bar__item">
<a href="http://topcoat.io"
target="_blank"
class="topcoat-button-bar__button">
Topcoat
</a>
</li>
<li class="topcoat-button-bar__item">
<a href="http://brackets.io"
target="_blank"
class="topcoat-button-bar__button">
Brackets
</a>
</li>
<li class="topcoat-button-bar__item">
<a href="http://html.adobe.com"
target="_blank"
class="topcoat-button-bar__button">
Adobe Web
</a>
</li>
</ul>
<p>
*look at HTML source
</p>
<div class="spacer">
<hr>
</div>
<h2>Adding sizing</h2>
<p>
Topcoat separates layout and positioning from styling to make the components more reusable.
<br>
The below example has the layout class `full` added to elements to show how sizing can be applied.
</p>
<div class="topcoat-button-bar full">
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button full">One</button>
</div>
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button full">Two</button>
</div>
<div class="topcoat-button-bar__item">
<button class="topcoat-button-bar__button full">Three</button>
</div>
</div>
<div class="spacer">
<hr>
</div>
<small>
<a href="https://www.twitter.com/dam">@dam</a> ♥s you
</small>
<script src="//use.edgefonts.net/source-sans-pro:n3,n4,n6;source-code-pro:n3.js"></script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
body {
padding: 0 50px;
background-color: #f4f4f4;
font-family: source-sans-pro, sans-serif;
}
:focus {
outline-color: transparent;
outline-style: none;
}
.full {
width: 100%;
}
.title {
letter-spacing: -.065em;
}
.spacer {
padding: 25px 0;
}
.topcoat-button-bar__item > input {
border: 0;
clip: rect(0 0 0 0);
height: 2rem;
margin: 0 -2rem -2rem 0;
overflow: hidden;
padding: 0;
position: absolute;
width: auto;
opacity: 0.001;
}
.button-bar,
.topcoat-button-bar {
display: table;
table-layout: fixed;
white-space: no-wrap;
margin: 0;
padding: 0;
}
.topcoat-button-bar__item {
display: table-cell;
width: auto;
border-radius: 0;
}
.topcoat-button-bar > .topcoat-button-bar__item:first-child {
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
}
.topcoat-button-bar > .topcoat-button-bar__item:last-child {
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
}
.topcoat-button-bar__item:first-child > .topcoat-button-bar__button {
border-right: none;
}
.topcoat-button-bar__item:last-child > .topcoat-button-bar__button {
border-left: none;
}
.button,
.topcoat-button-bar__button {
position: relative;
display: inline-block;
overflow: hidden;
box-sizing: border-box;
margin: 0;
padding: 0;
border: none;
background: transparent;
background-clip: padding-box;
color: inherit;
vertical-align: top;
text-decoration: none;
text-overflow: ellipsis;
white-space: nowrap;
font: inherit;
cursor: default;
user-select: none;
}
.topcoat-button-bar__button {
padding: 0 1.25rem;
border: 1px solid #a5a8a8;
/* Important inheritance to manipulate border radius from parent */
border-radius: inherit;
background-color: #e5e9e8;
-webkit-box-shadow: inset 0 1px #fff;
box-shadow: inset 0 1px #fff;
color: #454545;
text-shadow: 0 1px #fff;
line-height: 3rem;
}
:checked + .topcoat-button-bar__button,
.topcoat-button-bar__button:active,
.topcoat-button-bar__button.is-active {
background-color: #d3d7d7;
-webkit-box-shadow: inset 0 1px rgba(0,0,0,0.12);
box-shadow: inset 0 1px rgba(0,0,0,0.12);
}
.topcoat-button-bar__item:disabled,
.topcoat-button-bar__item.is-disabled {
opacity: 0.3;
cursor: default;
pointer-events: none;
}
.topcoat-button-bar__button:focus {
border: 1px solid #0940fd;
-webkit-box-shadow: 0 0 0 2px #6fb5f1;
box-shadow: 0 0 0 2px #6fb5f1;
z-index: 1;
}
Also see: Tab Triggers