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="container">
    <h5>Add Date</h5>
    <form id="addDate">
        <input type="date" name="date" id="date">
        <input type="time" name="time" id="time">
        <button type="submit">Submit</button>
    </form>
    <p class="hidden">You have</p>
    <div class="pickedTime">

        <div class="time">
            <span id="time-years">-</span>
            <p>Years</p>
        </div> <!-- time -->

        <div class="time">
            <span id="time-days">-</span>
            <p>Days</p>
        </div> <!-- time -->

        <div class="time">
            <span id="time-hours">-</span>
            <p>Hours</p>
        </div> <!-- time -->

        <div class="time">
            <span id="time-minutes">-</span>
            <p>Minutes</p>
        </div> <!-- time -->

        <div class="time">
            <span id="time-seconds">-</span>
            <p>Seconds</p>
        </div> <!-- time -->

    </div> <!-- pickedTime -->
    <p class="hidden">Until: <span id="until"></span></p>

    <h1>Coming soon</h1>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam praesentium impedit temporibus accusantium
        distinctio consectetur nam, architecto blanditiis laboriosam! Quasi ducimus dolor iste fugiat doloremque
        quia
        non velit, nulla deserunt ratione harum debitis nemo porro?</p>
    <div class="boxes">
        <div class="box">
            <span id="days">-</span>
            <p>Days</p>
        </div> <!-- box -->

        <div class="box">
            <span id="hours">-</span>
            <p>Hours</p>
        </div> <!-- box -->

        <div class="box">
            <span id="minutes">-</span>
            <p>Minutes</p>
        </div> <!-- box -->

        <div class="box">
            <span id="seconds">-</span>
            <p>Seconds</p>
        </div> <!-- box -->

    </div> <!-- boxes -->
</div> <!-- container -->
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap')

$dark: #000000
$light: #ffffff
$main: #b6281b
$shadow: rgba(0,0,0,0.5)
@mixin inspect()
    border: 1px solid red
    
*
    box-sizing: border-box
    padding: 0
    margin: 0
body 
    width: 100%
    min-height: 100vh
    font-family: 'Roboto', sans-serif
    background: url('https://cdn.pixabay.com/photo/2018/03/26/14/07/space-3262811_960_720.jpg') no-repeat center/cover
    display: flex
    flex-direction: column
    align-items: center
    position: relative
    &::before 
        content: ''
        position: absolute
        width: 100%
        height: 100%
        background: $shadow
        z-index: -1
.container
    text-align: center
    margin: 2rem auto 0
    padding: 0 15px
    &>*
        padding: 1rem
    h5
        font-size: 2rem
    form 
        display: flex
        justify-content: center
        flex-wrap: wrap
        width: 100%
        height: 100%
        input 
            padding: 10px 15px
            font-size: 1.2rem
            border: none
            border-right: 1px solid $shadow
        button
            font-size: 1.2rem
            outline: none
            border: none
            padding: 10px 15px
            background: $light
            color: $main
            cursor: pointer
            transition: 0.2s linear
            &:hover
                background: $main
                color: $light

    h1
        font-size: 3rem
        text-transform: uppercase
    h5,h1,p
        color: $light
        text-shadow: 0 0 5px $shadow
    p
        font-size: 1.2rem
        width: 80%
        margin: auto
    .hidden 
        display: none
    .pickedTime
        display: flex
        flex-wrap: wrap
        justify-content: center
        align-items: center
        .time 
            margin: 0.5rem
            padding: 0.5rem 1rem
            background: $light
            span 
                font-size: 2.5rem
                color: $main
            p 
                color: $dark
                width: 100%
    .boxes 
        display: flex
        flex-wrap: wrap
        justify-content: center
        align-items: center
        .box
            background: $light
            margin: 1rem
            padding: 1rem 2rem
            display: flex
            flex-direction: column
            text-align: center
            span 
                color: $main
                font-weight: bold
                font-size: 4rem
            p 
                color: $dark
                width: 100%

              
            
!

JS

              
                const s = 1000,
    m = s * 60,
    h = m * 60,
    d = h * 24,
    y = d * 365;

function counting() {
    const days = document.getElementById('days'),
        hours = document.getElementById('hours'),
        minutes = document.getElementById('minutes'),
        seconds = document.getElementById('seconds'),
        timeNow = new Date().getTime(),
        setDate = new Date('01/01/2021').getTime(),
        diff = setDate - timeNow;

    days.innerText = Math.floor(diff / d);
    hours.innerText = Math.floor((diff % d) / h);
    minutes.innerText = Math.floor((diff % h) / m);
    seconds.innerText = Math.floor((diff % m) / s);
    // console.log(Math.floor(diff / (d * 365)));

}
setInterval(() => {
    counting();
}, 1000);


const formAddDate = document.getElementById('addDate');
formAddDate.addEventListener('submit', addTime);

function addTime(e) {
    const date = document.getElementById('date').value,
        time = document.getElementById('time').value,
        timeYears = document.getElementById('time-years'),
        timeDays = document.getElementById('time-days'),
        timeHours = document.getElementById('time-hours'),
        timeMinutes = document.getElementById('time-minutes'),
        timeSeconds = document.getElementById('time-seconds');

    if (date && time) {
        const chosenDate = new Date(`${date} ${time}`)
        document.getElementById('until').innerText = chosenDate.toUTCString();

        const hidden = document.querySelectorAll('.hidden');
        hidden.forEach(el => el.style.display = 'block');

        const interval = setInterval(() => {
            const pickedDate = new Date(`${date} ${time}`).getTime(),
                currentDate = new Date().getTime(),
                difference = pickedDate - currentDate,
                years = Math.floor(difference / y);

            if (years < 1) {
                timeYears.parentElement.style.display = 'none';
            } else {
                timeYears.parentElement.style.display = 'block';

            }
            timeYears.innerHTML = Math.floor(difference / y);
            timeDays.innerHTML = Math.floor((difference % y) / d);
            timeHours.innerHTML = Math.floor((difference % d) / h);
            timeMinutes.innerHTML = Math.floor((difference % h) / m);
            timeSeconds.innerHTML = Math.floor((difference % m) / s);
        }, 1000);

        document.querySelector('button').addEventListener('click', () => {
            clearInterval(interval);
        });

        formAddDate.reset();
    }
    e.preventDefault();
}
              
            
!
999px

Console