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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Abolfazl-jmd Dictionary App</title>
    <link
      rel="stylesheet"
      href="https://unicons.iconscout.com/release/v4.0.0/css/line.css"
    />
  </head>
  <body>
    <div class="container">
      <div class="dic__wrapper">
        <header class="dic__header">
          <h1 class="title">English Dictionary</h1>
          <div class="input">
            <i class="uil uil-search search"></i>
            <input
              class="search__box"
              type="text"
              placeholder="Search a word"
            />
          </div>

          <p class="description">
            Type a word and press enter to get meaning, examples, pronuciation,
            and synonyms of that types word.
          </p>
        </header>

        <section class="dic__details"></section>
      </div>
    </div>
    
  </body>
</html>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #bb86fc;
  --secondary-color: #03dac6;
  --error-color: #cf6679;
  --background-color: #312c2c;
  --text-color: #fff;
  --primary-varient: #2596b9;
  --icon-hover-color: #d85e75;
}

html {
  font-size: 62.5%;
  color: var(--text-color);
}

.container {
  background-color: aquamarine;
  width: 100%;
  height: 100vh;
  position: relative;
}

.dic__wrapper {
  background: var(--background-color);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
  padding: 20px;
  width: 50%;
}

.dic__header {
  text-align: center;
  margin-bottom: 10px;
}

.title {
  font-size: 4rem;
  margin-bottom: 10px;
  letter-spacing: 1px;
  color: var(--primary-color);
}
.input {
  position: relative;
}

.search__box {
  width: 70%;
  height: 30px;
  margin-bottom: 10px;
  background: var(--secondary-color);
  border: none;
  padding-left: 35px;
  border-radius: 5px;
  color: #fff;
}

.search {
  font-size: 2.5rem;
  position: absolute;
  transform: rotateY(180deg);
  vertical-align: middle;
  margin-top: 3px;
  margin-left: 5px;
  color: var(--primary-color);
  cursor: pointer;
}

.description {
  color: var(--error-color);
  font-size: 1.5rem;
}

.search__box:focus {
  outline: none;
}

.search__box::placeholder {
  color: #fff;
}
.search__box::-webkit-search-cancel-button {
  cursor: pointer;
}

.word {
  font-size: 2.5rem;
  color: var(--primary-color);
}

.word--detail {
  font-size: 1.5rem;
  color: var(--primary-varient);
  letter-spacing: 1.5px;
}

.pronunce__icon {
  color: var(--error-color);
  font-size: 4rem;
  cursor: pointer;
  transition: 0.2s ease-in;
}

.pronunce__icon:hover {
  color: var(--icon-hover-color);
}

.main__detail {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.meaning {
  margin: 10px 0;
  padding: 10px 0;
  padding-left: 5px;
  border-radius: 8px;
  overflow-wrap: break-word;
}

.meaning-1 {
  border-left: 3px solid var(--secondary-color);
}

.meaning-2 {
  border-left: 3px solid var(--primary-color);
}

.meaning-3 {
  border-left: 3px solid var(--primary-varient);
}

.word__title {
  font-size: 2rem;
}

.word__meaning {
  margin: 5px 0;
  font-size: 1.5rem;
}

@media (max-width: 800px) {
  .dic__wrapper {
    width: 80%;
  }
}

@media (max-width: 485px) {
  .dic__wrapper {
    width: 95%;
    min-width: 50%;
  }
}

@media (max-width: 365px) {
  .dic__wrapper {
    width: 95%;
  }
  .title {
    font-size: 3rem;
  }
  .search__box {
    width: 100%;
  }
  .word {
    font-size: 2rem;
  }
  .pronunce__icon {
    font-size: 3rem;
  }
  .word__title {
    font-size: 1.5rem;
  }
  .word__meaning {
    font-size: 1.4rem;
  }
}
              
            
!

JS

              
                
// COMMON STUFF
const dicWrapper = document.querySelector(".dic__details");
const inputSearchInput = document.querySelector(".search__box");
const searchIcon = document.querySelector(".search");
const searchedWord = document.querySelector(".word");
const wordDetail = document.querySelector(".word--detail");
const wordFonetic = document.querySelector(".pronunciation");
const wordMeaning = document.querySelector(".word--meaning");
const wordExample = document.querySelector(".example");
const wordSynonyms = document.querySelector(".synonym");
const searchDescription = document.querySelector(".description");
let pronuncitionAudio;
let voiceIcon;

// Searching the word;

const searchWord = function () {
  let word = inputSearchInput.value;
  let url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;

  fetch(url)
    .then((response) => response.json())
    .then((data) => {
      let definition = data[0].meanings[0].definitions[0].definition;

      let partOfSpeech = data[0].meanings[0].partOfSpeech;

      let phonetic = data[0].phonetic;

      let word = data[0].word;

      let synonyms = [...data[0].meanings[0].definitions[0]?.synonyms];

      let example = data[0].meanings[0].definitions[0].example;

      pronuncitionAudio = `http:${data[0].phonetics[0].audio}`;

      let markup = `<div class="main__detail">
      <div class="word__details">
        <h2 class="word">${word}</h2>
        <p class="word--detail">
          ${partOfSpeech} <span class="pronunciation">/${phonetic}/</span>
        </p>
      </div>
      <p class="pronunce__icon"><i class="uil uil-volume-up"></i></p>
    </div>
    <hr />
    <div class="meaning meaning-1">
      <h3 class="word__title">Meaning</h3>
      <p class="word__meaning word--meaning">
        ${definition}
      </p>
    </div>
    <hr />
    <div class="meaning meaning-2">
      <h3 class="word__title">Example</h3>
      <p class="word__meaning example">
        ${example}
      </p>
    </div>
    <hr />
    <div class="meaning meaning-3">
      <h3 class="word__title">Synonyms</h3>
      <p class="word__meaning synonym">
      ${findSynonym(synonyms)}
      </p>
    </div>`;

      // Now we should add the markup to our container
      dicWrapper.innerHTML = markup;

      // Grabbing the voice icon
      voiceIcon = document.querySelector(".pronunce__icon");

      // The pronunciation voice
      voiceIcon.addEventListener("click", () => {
        let audio = new Audio(pronuncitionAudio);
        audio.play();
      });

      inputSearchInput.value = "";
      searchDescription.innerText = "";
    })
    .catch(
      (searchDescription.innerText = `Sorry, the word ${inputSearchInput.value} is not valid. Please search another one.`)
    );
};

searchIcon.addEventListener("click", searchWord);
inputSearchInput.addEventListener("keydown", (e) => {
  if (e.keyCode === 13) {
    searchWord();
  }
});

findSynonym = function (synonyms) {
  let synList = [];
  if (synonyms.length === 0) return " ";
  else {
    synonyms.forEach((word, i) => {
      if (i > 4) return;
      else {
        synList.push(word);
      }
    });
  }
  return synList.join(", ");
};
              
            
!
999px

Console