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

              
                <!-- countdown -->
<div class="countdown">
    <span class="countdown__time js-countdown-day">0</span>
    <span class="countdown__unit">日</span>
    <span class="countdown__time js-countdown-hour">00</span>
    <span class="countdown__unit">時間</span>
    <span class="countdown__time js-countdown-min">00</span>
    <span class="countdown__unit">分</span>
    <span class="countdown__time js-countdown-sec">00</span>
    <span class="countdown__unit">秒</span>
    <span class="countdown__time js-countdown-ms">00</span>
</div><!-- /countdown -->
              
            
!

CSS

              
                .countdown {
    padding: 20px;
    text-align: center;
    border-radius: 5px;
    font-size: 2rem;
    color: #fff;
    background-color: #000;
}
              
            
!

JS

              
                const countdown = ()=>{
    const now = new Date(); //現在日時
    const target = new Date('2023/12/31 23:59:59'); //対象日時
    const differ = target.getTime() - now.getTime(); //残り日時
    
    const ms = Math.floor(differ); //ミリ秒
    const sec = Math.floor(differ / 1000 % 60); //秒
    const min = Math.floor(differ / 1000 / 60 % 60); //分
    const hour = Math.floor(differ / 1000 / 60 / 60 % 24); //時
    const day = Math.floor(differ / 1000 / 60 / 60 / 24); //日

    document.querySelector('.js-countdown-ms').textContent = String(ms).slice(-3, -1);
    document.querySelector('.js-countdown-sec').textContent = String(sec).padStart(2, '0');
    document.querySelector('.js-countdown-min').textContent = String(min).padStart(2, '0');
    document.querySelector('.js-countdown-hour').textContent = String(hour).padStart(2, '0');
    document.querySelector('.js-countdown-day').textContent = String(day).padStart(2, '0');
}
setInterval(countdown, 1);
              
            
!
999px

Console