Pen Settings

HTML

CSS

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

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

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.

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

              
                <link href='https://fonts.googleapis.com/css?family=Lato:400,300' rel='stylesheet' type='text/css'>
  <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>

<script src="http://lokeshdhakar.com/projects/color-thief/js/color-thief.js"></script>
<body>
  
  <div class="header">
    <h1>Color palette from image </h1>
  <h2> using <a href="http://lokeshdhakar.com/projects/color-thief">color thief</a></h2>
  <p>Every time you refresh you get a new image</p>
  </div>
  
  <div class="main">
    <div class="img-container">
      <img src="https://2.bp.blogspot.com/-yG1phtfRbXE/WChuWyBS1bI/AAAAAAAAIhs/UCg6W-7QhNUOPAYrbU9-ENHoRAOsKelvQCLcB/s1600/Sunflowers-vincent-2012-233.jpg" alt="Example image" class="image" crossorigin="anonymous" />
    </div>
    
    <div class="content">
    <h1>Bluth Ipsum</h1>
    <p>You need to do more with Rita. Believe me, I'd like to. They want to break his legs. It's a good thing he's already got that little scooter. They don't appreciate him. It's his glasses… they make him look like a lizard. Plus he's self-conscious. A Colombian cartel that WON'T kidnap and kill you.</p>
  </div>
  </div>
   
  
  
  

</body>


              
            
!

CSS

              
                html {
  font-family: 'Lato', system, sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.main {
  display: flex;
  box-sizing: border-box;
  box-shadow: 0 0px 100px rgba(0,0,0,0.2);
  margin: 30px auto 30px auto;
  width: 960px;
}

.header {
  color: #4d4d4d;
  box-sizing: border-box;
  text-align: center;
}

.image {
  width: 405px;
  height: 270px;
  object-fit: cover;
  display: block;
}

.content {
  box-sizing: border-box;
  color: white;
  font-weight: 400;
  flex-basis: 150%;
  line-height: 1.5;
  padding: 0 30px;
  text-align: left;
}

.content {
  h1 {
    color: white;
    font-weight: 300;
    text-align: left;
  }
}

              
            
!

JS

              
                var colorThief = new ColorThief();

var image = $("img.image")[0];

$(image).load(function() {
  var color = colorThief.getPalette(image, 8);

  var color1 = 'rgb(' + color[0] + ')';
  var color2 = 'rgb(' + color[1] + ')';

  $('.main').css('background', 'linear-gradient(to right,' + color1 + ',' + color2 + ')');
  
  $('a').css('color', color1);
});
              
            
!
999px

Console