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

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

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              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}') ◑

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

body {
  background: #212121;
}

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

.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 {
  overflow: hidden;
  position: fixed;
  top: 50%; left: 50%;
  width: 70vh;
  max-width: 90%;
  height: 90vh;
  box-shadow: inset 0 0 0 var(--bezel) var(--color-contrast), 0 0 4rem var(--color-bg);
  transition: 200ms background-color linear, 200ms box-shadow cubic-bezier(.7,.3,.25,1.15) 200ms;
  will-chrange: background-color, box-shadow;
  transform: translate(-50%,-50%);
  background-color: var(--color-bg);
}
.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: var(--bezel);
  background: var(--color-contrast);
  color: var(--color-bg);
  transition: 200ms background-color cubic-bezier(.7,.3,.25,1.15) 200ms;
  will-chrange: background-color, box-shadow; 
}

.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-bg);
  }
  .triange {
    fill: var(--color-contrast);
  }
}

.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}}

            
          
!
            
              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
🕑 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.

Console