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

              
                h1 Photoshop images with CSS blend-modes

.content__intro
  h2 Intro
  .description
    p Before I learned how to write "the codez" I was a photographer. In photoshop, there are 3 simple techniques to lighten, darken and colorize  images quickly. Now we can do these same techniques with CSS. 
  
.content__lighten
  h2  Lighten a dark image
  .description 
    h3 (under exposure)
    p Sometimes you get a dark image and you wish you could lighten it. Well you can—using the same quick method you'd use in photoshop. Just duplicate the layer and set it's blend mode to screen.
  
  .media-1
  
  .description 
    p Below I took the exact same image and gave it multiple backgrounds of itself. I know, this sounds weird, but you can totally create multiple background images in CSS.
    
    pre
      code background-image: url(photo-1.jpg), url(photo-2.jpg)
    
    p We can then lighten that image by adding: 
    
    pre
      code background-blend-mode: screen
      
    p In this case, I did three layers of the same image to make the effect stronger. You can add as many layers as you'd like.
  
  .media-2
  
  .description
    p 
      a(href='https://500px.com/photo/109516309/giml%C3%A9-by-stian-klo?from=popular') Source image
 
 .content__darken
  h2  Darken a light image
  .description 
    h3 (over exposure)
    p Sometimes you get a light image and you wish that you could darken it. We can do that using the inverse of the method above.
  
  .media-1
  
  .description 
    p Again, we use the multiple background trick to make 2 layers of the same image. Then we set:
    
    pre
      code background-blend-mode: multiply
      
    p Boom! Done. Darkening accomplished.
  
  .media-2
  
  .description
    p 
      a(href='https://500px.com/photo/4597826/rachel-by-molly-thompson') Source image
    
 
.content__colorize
  h2  Colorizing 1
  .description 
    p Sometimes you just want to make an image look cool. Maybe you want to colorize an image to set text over it. Regardless, colorizing is easy. 
  
  .media-1
  
  .description 
    p This time we use one image and a background color:
    
    pre
      code
      | background-image: url(image.jpg)
      | background-color: #0fc
      | background-blend-mode: multiply
  
  .media-2
  
  .description 
    p Below we use a "screen" blend mode:
    pre
      code
      | background-image: url(image.jpg)
      | background-color: tomato
      | background-blend-mode: screen
  
  .media-3
  
  .description 
    p Bleow we use an image with a "linear-gradient" background as a second image
    
    pre
      code
      | background-image:  url(image/jpg), linear-gradient(135deg, red, blue)
      | background-blend-mode: overlay
  
  .media-4
  
  .description 
    p Bleow is another, but using "hard-light" instead.
  
  pre
      code
      | background-image: url(image.jpg), linear-gradient(45deg, red, green, blue)
      | background-position: center center
      | background-blend-mode: hard-light
  
  
  .media-5
  
  .description
    p
       a(href='https://drscdn.500px.org/photo/63285587/m%3D2048/5b76fef38d86247ba8a99007d61df3a2') Source image     
 
 
 .content__bw
  h2  Colorizing 2
  .description 
    h3 (Black and White)
    p You can also turn a color image to a black-and-white image too, but the technique is a little different.
  
  .media-1
  
  .description 
    p This time we use a pseudo-element to place a background color over the image.
    
    pre
      code 
        | &::after
        |   content: ''
        |   position: absolute
        |   top: 0
        |   left: 0
        |   background-color: #ccc
        |   width: 100%
        |   height: 100%
        |   mix-blend-mode: color
      
    p You can use this technique to create any monotone image.
  
  .media-2
  
  .description
    p 
       a(href='https://500px.com/photo/109802031/focus-result-(b-)-by-marc-buys') Source image
 
.content__outtro
  h2 Outtro
  .description 
    p I could do this forever. There are so many options. I'd argue that the most usable blend-modes are multiply, screen, overlay, soft-light, hard-light and color.
    
    p If you use a background-image and background-color on the same element, the image will alway sit on top. The blend mode is applied top down. Thus, the image ends, up with the blend-mode. 
    
    p To make some blend modes work, you need to place the background-color over the background-image. This requires using an absolutely positioned pseudo-element to sit on top of the image. We will also need to use "mix-blend-mode" instead of "background-blend-mode."
    
    h3 Important note!
    p While most of the exmaples in this pen used background images with blend-modes, you can use the technique in Colorize 2 to apply blend-modes to img tags. Just put a pseudo-element over the img and use "mix-blend-mode."
    
    h3 500px
    p 
      | All the photos came from 500px. None of them are mine, but you can peep my photos at my
      | 
      a(href="https://500px.com/benjamingandhi-shepard") 500px
      | account.
    
    h3 Jade and Stylus
    p Don't be intimidated by Jade and Stylus. Just click the new "View Compiled" buttons in the code window to get the compiled source codez! You can then convert them into whatever you want (css to LESS or css to scss)
    
    

  
  
  
              
            
!

CSS

              
                *
  box-sizing border-box
  
:root
  font-size 18px
  
body
  background-color #fc0
  color #333
  font-family source sans pro
  font-weight 200
  line-height 1.25
  margin-top 2rem
  
h1
  font-size 8vw
  font-weight 900
  padding 1rem
  text-align center
  text-shadow 5px 5px 0 rgba(100,100,100, 0.4)
  text-transform uppercase
  
h2
  font-size 5vw
  font-weight 600
  position relative
  text-align center
  text-shadow 5px 5px 0 #eee
  text-transform uppercase
  
  &::after
    border-bottom 5px solid #333
    bottom -1rem
    content: ''
    left 50%
    position absolute
    transform translateX(-50%)
    width 6rem
    
h3
  font-family source sans pro
  font-size 2vw
  font-weight 200
  padding 3rem 0 0 0
  text-align center
  
.description
  
  p
    font-family source serif pro
    line-height 1.5
    margin 2rem 0
    padding 0 6rem
  
[class^=content]
  background-color white
  box-shadow 10px 10px 0 rgba(100,100,100, 0.2)
  margin 4rem auto
  padding 2rem
  width 80vmax
  
   
[class^=media]
  background-position center center 
  background-repeat no-repeat
  background-size cover
  height 50vh
  width 100%
      
  
.content
      
  &__lighten
    
    .media-1
      background-image: url(https://drscdn.500px.org/photo/109516309/m%3D2048/c1b43253d5d2f8e48c211f544672949d)
    
    .media-2
      background-image:  url(https://drscdn.500px.org/photo/109516309/m%3D2048/c1b43253d5d2f8e48c211f544672949d), url(https://drscdn.500px.org/photo/109516309/m%3D2048/c1b43253d5d2f8e48c211f544672949d), url(https://drscdn.500px.org/photo/109516309/m%3D2048/c1b43253d5d2f8e48c211f544672949d)
      background-blend-mode screen
 
  &__darken
    
    .media-1
      background-image: url(https://drscdn.500px.org/photo/4597826/m%3D2048/04c42fa661e7a2d66a99cdada44dc03c)
    
    .media-2
      background-image:  url(https://drscdn.500px.org/photo/4597826/m%3D2048/04c42fa661e7a2d66a99cdada44dc03c), url(https://drscdn.500px.org/photo/4597826/m%3D2048/04c42fa661e7a2d66a99cdada44dc03c)
      background-blend-mode multiply
      
      
  &__colorize
    
    .media-1
      background-image: url(https://drscdn.500px.org/photo/63285587/m%3D2048/5b76fef38d86247ba8a99007d61df3a2)
    
    .media-2
      background-image:  url(https://drscdn.500px.org/photo/63285587/m%3D2048/5b76fef38d86247ba8a99007d61df3a2)
      background-color #0fc
      background-blend-mode: multiply
      
    .media-3
      background-image:  url(https://drscdn.500px.org/photo/63285587/m%3D2048/5b76fef38d86247ba8a99007d61df3a2)
      background-color tomato
      background-blend-mode: overlay
      
    .media-4
      background-image:  url(https://drscdn.500px.org/photo/63285587/m%3D2048/5b76fef38d86247ba8a99007d61df3a2), linear-gradient(135deg, red, blue)
      background-blend-mode: overlay

      display flex
      align-items center
      justify-content center
      
      &::after
        color white
        content: 'Elutheria'
        font-family source sans pro
        font-size 5rem
        font-weight 200
        /*position absolute
        top center
        left center*/
        text-transform uppercase
        
      
      
    .media-5
      background-image url(https://drscdn.500px.org/photo/63285587/m%3D2048/5b76fef38d86247ba8a99007d61df3a2), linear-gradient(45deg, red, green, blue)
      background-position 50% 50%
      background-blend-mode hard-light
      

  &__bw
    
    .media-1
      background-image: url(https://drscdn.500px.org/photo/109802031/m%3D1170/06b0b6ff2b8533c1f952fe8661abba56)
    
    .media-2
      background-image:  url(https://drscdn.500px.org/photo/109802031/m%3D1170/06b0b6ff2b8533c1f952fe8661abba56)
      
      position relative
  
      &::after
        content: ''
        position absolute
        top 0
        left 0
        background-color #ccc
        width 100%
        height 100%

        mix-blend-mode color
      
pre
  background-color #333
  color #eee
  display block
  font-family source code pro
  padding 1rem 
  white-space pre-wrap
  
a
  background-color #fc0
  color #333
  display inline-block
  padding 0 .5rem
  text-decoration none
  
  &:hover
    background-color #333
    color #fc0
   
              
            
!

JS

              
                
              
            
!
999px

Console