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

              
                //- To see the process of how I made this dark mode toggle, watch this tutorial video:
//- https://youtu.be/42gltu11wb8

//- It explains choosing dark mode colors, how to set up the CSS in SASS, creating the transition effect in CSS and making the dark mode persistent across pages and refreshes.


header.masthead
  .masthead-inner
    h1.logo Logo
    nav.nav
      ul
        li
          button.dark-button Dark <i class="zmdi zmdi-brightness-2 zmdi-hc-fw"></i> 
        li
          button.light-button(hidden) Light <i class="zmdi zmdi-sun zmdi-hc-fw"></i>
main
  h2 Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus, non.
  
  img(src="https://source.unsplash.com/1600x900?Chicago")
  
  p Marley was dead: to begin with. There is no doubt whatever about that. The register of his burial was signed by the clergyman, the clerk, the undertaker, and the chief mourner. Scrooge signed it: and Scrooge’s name was good upon ’Change, for anything he chose to put his hand to. Old Marley was as dead as a door-nail.

  p Mind! I don’t mean to say that I know, of my own knowledge, what there is particularly dead about a door-nail. I might have been inclined, myself, to regard a coffin-nail as the deadest piece of ironmongery in the trade. But the wisdom of our ancestors is in the simile; and my unhallowed hands shall not disturb it, or the Country’s done for. You will therefore permit me to repeat, emphatically, that Marley was as dead as a door-nail.

  p Scrooge knew he was dead? Of course he did. How could it be otherwise? Scrooge and he were partners for I don’t know how many years. Scrooge was his sole executor, his sole administrator, his sole assign, his sole residuary legatee, his sole friend, and sole mourner. And even Scrooge was not so dreadfully cut up by the sad event, but that he was an excellent man of business on the very day of the funeral, and solemnised it with an undoubted bargain.

  p The mention of Marley’s funeral brings me back to the point I started from. There is no doubt that Marley was dead. This must be distinctly understood, or nothing wonderful can come of the story I am going to relate. If we were not perfectly convinced that Hamlet’s Father died before the play began, there would be nothing more remarkable in his taking a stroll at night, in an easterly wind, upon his own ramparts, than there would be in any other middle-aged gentleman rashly turning out after dark in a breezy spot—say Saint Paul’s Churchyard for instance—literally to astonish his son’s weak mind.

  p Scrooge never painted out Old Marley’s name. There it stood, years afterwards, above the warehouse door: Scrooge and Marley. The firm was known as Scrooge and Marley. Sometimes people new to the business called Scrooge Scrooge, and sometimes Marley, but he answered to both names. It was all the same to him.
  
  img.small(src="https://source.unsplash.com/1600x900?wrigley")

  p Oh! But he was a tight-fisted hand at the grindstone, Scrooge! a squeezing, wrenching, grasping, scraping, clutching, covetous, old sinner! Hard and sharp as flint, from which no steel had ever struck out generous fire; secret, and self-contained, and solitary as an oyster. The cold within him froze his old features, nipped his pointed nose, shrivelled his cheek, stiffened his gait; made his eyes red, his thin lips blue; and spoke out shrewdly in his grating voice. A frosty rime was on his head, and on his eyebrows, and his wiry chin. He carried his own low temperature always about with him; he iced his office in the dog-days; and didn’t thaw it one degree at Christmas.

  p External heat and cold had little influence on Scrooge. No warmth could warm, no wintry weather chill him. No wind that blew was bitterer than he, no falling snow was more intent upon its purpose, no pelting rain less open to entreaty. Foul weather didn’t know where to have him. The heaviest rain, and snow, and hail, and sleet, could boast of the advantage over him in only one respect. They often “came down” handsomely, and Scrooge never did.
  
footer.footer
  .footer-inner
      h1.logo Logo
      nav.nav
        ul
          li 
            a(href="https://cdpn.io/brianhaferkamp/debug/KKgGWog") Page 2
          li
            button.dark-button Dark <i class="zmdi zmdi-brightness-2 zmdi-hc-fw"></i> 
          li
            button.light-button(hidden) Light <i class="zmdi zmdi-sun zmdi-hc-fw"></i>
              
            
!

CSS

              
                //- To see the process of how I made this dark mode toggle, watch this tutorial video:
//- https://youtu.be/42gltu11wb8


@import url("https://fonts.googleapis.com/css?family=Raleway:400,400i,700")

body
  font-family: Raleway, sans-serif
  font-size: 18px
  line-height: 1.7
  background:
    color: #eaeaea
  color: #333
  transition: background-color 800ms ease
  
  &.dark
    background:
      color: #222
    color: #eaeaea
    
    .masthead,
    .footer
      background:
        color: #121212
        
    img
      // filter: saturate(50%)
      filter: brightness(70%)
    
h2
  font-size: 3rem
  line-height: 1.2

img
  width: 100%
  
  &.small
    width: 60%
    float: right
    padding: 1rem
  
.masthead,
.footer
  padding: 0 1rem
  background:
    color: #ddd
    
  transition: background-color 800ms ease

.masthead-inner,
.footer-inner
  display: flex
  justify-content: space-between
  align-items: center
  max-width: 900px
  margin: auto
  
.nav
  ul
    list-style: none
    padding: 0
    margin: 0

button
  border: 1px solid #333
  padding: .5rem
  background: #333
  border-radius: 5px
  transition: background 200ms ease
  color: #eaeaea
  
  &:hover
    background: rgba(#333, 0.8)
    

.dark-button
  i
    transform: rotate(35deg)
    margin-left: .3rem
      
      
main
  padding: 1rem
  max-width: 900px
  margin: auto
              
            
!

JS

              
                //- To see the process of how I made this dark mode toggle, watch this tutorial video:
//- https://youtu.be/42gltu11wb8



// Dark Mode Setup

var darkMode;

if (localStorage.getItem('dark-mode')) {  
  // if dark mode is in storage, set variable with that value
  darkMode = localStorage.getItem('dark-mode');  
} else {  
  // if dark mode is not in storage, set variable to 'light'
  darkMode = 'light';  
}

// set new localStorage value
localStorage.setItem('dark-mode', darkMode);



if (localStorage.getItem('dark-mode') == 'dark') {
  // if the above is 'dark' then apply .dark to the body
  $('body').addClass('dark');  
  // hide the 'dark' button
  $('.dark-button').hide();
  // show the 'light' button
  $('.light-button').show();
}


// Toggle dark UI

$('.dark-button').on('click', function() {  
  $('.dark-button').hide();
  $('.light-button').show();
  $('body').addClass('dark');  
  // set stored value to 'dark'
  localStorage.setItem('dark-mode', 'dark');
});

$('.light-button').on('click', function() {  
  $('.light-button').hide();
  $('.dark-button').show();
  $('body').removeClass('dark');
  // set stored value to 'light'
  localStorage.setItem('dark-mode', 'light');   
});



//--------------------------------------------------
// Below is all that is neede for the basic toggle
//--------------------------------------------------

// $('.dark-button').on('click', function() {  
//   $('.dark-button').hide();
//   $('.light-button').show();
//   $('body').addClass('dark');
// });

// $('.light-button').on('click', function() {  
//   $('.light-button').hide();
//   $('.dark-button').show();
//   $('body').removeClass('dark');  
// });
              
            
!
999px

Console