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

              
                mixin ghc
 a.github-corner(href='//github.com/meodai/color-names', target='_blank', aria-label='View source on Github')
  svg(width='80', height='80', viewbox='0 0 250 250', aria-hidden='true')
    path.triange(d='M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z')
    path.octo-arm(d='M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2', style='transform-origin: 130px 106px;')
    path.octo-body(d='M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z')
 
h1.loading Loading Names
  

.js-app.is-hidden
  +ghc
  style :root { --color-bg: {{currentColor.value}}; --color-contrast: {{currentColor.contrastValue}}; }
  
  div.background
    .inner
      .logo.
      input(type='color' @input='update')
      .header
        h1 {{currentColor.name}}
        h2: input(type='text' @input='update' ':value'='currentColor.value' spellcheck=false)
        -// span(':style'='{color: currentColor.nameValue}') ◑

              
            
!

CSS

              
                @import 'https://fonts.googleapis.com/css?family=Space+Mono:400';



:root {
  --color-bg: #fff;
  --color-contrast: #000;
  --bezel: 4vmin;
}

body {
  background: var(--color-contrast);
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(#fff,.15);
  }
}

.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
}

html, body {
  min-height: 100%;
}

html, body, input {
  font-family: 'Space Mono', ipm, Menlo, 'Courier New', monospace;
  font-size: calc(1vmin + .75rem);
  
  &, h1, h2 {
    font-weight: 400;
  }
}

input {
  appearance: none;
  border: none;
  padding: 0;
  margin: 0;
  background: none;
  color: currentColor;
  &[type='text'] {
    &:focus {
      outline: none;
    }
  }
}

.js-app {
  transition: opacity 400ms, visibility 400ms;
  background-color: var(--color-bg);
}

h2 {
  clip-path: inset(0 0 0 0);
  transition: 400ms clip-path cubic-bezier(.7,.25,0,1) 1000ms;
}

.logo {
  transition: 333ms transform cubic-bezier(.7,.3,.25,1.15);
  //transform: rotate(180deg) translateY(20%) translateZ(0);
  transform-origin: 50% 50%;
  pointer-events: none;
}

.background {
  position: fixed;
  top: 50%; left: 50%;
  width: 70vh;
  max-width: 90%;
  height: 90vh;
  transform: translate(-50%,-50%);
  background-color: var(--color-bg);
  &::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    box-shadow: 0 0 4rem var(--color-bg);
    pointer-events: none;
    transform: scale(.9) translateY(2vmin);
  }
}
.logo {
  svg {
    width: 6rem;
    height: auto;
    transition: 640ms transform cubic-bezier(.7,.3,.25,1.15) 200ms, 500ms opacity linear 240ms;
    transform: scale(1) rotate(0deg);
    path {
      fill: currentColor;
    }
  }
}


.header {
  position: absolute;
  bottom: -1px; left: -1px; right: -1px;
  padding: calc(var(--bezel) * .75) var(--bezel) var(--bezel);
  background-color: var(--color-contrast);
  color: var(--color-bg);
}

.inner {
  h1 {
    position: relative;
    margin: 0 0 .6rem 0;
  }
  h2 {
    margin: 0;
    font-size: 1rem;
    span {
      display: none;
    }
  }
  input[type='color'],
  input[type='button'] {
    cursor: pointer;
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 100%; height: auto;
    opacity: 0;
  }
}

.is-hidden {
  visibility: hidden;
  opacity: 0;
  .background {
    box-shadow: inset 0 0 0 0 currentColor;
  }
  .logo svg {
    opacity: 0;
    transform: scale(0.15) rotate(-280deg);
  }
  h2 {
    clip-path: inset(0 0 100% 0);
  }
  .github-corner {
    transform: translate3d(150%,-150%,0);
  }
}

.github-corner {
  z-index: 1;
  color: currentColor;
  position: absolute;
  top: 0; right: 0;
  transform: translate3d(0,0,0);
  transition: 333ms transform cubic-bezier(.7,.3,.25,1.15) 1200ms;
  will-change: transform;
  svg {
    width: 4rem; height: 4rem;
  }
  path {
    transition: 200ms fill linear;
    will-chrange: fill;
  }
  .octo-arm,
  .octo-body {
    fill: var(--color-contrast);
  }
  .triange {
    fill: var(--color-bg);
  }
}

.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}

              
            
!

JS

              
                let timer;

function getColors(data) {
  let map = {};
  data.forEach(function(entry){
    map[entry.name] = entry.hex;
  });
  let nc = nearestColor.from(map);
  let buntName = new Vue({
    el: '.js-app',
    data: {
      rotation: 180,
      currentColor: {
        value: '#ffffff', 
        name: 'white',
        nameValue: '#ffffff',
        contrastValue: '#000000',
      }
    },
    methods: {
      update: function(e, val){
        const v = val || e.target.value;
        
        if( !tinycolor(v).isValid() ){
          return;
        }
        
        let c = nc(v); 
        this.currentColor.name = c['name'];
        this.currentColor.nameValue = c['value'];
       
        this.currentColor.value = v;
        
        clearTimeout(timer);
        timer = setTimeout(() => { window.location.hash = v }, 500);
        
        let complement = tinycolor(v).complement();
        this.currentColor.contrastValue = tinycolor.mostReadable(v, [
          complement.toHexString(),
          complement.saturate(20).toHexString(),
          complement.saturate(30).toHexString(),
          complement.brighten(20).toHexString(),
          complement.brighten(30).toHexString(),
          complement.darken(20).toHexString(),
          complement.darken(30).toHexString(),
          complement.lighten(20).toHexString(),
          complement.lighten(30).toHexString(),
          complement.desaturate(20).toHexString(),
          complement.desaturate(30).toHexString(),
        ],{
          includeFallbackColors:true,
          level:"A",
          size:"small"
        }).toHexString()

      }
    },
    ready: function(){
      
      if ( !Modernizr.inputtypes.color ) {
        const $c = document.querySelector("input[type='color']");
        $c.classList.add("{hash:true}");
        $c.setAttribute("onchange", "up(this.jscolor)");
        $c.setAttribute("type", "button");
        var picker = new jscolor($c);
        window.up = (e) => { 
          let val = tinycolor($c.style['background-color']).toHexString();
          this.update(e, val)
        }
      }
      
      const hash = window.location && window.location.hash;
      
      if (hash) {
        this.update(null, hash);
      } else {
        this.update(null, '#'+Math.floor(Math.random()*16777215).toString(16));
      }
      
      setTimeout(() => {
        this.$el.classList.remove('is-hidden');
      },10);
      
      setTimeout(() => {
        document.querySelector('input[type="text"]').focus();
      },2000);
    },
  }); 
}

const xhr = new XMLHttpRequest();
xhr.open('GET', '//color-names.herokuapp.com/v1/');
xhr.onload = e => {
    if (xhr.status === 200) {
      let resp = JSON.parse(xhr.responseText);
      getColors(resp.colors);
    } else {
        console.log(xhr.status);
    }
};
xhr.send();


              
            
!
999px

Console