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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                
  <header></header>
  <section></section>
              
            
!

CSS

              
                /* Bootstrap 4 Reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -ms-overflow-style: scrollbar;
  -webkit-tap-highlight-color: transparent;
  font-size: 62.5%;
}

@-ms-viewport {
  width: device-width;
}

article, aside, dialog, figcaption, figure, footer, header, hgroup, main, nav, section {
  display: block;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 1.4rem;
  font-weight: normal;
  line-height: 1.5;
  color: #212529;
  text-align: left;
  background-color: #fff;
}

h1, h2, h3, h4, h5, h6 {
  margin-top: 0;
  margin-bottom: .5rem;
}

p {
  margin-top: 0;
  margin-bottom: 1rem;
}

html, body, h1, h2, h3, h4, h5, h6, p, ol, ul, li, dl,
dt, dd, blockquote, address, table {
  margin: 0;
  padding: 0;
}

* {
  font-weight: 100;
}


/****************/
/* Local Styles */
/****************/
body {
  font-size: 100%;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  font-size: 100%;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  font-family: sans-serif;
  font-weight: 100;
  background: linear-gradient(45deg, white 25%,
    #eee 25%, #eee 50%, 
    white 50%, white 75%, 
    #eee 75%);
  background-size:10px 10px;
}
article {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  margin: 20px;
  padding: 20px;
  height: 80%;
}
header {
  box-shadow: 0 6px 20px rgba(0,0,0,0.85);
  padding: 20px;
  background-color: #222;
}
h1 {
  color: #fff;
  margin: 0;
  font-size: 2.4rem;
}
section {
  height: 80vh;
  display: flex;
  justify-content: center;
  padding: 60px;
}
#clock {
  height: 300px;
  width: 300px;
}
              
            
!

JS

              
                /** @jsx h */
const { h, render, Component } = composi

const title = new Component({
  container: 'header',
  render() {
    return (
      <h1>Composi - SVG Clock</h1>
    )
  }
})
title.update()

class Clock extends Component {
  render() {
    return (
      <svg id='clock' xmlns="http://www.w3.org/2000/svg"
        xmlns-xlink="http://www.w3.org/1999/xlink"
        version="1.1"
        baseProfile="full"
        width="100%" 
        height="100%" 
        viewBox="0 0 200 200">
        <defs>
          <symbol id="threeHourStroke">
            <line x1="100" y1="0" x2="100" y2="18" stroke="#333" stroke-width="4.4" stroke-linecap="butt"/>
          </symbol>    
          <symbol id="hourStroke">
            <line x1="100" y1="0" x2="100" y2="14"  stroke="#333" stroke-width="4.4" stroke-linecap="butt"/>
          </symbol>
          <symbol id="minuteStroke">
            <line x1="100" y1="0" x2="100" y2="8" stroke="#333" stroke-width="3.6" stroke-linecap="butt"/>
          </symbol>

          <symbol id="quarterStrokes">
            <use href="#threeHourStroke" />
            <use href="#minuteStroke" transform="rotate( 6, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(12, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(18, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(24, 100, 100)"/>
            <use href="#hourStroke"   transform="rotate(30, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(36, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(42, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(48, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(54, 100, 100)"/>
            <use href="#hourStroke"   transform="rotate(60, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(66, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(72, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(78, 100, 100)"/>
            <use href="#minuteStroke" transform="rotate(84, 100, 100)"/>
          </symbol>
        </defs>
        <circle cx="100" cy="100" r="98.5" fill="#fff" stroke-width="3" stroke="#000"/>
        <g clip-path="url(#dialCircle)">
          <use href="#quarterStrokes"/>
          <use href="#quarterStrokes" transform="rotate( 90, 100, 100)"/>
          <use href="#quarterStrokes" transform="rotate(180, 100, 100)"/>
          <use href="#quarterStrokes" transform="rotate(270, 100, 100)"/>
        </g>
        <g id="hourHand" fill="#222">
          <rect x="97.3" y="65" width="5.4" height="35" fill="rgb(34,34,34)"/>
          <circle transform="matrix(1,0,0,1,3,0)" cx="97.3" cy="58.5" r="9" fill="rgb(34,34,34);"/>
          <circle transform="matrix(1,0,0,1,-3,0)" cx="102.7" cy="58.5" r="9" fill="rgb(34,34,34)"/>
          <path d="M90.757,58.5C90.757,54.167 92.2,47.167 100,37.5C107.8,47.167 109.329,54.167 109.329,58.5L90.757,58.5Z" fill="rgb(34,34,34)" fill-rule="nonzero"/>
          <path d="M93.5,123C97.833,124.667 102.167,124.667 106.5,123C104.167,118.333 102.9,110.667 102.7,100L97.3,100C97.3,110.667 96.033,118.333 93.5,123Z" fill="rgb(34,34,34" fill-rule="nonzero"/>
          <circle cx="100" cy="100" r="7.4" fill="rgb(34,34,34)"/>
        </g>
        <g id="minuteHand" fill="#222">
          <polygon points="95.3,49 99.5,2 100.5,2 104.7,49 102.7,100 97.3,100" stroke="none"/>
          <path d="M 93.5,123 Q 100,125.5 106.5,123 Q 103,116 102.7,100 L 97.3,100 Q 97.3,116 93.5,123 Z" stroke="none"/>
          <circle cx="100" cy="100" r="7" stroke="none"/>
        </g>
        <g id="secondHand">
          <polygon points="98,4 102,4 102.3,36 97.7,36" fill="#ad1a14" stroke="none"/>
          <circle cx="100" cy="45" r="10" fill="none" stroke="#ad1a14" stroke-width="4"/>
          <polygon points="97.5,56 102.5,55 103,102 97,102" fill="#ad1a14" stroke="none"/>
        </g>
      </svg>
    )
  }
  tick() {
    var now     = new Date();
    var hours   = now.getHours();
    var minutes = now.getMinutes();
    var time    = Math.min(60000, 1.025 * (1000 * now.getSeconds() + now.getMilliseconds()));
    var seconds = Math.floor(time / 1000);
    var millis  = time % 1000;
    rotate('hourHand',   hours * 30 + minutes * 0.5);
    rotate('minuteHand', minutes * 6);
    rotate('secondHand', 6 * seconds + 3 * (1 + Math.cos(Math.PI + Math.PI * (0.001 * millis))));

    function rotate(id, angle) {
      const element = document.getElementById(id);
      if (element) {
        element.setAttribute('transform', 'rotate(' + angle + ', 100, 100)');
        if (element.getAttribute('visibility') == 'hidden') {
          element.setAttribute('visibility', 'visible');
        }
      }
    }
  }
  componentDidMount() {
    setInterval(() => this.tick())
  }
}

const clock = new Clock({
  container: 'section'
})
clock.update()
              
            
!
999px

Console