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

              
                <div class="clock">
  <div class="hand seconds"></div>
  <div class="hand minutes"></div>
  <div class="hand hour"></div>
</div>
              
            
!

CSS

              
                html {
  width: 100%;
  height: 100%;
  position: relative;
  font-size: 16px;
  
  @media only screen and (min-width: 48rem){
    font-size: 22px;
  }
  
  @media only screen and (min-width: 80rem){
    font-size: 28px;
  }
}

html,
.hand{
  background-color: #FEFEFE;
  transition: all 1s ease-in;
}

html {
  &.night {
    background-color: #1A1A1A;
    
    .hand {
      background-color: #1A1A1A;
      border-color: #FEFEFE;
    }
  }
}

.clock {
  width: 15.625rem;
  height: 15.625rem;
  margin: -7.8125rem 0 0 -7.8125rem;
  position: absolute;
  top: 50%;
  left: 50%;
  
  > .hand {
    position: absolute;
    top: 50%;
    left: 50%;
    border: 0.375rem solid #1A1A1A;

    &:after {
      display: block;
      content: '';
      width: 1.25rem;
      height: 1.25rem;
      margin-top: -0.9375rem;
      margin-left: -0.625rem;
      position: absolute;
      background-color: inherit;
      top: 0;
      left: 50%;
    }
  }
}

.seconds{
  width: 12.5rem;
  height: 12.5rem;
  margin: -6.25rem 0 0 -6.25rem;
  border-radius: 12.5rem;
}

.minutes{
  width: 9.375rem;
  height: 9.375rem;
  margin: -4.6875rem 0 0 -4.6875rem;
  border-radius: 9.375rem;
}

.hour{
  width: 6rem;
  height: 6rem;
  margin: -3rem 0 0 -3rem;
  border-radius: 6rem;
}
              
            
!

JS

              
                /**
 * "Broken Line" Minimalist Clock
 * Based on Lukas Avenas "Broken Line"
 * https://www.behance.net/gallery/28569407/broken-line
 * @author Mike King (@micjamking) 
 */
(function(){
  'use strict';
  
  /** 
   * Creates a new clock
   * @constructor
   */
  function Clock(){
    
    /** 
     * Length of an hour in degrees
     * @constant {number} HOUR_DEG 360 degrees / 12 hours
     */
    this.HOUR_DEG = 30;
    
    /** 
     * Length of a minute & second in degrees
     * @constant {number} MIN_SEC_DEG 360 degrees / 60 (minutes || seconds)
     */
    this.MIN_SEC_DEG = 6;
    
    /** 
     * The current date
     * @type {date}
     */
    this.date;
    
    /** 
     * The iteration counter
     * Keep looping instead of rewinding
     * when transitioning from 360deg to 0deg
     * @type {Object}
     */
    this.iteration = {
      sec: 0,
      min: 0,
      hour: 0
    };
    
    /** 
     * Reference to the hour hand
     */
    this.hour = document.querySelector('.hour');
    
    /** 
     * Reference to the minute hand
     */
    this.min = document.querySelector('.minutes');
    
    
    /** 
     * Reference to the second hand
     */
    this.sec = document.querySelector('.seconds');
  }
  
  /**
   * Get hour and set degree of rotation
   */
  Clock.prototype.getHour = function(){
    // Use 12-hour clock (if PM, minus 12)
    var hour = this.date.getHours();
    hour = (hour > 12) ? hour - 12 : hour;
    
    // Set current hour in degrees
    var degree = 'rotate(' + ((this.HOUR_DEG * (this.date.getMinutes() / 60)) + (this.HOUR_DEG * hour)) + 'deg)';
    
    // Apply the degree
    if (this.hour){
      if (hour === 12 && this.date.getMinutes() === 59){
        ++this.iteration.hour;
      }
      
      this.hour.style.webkitTransform = degree;
      this.hour.style.transform       = degree;
    }
  };
  
  /**
   * Get minute and set degree of rotation
   */
  Clock.prototype.getMinutes = function(){
    // Set current minute in degrees
    var degree = 'rotate(' + (this.MIN_SEC_DEG * this.date.getMinutes() + (this.iteration.min  * 360)) + 'deg)';
    
    // Apply the degree
    if (this.min){
      if (this.date.getMinutes() === 59 && 
          this.date.getSeconds() === 59){
        ++this.iteration.min;
      }
      
      this.min.style.webkitTransform = degree;
      this.min.style.transform       = degree;
    }
  };
  
  /**
   * Get seconds and set degree of rotation
   */
  Clock.prototype.getSeconds = function(){
    // Set current seconds in degrees
    var degree = 'rotate(' + (this.MIN_SEC_DEG * this.date.getSeconds() + (this.iteration.sec  * 360)) + 'deg)';
    
    // Apply the degree
    if (this.sec){
      if (this.date.getSeconds() === 59){
        ++this.iteration.sec;
      }
      this.sec.style.webkitTransform = degree;
      this.sec.style.transform       = degree;
    }
  };

  /**
   * Get AM/PM and set color scheme
   */
  Clock.prototype.getPeriod = function(){
    var html = document.documentElement;
    var isAverageDayTime = (this.date.getHours() > 6) && (this.date.getHours() < 18);
    html.className = isAverageDayTime ? 'day' : 'night';
  };
  
  /**
   * Clock initialization
   */
  Clock.prototype.init = function(){
    // Fire clock functions once per sec
    setInterval((function(){
    	this.date = new Date();
      this.getHour();
      this.getMinutes();
      this.getSeconds();
      this.getPeriod();
    }).bind(this), 1000);
  };
   
  /**
   * Can I kick it?...
   * @constructs Clock
   */
  var clock = new Clock();
  
  /**
   * ...YES YOU CAN!
   */
  clock.init();
})();
              
            
!
999px

Console