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

              
                <div class="clock">
  <div class="hand hour-hand"></div>
  <div class="hand minute-hand"></div>
  <div class="hand second-hand"></div>
  <div class="center-dot"></div>
</div>
<div class="bla-bla-bla">This clock is a simple analog clock with hour, minute, and second hands, and a vintage design. It was created using HTML, CSS, and JavaScript. The clock is displayed on a circular background with a vintage image, and the hands are designed to match the vintage aesthetic.

  The JavaScript code uses the Date object to get the current time and update the position of the hands every second using the setInterval() method. The positions of the hands are calculated using simple math to convert the current time into degrees for each hand's rotation. The CSS is used to position the hands and add the box shadow effect to the clock. Overall, this clock is a fun and simple project that showcases the power of HTML, CSS, and JavaScript for creating dynamic and interactive web content. </div>
              
            
!

CSS

              
                body {
  background-color: black;
  color: white;
}
.clock {
  width: 90vh;
  height: 90vh;
  border: 1px solid #333;
  border-radius: 50%;
  position: relative;
  margin: 50px auto;
  background-image: url(https://idgrafica.com/wp-content/uploads/2023/02/quadrante-scuro.png);
  background-size: cover;
  background-position: center;
  box-shadow: 0px 4px 5px 2px rgb(0 0 0 / 50%);
}

.hand {
  width: 45%;
  margin-left: 5%;
  height: 6px;
  background-color: #333;
  position: absolute;
  top: 50%;
  transform-origin: 100%;
  transform: rotate(90deg);
  filter: drop-shadow(5px 0px 5px black);
}
.hour-hand {
  z-index: 3;
  height: 16%;
  background-image: url(https://idgrafica.com/wp-content/uploads/2023/02/ore9.png);
  background-size: contain;
  background-repeat: no-repeat;
  background-color: transparent;
  background-position-y: -0px;
  background-position-x: 100%;
  top: 42%;
}
.minute-hand {
  z-index: 2;
  height: 11%;
  background-image: url(https://idgrafica.com/wp-content/uploads/2023/02/minuti9.png);
  background-size: contain;
  background-repeat: no-repeat;
  background-color: transparent;
  background-position-y: 50%;
  background-position-x: 0px;
  top: 44.5%;
  left: 0%;
}
.second-hand {
  z-index: 4;
  background-color: red;
  height: 2px;
}
.center-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 3%;
  width: 3%;
  background-color: red;
  border-radius: 50%;
  z-index: 10;
}
.bla-bla-bla {
  width: 600px;
  margin: auto;
  font-size: 20px;
  text-align: center;
}

              
            
!

JS

              
                // Wait for the page to load before executing the code inside the function
document.addEventListener("DOMContentLoaded", function () {
  // Get the hour, minute, and second hand elements from the HTML document
  const hourHand = document.querySelector(".hour-hand");
  const minuteHand = document.querySelector(".minute-hand");
  const secondHand = document.querySelector(".second-hand");

  // Define a function that will be called repeatedly to update the clock hands
  function setDate() {
    // Get the current time as a Date object
    const now = new Date();

    // Calculate the angle in degrees for the second hand based on the current seconds
    const seconds = now.getSeconds();
    const secondsDegrees = (seconds / 60) * 360 + 90;

    // Set the transform style of the second hand element to rotate it to the correct angle
    secondHand.style.transform = `rotate(${secondsDegrees}deg)`;

    // Calculate the angle in degrees for the minute hand based on the current minutes and seconds
    const minutes = now.getMinutes();
    const minutesDegrees = (minutes / 60) * 360 + (seconds / 60) * 6 + 90;

    // Set the transform style of the minute hand element to rotate it to the correct angle
    minuteHand.style.transform = `rotate(${minutesDegrees}deg)`;

    // Calculate the angle in degrees for the hour hand based on the current hours, minutes, and seconds
    const hours = now.getHours();
    const hoursDegrees = (hours / 12) * 360 + (minutes / 60) * 30 + 90;

    // Set the transform style of the hour hand element to rotate it to the correct angle
    hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
  }

  // Call the setDate function every 1000 milliseconds (1 second) to update the clock hands
  setInterval(setDate, 1000);
});

              
            
!
999px

Console