Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h1>Buttons without class</h1>
  <p>Buttons shouldn't need classes to function. Clean up your act (and your code) with some HTML!</p>
  <ul>
    <li>
      <button type="button">Default</button>
      <button type="button" disabled>Default</button>
    </li>
    <li>
      <button type="submit">Primary</button>
      <button type="submit" disabled>Primary</button>
    </li>
    <li>
      <form action="#"><button>Success</button></form>
      <form action="#"><button disabled>Success</button></form>
    </li>
    <li>
      <button type="reset">Danger</button>
      <button type="reset" disabled>Danger</button>
    </li>
    <li>
      <button type="button" aria-owns="modal-something">Info</button>
      <button type="button" aria-owns="modal-something" disabled>Info</button>
    </li>
  </ul>

  <h2>But why?</h2>
  <p>Everytime I ask people why they use <code>div</code>'s or <code>a</code>'s for their buttons, the default response is something like <q>Because it's easier to style</q>. This page shows Bootstrap's buttons styled via some standard HTML and a bunch of CSS selectors. Moreover, they don't use classes.</p>
  <p>The used CSS properties are—as I copied them—almost identical to those of Bootstrap. The only thing I changed is some inherited font stuff on the default <code>button</code> declaration. Most of the work went into a clean-up of the selectors.</p>

  <h2>But how?</h2>
  <p>To pull this nifty trick off I used this great CSS framework called Cool Semantic Styles (previously know as Cascading Style Sheets). This revolutionary technique uses information that is built into HTML itself—believe it or not—to turn it into styles. Who knew you could set a <code>disabled</code> attribute on a <code>button</code> and style it accordingly?</p>
  <p>When I first discoverd this technique I was blown away. It took me several years to recover from the overwhelmed feeling of happyness—I'm not really sure I <em>have</em> recovered to be honest.</p>

  <h3>But, but, how?</h3>
  <p>Don't worry, I know the feeling, I've been there! It will all come together once you start with Cool Semantic Styles. Just try it out; it's built into every browser.</p>

  <h3>This sounds great, what is the catch?</h3>
  <p>Okay, there is this one itsy bitsy tiny little thing: support pre Internet Explorer 7 is pretty bad; Internet Explorer 6 and earlier don't allow you to select states in your Cool Semantic Styles documents.</p>
  
  <h2>So buttons? What about everything else?</h2>
  <p>I know Cool Semantic Styles seems limited at this time, but I teamed up with major  browser vendors like Mozilla, Apple, and Microsoft to add support for more design patterns soon. Even the W3C and its WAI-ARIA initiative are on board!</p>

  <section>
    <h2>Thoughts during development</h2>
    <p>Buttons are not links, so I will not include styles for it.</p>
    <p>I copied Bootstraps base colours, but kept the text dark, because white on these backgrounds (as is the default) does not have enough contrast.</p>
    <p>Bootstrap's disabled styling isn't the best, but I kept it for consistency's sake.</p>
    <p>Could have used a mixin to do the styles, as they are just repetitions, but I feel it is important to see what is happening in an example. And see the madness we create when we style this many buttons.</p>
    <p>We could have used <code>:matches()</code> if it wasn't for those pesky Edge fellers.</p>
    <p>What exactly is a success button? When do you get a success button? And what should it convey? Who came up with this?! <s>This version of Cool Semantic Styles uses a <code>form</code> with an aria attribute <code>aria-invalid</code> that has a value of <code>false</code>. I"m not sure this is the right approach for this, but as soon as someone tells me what a success button is, I'll change it.</s> My inferior knowledge was proven again by the artist (and jQuery Standards Dude) Brian Kardell. We can use the <code>:valid</code> pseudo-class to check the validity of a form and thus mark a button as a success, or something. Still not sure what a success button does. Anyway, this works a treat!</p>
    <p>The current “info”-button uses a standard <code>button</code> with a <code>aria-owns</code> pointed at an element with an <code>id</code> that starts with “modal-”. I'm not saying that all modal triggering buttons are info buttons, but it seemed like a good thing at the time. If you have any suggestions, suggest away!</p>
    <p>I skipped Bootstrap's warning style button. As I'm not sure what it's used for and how it's different from a danger button. I'm sure that if it's distinct from the danger button, there is distinct HTML around it.</p>
  </section>
</main>
              
            
!

CSS

              
                // Bootstrappy vars
$primary: #337ab7;
$success: #5cb85c;
$info: #5bc0de;
$warning: #f0ad4e;
$danger: #d9534f;

button {
  display: inline-block;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-family: inherit;
  font-size: inherit;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  cursor: pointer;
  background-image: none;
}

button:focus,
button:hover,
button:active {
  color: inherit;
}

button:active {
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
}

// Default
// This was first 38 lines of Sass with nesting and what not.
// Now it's 38 lines of pure css (selectors anyway), 
// look at the mess you need for these styles.

// Ended up using :not([disabled]) to prevent slew 
// of disabled resets and thus saved 14(!) lines.
button[type="button"] {
  border-color: #ccc;
  background: #fff;
}

button[type="button"]:not([disabled]):focus,
button[type="button"]:not([disabled]):hover,
button[type="button"]:not([disabled]):active {
  background-color: darken(#fff, 10%);
}

button[type="button"]:not([disabled]):hover,
button[type="button"]:not([disabled]):active {
  border-color: darken(#ccc, 12%);
}
  
button[type="button"]:not([disabled]):focus {
  border-color: darken(#ccc, 25%);
}

button[type="button"]:not([disabled]):active:hover,
button[type="button"]:not([disabled]):active:focus{
  background-color: darken(#fff, 17%);
  border-color: darken(#ccc, 25%);
}

// Primary
button[type="submit"] {
  border-color: darken($primary, 5%);
  background: $primary;
}

button[type="submit"]:not([disabled]):focus,
button[type="submit"]:not([disabled]):hover,
button[type="submit"]:not([disabled]):active {
  background-color: darken($primary, 10%);
}

button[type="submit"]:not([disabled]):hover,
button[type="submit"]:not([disabled]):active {
  border-color: darken($primary, 15%);
}
  
button[type="submit"]:not([disabled]):focus {
  border-color: darken($primary, 30%);
}

button[type="submit"]:not([disabled]):active:hover,
button[type="submit"]:not([disabled]):active:focus{
  background-color: darken($primary, 17%);
  border-color: darken($primary, 30%);
}

// Something for success?
form:valid button {
  border-color: darken($success, 5%);
  background: $success;
}

form:valid button:not([disabled]):focus,
form:valid button:not([disabled]):hover,
form:valid button:not([disabled]):active {
  background-color: darken($success, 10%);
}

form:valid button:not([disabled]):hover,
form:valid button:not([disabled]):active {
  border-color: darken($success, 15%);
}
  
form:valid button:not([disabled]):focus {
  border-color: darken($success, 30%);
}

form:valid button:not([disabled]):active:hover,
form:valid button:not([disabled]):active:focus{
  background-color: darken($success, 17%);
  border-color: darken($success, 30%);
}

// Warning?
// Danger?
button[type="reset"] {
  border-color: darken($danger, 5%);
  background: $danger;
}

button[type="reset"]:not([disabled]):focus,
button[type="reset"]:not([disabled]):hover,
button[type="reset"]:not([disabled]):active {
  background-color: darken($danger, 10%);
}

button[type="reset"]:not([disabled]):hover,
button[type="reset"]:not([disabled]):active {
  border-color: darken($danger, 15%);
}
  
button[type="reset"]:not([disabled]):focus {
  border-color: darken($danger, 30%);
}

button[type="reset"]:not([disabled]):active:hover,
button[type="reset"]:not([disabled]):active:focus{
  background-color: darken($danger, 17%);
  border-color: darken($danger, 30%);
}


// Info (linked to modal)?
// Sounds plausable
button[aria-owns^=modal-] {
  border-color: darken($info, 5%);
  background: $info;
}

button[aria-owns^=modal-]:not([disabled]):focus,
button[aria-owns^=modal-]:not([disabled]):hover,
button[aria-owns^=modal-]:not([disabled]):active {
  background-color: darken($info, 10%);
}

button[aria-owns^=modal-]:not([disabled]):hover,
button[aria-owns^=modal-]:not([disabled]):active {
  border-color: darken($info, 15%);
}
  
button[aria-owns^=modal-]:not([disabled]):focus {
  border-color: darken($info, 30%);
}

button[aria-owns^=modal-]:not([disabled]):active:hover,
button[aria-owns^=modal-]:not([disabled]):active:focus{
  background-color: darken($info, 17%);
  border-color: darken($info, 30%);
}

button[disabled] {
  color: inherit;
  cursor: not-allowed;
  opacity: 0.65;
}

button[disabled]:active {
  box-shadow: none;
}

// Basic bits
body {
  max-width: 40em;
  font-family: "Lucida Grande", sans-serif;
}

code {
  display: inline-block;
  margin: 0;
  padding: 3px 6px;
  border: 1px solid #999;
  border-radius: 3px;
  color: hsl(229, 100%, 25%);
  font-size: inherit;
  line-height: 1;
  vertical-align: baseline;
  background: hsl(0, 0%, 90%);
}

h2,
h3,
p {
  margin-bottom: 0;
}

p {
  line-height: 1.5em;
}

form {
  display: inline;
}

* + * {
  margin-top: 1em;
}

// Safari doesn't do this by default?
s code {
  text-decoration: line-through;
}
              
            
!

JS

              
                var buttons = document.getElementsByTagName('button');

for (var i=0; i < buttons.length; i++) {
  buttons[i].addEventListener(preventDefault);
}

function preventDefault(event) {
  event.preventDefault();
}
              
            
!
999px

Console