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="background">
  
  <div class="header">
    <svg width="130" height="50" class="DisplayNone_desktop-oversized__OPqkZ spacing_noMargin__Q_PsJ spacing_oversized-margin-right-50__Z6BXP spacing_desktop-margin-right-30__C4NEG spacing_mobile-margin-right-15__uM70E spacing_tablet-margin-right-15__zeT1z" viewBox="0 0 130.318 50"><g transform="translate(-3894 2762)"><rect width="50" height="50" rx="8" transform="translate(3894 -2762)" fill="#07a081"></rect><path d="M32.671,44.73h7.091V37.935H41.9a5.657,5.657,0,1,0,0-11.314H32.671Zm10.763,3.622H29V23H41.9a9.271,9.271,0,0,1,1.53,18.435Z" transform="translate(3880 -2773)" fill="#fff"></path><path d="M1.694,0h2.6V-6.16H7.656a6.579,6.579,0,0,0,2.915-.616,4.639,4.639,0,0,0,1.969-1.76,5.1,5.1,0,0,0,.7-2.728,5.146,5.146,0,0,0-.7-2.75,4.639,4.639,0,0,0-1.969-1.76,6.579,6.579,0,0,0-2.915-.616H1.694Zm2.6-8.47v-5.61H7.722a3.03,3.03,0,0,1,2.134.748,2.641,2.641,0,0,1,.814,2.046A2.684,2.684,0,0,1,9.856-9.24a2.978,2.978,0,0,1-2.134.77ZM20.372.264a5.925,5.925,0,0,0,3.179-.836,4.64,4.64,0,0,0,1.9-2.112l-2.024-.99a3.73,3.73,0,0,1-1.2,1.243,3.29,3.29,0,0,1-1.837.5A3.458,3.458,0,0,1,18-2.827a3.433,3.433,0,0,1-1.1-2.409H25.74a3.34,3.34,0,0,0,.088-.572q.022-.308.022-.594a6.154,6.154,0,0,0-.671-2.849,5.361,5.361,0,0,0-1.936-2.112,5.61,5.61,0,0,0-3.069-.8,5.7,5.7,0,0,0-3,.8,5.773,5.773,0,0,0-2.1,2.2,6.476,6.476,0,0,0-.77,3.179A6.482,6.482,0,0,0,15.081-2.8,5.9,5.9,0,0,0,17.226-.561,5.958,5.958,0,0,0,20.372.264Zm-.2-10.34a3,3,0,0,1,2.112.792,2.9,2.9,0,0,1,.924,2.068H16.94a3.313,3.313,0,0,1,1.122-2.112A3.208,3.208,0,0,1,20.174-10.076ZM26.422,0h2.926l2.706-3.982L34.738,0h2.926L33.506-5.962l4.18-5.94H34.76L32.054-7.964,29.348-11.9H26.422l4.158,5.94ZM44.088.264a5.925,5.925,0,0,0,3.179-.836,4.64,4.64,0,0,0,1.9-2.112l-2.024-.99a3.73,3.73,0,0,1-1.2,1.243,3.29,3.29,0,0,1-1.837.5,3.458,3.458,0,0,1-2.4-.891,3.433,3.433,0,0,1-1.1-2.409h8.844a3.34,3.34,0,0,0,.088-.572q.022-.308.022-.594A6.154,6.154,0,0,0,48.9-9.251a5.361,5.361,0,0,0-1.936-2.112,5.61,5.61,0,0,0-3.069-.8,5.7,5.7,0,0,0-3,.8,5.773,5.773,0,0,0-2.1,2.2,6.476,6.476,0,0,0-.77,3.179A6.482,6.482,0,0,0,38.8-2.8,5.9,5.9,0,0,0,40.942-.561,5.958,5.958,0,0,0,44.088.264Zm-.2-10.34A3,3,0,0,1,46-9.284a2.9,2.9,0,0,1,.924,2.068h-6.27a3.313,3.313,0,0,1,1.122-2.112A3.208,3.208,0,0,1,43.89-10.076ZM51.546,0h2.486V-16.654H51.546ZM60.9.264a5.6,5.6,0,0,0,2.321-.451,3.635,3.635,0,0,0,1.551-1.254,3.21,3.21,0,0,0,.55-1.859,3.088,3.088,0,0,0-.792-2.123A4.635,4.635,0,0,0,62.26-6.732L60.324-7.3a4.436,4.436,0,0,1-1.034-.484,1.023,1.023,0,0,1-.484-.924,1.212,1.212,0,0,1,.484-1.012,2.068,2.068,0,0,1,1.3-.374,3.005,3.005,0,0,1,1.705.506A2.944,2.944,0,0,1,63.4-8.228l1.914-.9a4.344,4.344,0,0,0-1.8-2.233,5.337,5.337,0,0,0-2.9-.8,5.1,5.1,0,0,0-2.178.451,3.7,3.7,0,0,0-1.518,1.243,3.2,3.2,0,0,0-.55,1.87,3.1,3.1,0,0,0,.759,2.09,4.624,4.624,0,0,0,2.3,1.32l1.87.528a3.923,3.923,0,0,1,1.078.473,1.057,1.057,0,0,1,.506.957,1.259,1.259,0,0,1-.55,1.078,2.391,2.391,0,0,1-1.43.4,3.2,3.2,0,0,1-1.881-.594A4.049,4.049,0,0,1,57.684-3.96l-1.914.9a4.774,4.774,0,0,0,1.925,2.42A5.7,5.7,0,0,0,60.9.264Z" transform="translate(3959 -2728)" fill="#fff"></path></g></svg>
    <div class="tabs-container">
    <div class="Explore">Explore</div>
    <div class="License">License</div>
    <div class="Bell">🔔</div>
      <div class="Avatar_avatar__Om2KJ spacing_noMargin__Q_PsJ Avatar_size-30__eApGp clickable_clickable__Klxi1"><img src="https://images.pexels.com/users/avatars/447198683/yrwin-m-avellona-987.jpeg?auto=compress&amp;fit=crop&amp;h=30&amp;w=30&amp;dpr=1" srcset="https://images.pexels.com/users/avatars/447198683/yrwin-m-avellona-987.jpeg?auto=compress&amp;fit=crop&amp;h=30&amp;w=30&amp;dpr=1 1x, https://images.pexels.com/users/avatars/447198683/yrwin-m-avellona-987.jpeg?auto=compress&amp;fit=crop&amp;h=30&amp;w=30&amp;dpr=2 2x" alt="Yrwin M Avellona" class="spacing_noMargin__Q_PsJ" width="30" height="30"></div>
      <div class="Upload"><a class="Button_button__L4pRn spacing_noMargin__Q_PsJ spacing_margin-left-15__5DwCN spacing_padding-right-20__Q3ufi spacing_padding-left-20__GcW24 useAuth_hideWhenSignedOut__hAWWD Button_clickable__WBdod Button_white__snM9f Link_link__mTUkz spacing_noMargin__Q_PsJ" href="/upload/"><span class=""><span class="Button_text__mn5Ou">Upload</span></span></a></div> 
  </div>
  </div>
  
  <div class="background-content">
    <h1>The best free stock photos, royalty free images & videos shared by creators.</h1>
    <form id="search-form">
<input id= "search-bar" placeholder="Search for free photos" type="text">
</form>
</div>
  <h4 id="creator">
    <a href="https://www.pexels.com/photo/brown-rocks-during-golden-hour-2014422/">Photo</a> by <a href="https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=1200&w=800">Joey Farina</a>
  </h4>
  </div>
<a href="https://www.pexels.com">Photos provided by Pexels</a>
</div>
   <h1 id="free-stock-image">Free Stock Images</h1>

    <div id="picture-div"></div>
              
            
!

CSS

              
                * {
  margin:  0px;
 }

body {
        text-align: center;
        font-family:PlusJakartaSans,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Cantarell,Helvetica Neue,Ubuntu,sans-serif; ;
    }


.background {
  background-image:url("https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg?auto=compress&cs=tinysrgb&fit=crop&h=1200&w=800");
    height: 500px;
    background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
        display: flex;
        flex-direction: column;
        justify-content: center;
        /* align-items: center; */
        margin-bottom: 20px;
}
.tabs-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
a {
  color: white;
}

.Explore {
  text-color: white;
  margin: 5%;
  cursor: pointer;
}

.License {
   margin: 5%;
   cursor: pointer;
}
.Bell {
  margin: 5%;
  cursor: pointer;
}

.header {
  display: flex;
  margin: 0px 133px;
  padding: 20px 30px;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.Navbar_avatar__lI9jD {
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
}

.Avatar_size-30__eApGp {
    width: 30px;
    min-width: 30px;
    max-width: 30px;
    height: 30px;
    min-height: 30px;
    max-height: 30px;
}



.background-content{
        max-width: 630px;
        display: flex;
        box-sizing: border-box;
        flex-direction: column;
        justify-content: center;
        padding-top: 50px;
        text-size-adjust: 100px;
        line-height: 19.6px;
        color:white;
        font-size: 14px;
        margin: auto;
    }

#search-form {
    position: relative;
    display: center;
    width: 100%;
    height: 90px;
}

#creator{
        text-align: right;
        margin-right: 20px;
        margin-bottom: 10px;
}
  #creator a{
 color: white;
 }

.Upload {
  color: #000;
  background: #fff;
   border: 2px solid;
   border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  position: relative;
    z-index: 0;
  max-width: 100%;
  height: 50px;
  transition: background-color .1s,border ease-in-out,transform .1s,box-shadow 5ms,border-color .25s;
  vertical-align: top;
  white-space: nowrap;
    text-decoration: none;
    letter-spacing: -.015em;
    outline: none;
  margin: 15%
}



#search-bar {
  height: 30px;
    margin: 20px 0;
    font-size: 18px;
    font-weight: 400;
    line-height: 20.7px;
    padding: 8px 4px 8px 20px;
    width: 580px;
    border: solid 2px;
    border-radius: 10px;
}

#free-stock-image{
text-align: left;
margin-left: 133px;
margin-bottom: 20px;
}

#picture-div {
  display: flex;
   flex-wrap: wrap;
        text-align: left;
        margin: auto;
   -webkit-animation: fadeIn 5s;
  -moz-animation: fadeIn 5s;
  -o-animation: fadeIn 5s;
  -ms-animation: fadeIn 5s;
}
.picture-div:hover {
  background-color: blue;
}

.photo-div {
  width: 33%;
  animation: fadeIn 5s;
   -webkit-animation: fadeIn 5s;
  -moz-animation: fadeIn 5s;
  -o-animation: fadeIn 5s;
  -ms-animation: fadeIn 5s;
  cursor: pointer;
   transition: background-color 0.5s;
}
.photo-div:hover {
  background-color: blue;
}

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@-moz-keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@-webkit-keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@-o-keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@-ms-keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

img {
  width: 90%;
}

a {
  color: black;
}

              
            
!

JS

              
                var searchForm = document.querySelector('#search-form');
console.log(searchForm);
    searchForm.addEventListener('submit', function(e) {
      //This is the part where I am having an error because of the addEventListener
  e.preventDefault();
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      
       var res = JSON.parse(xhttp.responseText);
       var photoData = res.photos.map(function(photo) {
        return photo;
       });  
      
       var container = document.querySelector('#picture-div')
           container.innerHTML = '';
      console.log(photoData);
      if(photoData.length) {
     photoData.forEach(function(picture) {
        console.log(picture);
        var pictureDiv = document.createElement('div')
        pictureDiv.classList.add('photo-div')
         if(picture.src.landscape) {
          pictureDiv.innerHTML = `
    <figure>
     <img src=${picture.src.landscape}>
      <figcaption>
      This <a href=${picture.url}>Photo</a> was taken by <a href=${picture.photographer_url}>${picture.photographer}</a> on Pexels.
                                </figcaption>
                            </figure>
        `; 
         }
        container.appendChild(pictureDiv);
       }) 
        
      } else {
           container.innerHTML = `
   <h1>There is no photo for this search in pexel website please try again</h1>`;
      }
      
      
    }     
};
     var textValue = document.querySelector('#search-bar').value
      xhttp.open("GET",`https://api.pexels.com/v1/search?query=${textValue}`, true);
      
      
    xhttp.setRequestHeader('Authorization', 'Daf11Ufiia8ZxULnhAAaDhyqXNkaKwfA259yLSaSlgpuqbLlv4FPW3W3')
    xhttp.send(); 
})

              
            
!
999px

Console