<div class="container">
  <h1>Sunrise and Sunset Times for NYC</h1>
  <p class="muted">Example using the <a href="https://sunrisesunset.io/api/" target="_blank">SunriseSunset.io API</a>.</p>
  <div class="time-row">
    <div class="block">
      <div class="label">Sunrise</div>
      <div class="data"><strong><span id="sunrise"></span></strong></div>
    <div class="block">
      <div class="label">Sunset</div>
      <div class="data"><strong><span id="sunset"></span></strong></div>
  <div class="block">
      <div class="label">Raw data from API response</div>
      <div class="data"><code id="raw-output"></code></div>
  <div class="footer">
    <a href="https://sunrisesunset.io/api/" target="_blank">SunriseSunset API Documentation</a>
body {
  background: #09090B;
  color: #FAFAFA;
p {
  margin-top: 0;
  margin-bottom: 1.4em;
h1 {
  margin-bottom: 0.2em;
a {
  color: #FAFAFA;
.muted, .muted a, .footer a {
  color: #A1A1AA;
.footer {
  margin-top: 2em;
  font-size: 0.8em;
.container {
  text-align: center;
  max-width: 580px;
  margin: 1em auto;
.time-row {
  display: grid;
  gap: 1em;
  grid-template-columns: repeat(2,minmax(0,1fr));
  margin-bottom: 1em;
.block .label {
  color: #A1A1AA;
  font-size: 0.9em;
  margin-bottom: 0.4em;
.block .data {
  font-size: 1.3em;
.block {
  text-align: left;
  padding: 1.2em;
  display: block;
  overflow-wrap: break-word;
  border: 1px solid #27272A;
  border-radius: 1em;
// Coordinates for New York
const latitude = 40.71427
const longitude = -74.00597
const url = `https://api.sunrisesunset.io/json?lat=${latitude}&lng=${longitude}`

  .then(response => response.json())
  .then(data => {
    document.querySelector('#sunrise').innerHTML = data.results.sunrise
    document.querySelector('#sunset').innerHTML = data.results.sunset
  document.querySelector('#raw-output').innerHTML = JSON.stringify(data)
  .catch(error => console.error('Error:', error))

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.