cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

            
              <article>
    <h1>Button Pal</h1>
    <p>You get so much <i>for free</i> when you use a real button, so here's a block of CSS to remove the headache of styling them for you. Read more about why you should use a button <a href="https://css-tricks.com/small-tweaks-can-make-huge-impact-websites-accessibility/#article-header-id-2" target="_blank" rel="noopener">here</a>.</p>
    <h2>The button</h2>
    <p>Check out this totally workable button. It's pretty much as easy to work with as a <code>&lt;div&gt;</code>. You can share these styles with an <code>&lt;a&gt;</code> too 🚀</p>
    <button>Click to copy code to your clipboard</button>
    <div role="status"></div>
    <h2>The code</h2>
    <pre><code>button {
    display: inline-block;
    border: none;
    padding: 1rem 2rem;
    margin: 0;
    text-decoration: none;
    background: #0069ed;
    color: #ffffff;
    font-family: sans-serif;
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    transition: background 250ms ease-in-out, 
                transform 150ms ease;
    -webkit-appearance: none;
    -moz-appearance: none;
}

button:hover,
button:focus {
    background: #0053ba;
}

button:focus {
    outline: 1px solid #fff;
    outline-offset: -4px;
}

button:active {
    transform: scale(0.99);
}</code></pre>
    <footer>
        <p>If you find this useful, you should probably check out <a href="https://boilerform.design" target="_blank" rel="noopener">Boilerform</a> to make your forms easier too.</p>
    </footer>
</article>
            
          
!
            
              
/* Buttons styles start */
button {
    display: inline-block;
    border: none;
    padding: 1rem 2rem;
    margin: 0;
    text-decoration: none;
    background: #0069ed;
    color: #ffffff;
    font-family: sans-serif;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    text-align: center;
    transition: background 250ms ease-in-out, transform 150ms ease;
    -webkit-appearance: none;
    -moz-appearance: none;
}

button:hover,
button:focus {
    background: #0053ba;
}

button:focus {
    outline: 1px solid #fff;
    outline-offset: -4px;
}

button:active {
    transform: scale(0.99);
}
/* Button styles end */






/* Ignore these presentational styles */
html {
    height: 100%;
}

body {
    height: 100%;
    display: grid;
    place-items: center;
    background: #f3f3f3;
    font-family: -apple-system, BlinkMacSystemFont, 
                    "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", 
                    "Fira Sans", "Droid Sans", "Helvetica Neue", 
                    sans-serif;
    line-height: 1.5;
    color: #333;
}

article {
    max-width: 60ch;
    padding: 2rem 1rem;
}

> * + *:not(pre) {
    margin: 1rem 0 0 0;
}

h1, h2 {
    font-weight: 300;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

h2 {
    padding-top: 0.5rem;
}

a {
    color: #017171;
    text-decoration-skip-ink: auto;
}

pre {
    font-size: 1.2rem;
    margin: 0;
    padding: 0;
}

code {
    padding: 2px 4px;
    background: #222f3e;
    color: #f3f3f3;
}

pre code {
    display: block;
    position: relative;
    overflow-x: auto;
    tab-size: 4;
    padding: 2rem;
    -webkit-overflow-scrolling: touch;
}

[role="status"] {
    font-size: 0.8rem;
    font-style: italic;
    padding: 0.5rem 0 0 0;
}

[role="status"]:empty {
    display: none;
}

[aria-hidden="true"] {
    font-style: normal;
}
            
          
!
            
              console.clear();

const buttonElement = document.querySelector('button');
const codeElement = document.querySelector('pre code');
const statusElement = document.querySelector('[role="status"]');

// Either use the native clipboard API or use a little fallback
const clipboard = navigator.clipboard || {
    writeText(value) {
        
        // Create a textarea element and hide it
        const textAreaElem = document.createElement('textarea');
        textAreaElem.style.cssText = `
            opacity: 0;
            position: fixed;
            top: 50%;
        `;

        // Set its value to what we want to copy
        textAreaElem.value = value;
        
        // Stick it in the DOM
        document.body.appendChild(textAreaElem);
        
        // Use its native select method
        textAreaElem.select();
        
        // Copy that stuff to the clipboard!
        console.log(document.execCommand('copy'));

        // Remove it again
        document.body.removeChild(textAreaElem);

        return Promise.resolve();    
    }
};

buttonElement.addEventListener('click', evt => {
    
    evt.preventDefault();
    
    clipboard.writeText(codeElement.innerText)
        .then(() => {
            statusElement.innerHTML = '<span aria-hidden="true">🎉</span> Code copied to clipboard!';
        })
        .catch(() => {
            statusElement.innerHTML = '<span aria-hidden="true">🛑</span> There was an error copying the code. Try again!';
        });
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console