Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


                <p id="js-timetext">0.00</p>
<p id="js-btn--start">start</p>
<p id="js-btn--stop">stop</p>
<p id="js-btn--reset">reset</p>


                .btn {
  width: 100px;
  padding: 5px;
  color: #fff;
  display: inline-block;
  background: #0af;
  border-radius: 5px;
  box-shadow :0 4px 0 #08c;
  cursor: pointer;
.btn + .btn {
  margin-left: 20px;
.active {
  opacity: 1;
.noactive {
  opacity: .5;


  "use strict";//最近は厳密なエラーチェックをするのが推奨されている
  var startTime;//タイムを押した時の時刻を保持しておくため
  var timerId;//タイマーを回していくので
  var elapsedTime = 0;//タイマー経過をこの変数で保持
  var isRunning = false; //ボタンは押せてしまうのでタイマーの状態を保持。その値に応じて処理するかを決める
  var timetext = document.getElementById("js-timetext");
  var btnStart = document.getElementById("js-btn--start");
  var btnStop = document.getElementById("js-btn--stop");
  var btnReset = document.getElementById("js-btn--reset");
  function setBtnState (start, stop, reset){//ボタンの状態をture or falseで渡す
    //trueの時はbtn active。そうでない時はbtn noactiveをつける。三項演算子ですっきり書ける
    btnStart.className = start ? "btn active" : "btn noactive"; 
    btnStop.className = stop ? "btn active" : "btn noactive"; 
    btnReset.className = reset ? "btn active" : "btn noactive"; 
  setBtnState (true, false, false);
  btnStart.addEventListener("click", function(){
    if (isRunning) retune;//タイマーが走っていたら二重起動させない
    isRunning = true;//
    startTime =;//1970年 1月1日 00:00:00 からの経過ミリ秒を取得
    setBtnState (false, true, false);//startをクリックしたらstopだけtrueにする

  btnStop.addEventListener("click", function(){
    if (!isRunning) retune;//タイマー止まってる時には何もしてほしくない
    isRunning = false;//
    elapsedTime += - startTime;//現在の時間から最初の時間を引いたものを足しあげる
    setBtnState (true, false, true);//stopをクリックしたらstop以外をtrueに
  btnReset.addEventListener("click" , function(){
    if (isRunning) retune;//タイマーが走っていたら二重起動させない
    timetext.innerHTML = "0.00";//0.00に書き換える
    elapsedTime = 0;//0に書き換える
    setBtnState (true, false, false);//resetを押したら最初と同じ状態に

  function updateTimerText(){//updateTimerTextという関数を用意
    timerId = setTimeout(function(){
      var t = - startTime + elapsedTime;
      timetext.innerHTML = (t / 1000).toFixed(2);//ミリ秒を普通の秒になおすために1000で割る。toFixedは2ケタまで表示
    }, 10);//10ミリ秒間隔で実行