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

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

              
                <section class="controls">
  <button class="show-quizz">Quizz</button>
  <button class="toggle-kana">Hiragana / Katakana</button>
  <button class="toggle-serif">Toggle Serif</button>
  <button class="toggle-secondary">Toggle Additionals</button>
</section>
<section class="letters"></section>
<section class="search">
  <label for="name-input">Search by name</label>
  <input id="name-input" type="text">
  <div class="name-search"></div>
  <label for="hiragana-input">Search by hiragana</label>
  <input id="hiragana-input" type="text">
  <div class="hiragana-search"></div>
  <label for="katakana-input">Search by katakana</label>
  <input id="katakana-input" type="text">
  <div class="katakana-search"></div>
</section>
<section class="quizz">
  <button class="close">x</button>
  <div class="controls">
    <button class="quizz-hiragana">Hiragana</button>
    <button class="quizz-katakana">Katakana</button>
    <button class="quizz-name">Name</button>
  </div>
  <div class="quizz-content">
    <div class="quizz-question"></div>
    <div class="quizz-answer"></div>
  </div>
  <button class="quizz-show-answer">Show answer</button>
</section>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP&family=Noto+Serif+JP&display=swap')

body
  --background: #263238

// Letter element
.letter
  position: relative
  display: flex
  flex-direction: column
  align-items: center
  justify-content: center
  width: 70px
  height: 80px
  color: #212121
  background: #FAFAFA
  
  &.secondary
    background: #EEEEEE
    
    .letter-name
      color: #EF9A9A
      
    .letter-hiragana,
    .letter-katakana
      color: #BDBDBD
    

.letter-hiragana,
.letter-katakana
  font-size: 1.5em
  color: #212121

.letter-name
  font-size: .8em
  font-weight: 700
  color: #D32F2F


// Letters => letter table
.letters
  position: relative
  display: grid
  grid-template-areas: "A KA GA SA ZA TA DA NA HA BA PA MA YA RA WA N" "I KI GI SHI JI CHI DJI NI HI BI PI MI . RI . ." "U KU GU SU ZU TSU DZU NU FU BU PU MU YU RU . ." "E KE GE SE ZE TE DE NE HE BE PE ME . RE . ." "O KO GO SO ZO TO DO NO HO BO PO MO YO RO WO ."
  grid-gap: 2px
  width: 1150px
  margin: 15px auto
  padding: 3em
  font-family: 'Noto Sans JP', sans-serif
  
  .letter-katakana
    display: none
  
  &.serif
    font-family: 'Noto Serif JP', serif
  &.hide-secondary
    grid-template-areas: "A KA SA TA NA HA MA YA RA WA N" "I KI SHI CHI NI HI MI . RI . ." "U KU SU TSU NU FU MU YU RU . ." "E KE SE TE NE HE ME . RE . ." "O KO SO TO NO HO MO YO RO WO ."
    width: 780px
    .secondary
      display: none

  &.show-katakana
    .letter-hiragana
      display: none
    .letter-katakana
      display: block


// Letter row headings
.letter[data-name="A"],
.letter[data-name="I"],
.letter[data-name="U"],
.letter[data-name="E"],
.letter[data-name="O"]
  &:before
    content: attr(data-row)
    position: absolute
    left: -2em
    color: #757575
    text-transform: lowercase

// Letter column headings
.letter[data-name="KA"],
.letter[data-name="GA"],
.letter[data-name="SA"],
.letter[data-name="ZA"],
.letter[data-name="TA"],
.letter[data-name="DA"],
.letter[data-name="NA"],
.letter[data-name="HA"],
.letter[data-name="BA"],
.letter[data-name="PA"],
.letter[data-name="MA"],
.letter[data-name="YA"],
.letter[data-name="RA"],
.letter[data-name="WA"]
  &:before
    content: attr(data-col)
    position: absolute
    top: -2em
    color: #757575
    text-transform: lowercase

// Controls
.controls
  display: flex
  align-items: center
  justify-content: center
  
  button
    margin: 1em .7em
    padding: .6em 1.2em
    font-size: .8em
    color: #212121
    background: #ECEFF1
    border: none
    border-radius: .5em
    cursor: pointer

.search
  display: grid
  grid-template-columns: 140px 50px 150px
  align-items: center
  justify-content: center
  grid-gap: 10px
  margin: auto
  padding: 0 3em 3em
  
input
  width: 40px
  padding: 5px
  text-align: center
  border: none
  border-radius: 5px

.name-search,
.hiragana-search,
.katakana-search
  margin-left: 30px
  color: #FAFAFA
  font-size: 1.4em
  font-family: 'Noto Sans JP', sans-serif

label
  padding: 10px 0
  color: #757575


.quizz
  display: none
  position: absolute
  top: 0
  left: 0
  width: 100%
  height: 100%
  background: var(--background)
  opacity: 0
  transition: opacity .3s ease-in-out
  
  &.active
    display: flex
    flex-direction: column
    align-items: center
    justify-content: center
    opacity: 1
    
  .close
    position: absolute
    top: 15px
    right: 15px
    display: flex
    flex-direction: column
    align-items: center
    justify-content: center
    width: 30px
    height: 30px
    font-size: 18px
    line-height: 0.3
    color: #212121
    background: #ECEFF1
    border: none
    border-radius: 40px
    cursor: pointer

.quizz-content
  display: flex
  align-items: center
  justify-content: center
  width: 100%
  max-width: 500px
  margin: 0 auto
  
.quizz-question,
.quizz-answer
  display: flex
  flex-direction: column
  align-items: center
  justify-content: center
  width: 50%
  height: 400px
  font-family: 'Noto Sans JP', sans-serif
  font-size: 4em
  color: #FAFAFA
  
  @media(max-width: 470px)
    font-size: 2.5em

.quizz-answer
  opacity: 0
  
  &.revealed
    opacity: 1

.quizz-show-answer
  margin: 1em .7em
  padding: .6em 1.2em
  font-size: .8em
  color: #212121
  background: #ECEFF1
  border: none
  border-radius: .5em
  cursor: pointer

// Body
body
  background: var(--background)
              
            
!

JS

              
                interface Letter {
  name: string
  column: string
  row: string
  hiragana: string
  katakana: string
}

const createLetter = (name: string, column: string, row: string, hiragana: string, katakana: string, secondary = false): Letter => {
  return { name, column, row, hiragana, katakana, secondary }
}

const letters: Letter[] = [
  createLetter('A', '', 'a', 'あ', 'ア'),
  createLetter('I', '', 'i', 'い', 'イ'),
  createLetter('U', '', 'u', 'う', 'ウ'),
  createLetter('E', '', 'e', 'え', 'エ'),
  createLetter('O', '', 'o', 'お', 'オ'),
  
  createLetter('KA', 'k', 'a', 'か', 'カ'),
  createLetter('KI', 'k', 'i', 'き', 'キ'),
  createLetter('KU', 'k', 'u', 'く', 'ク'),
  createLetter('KE', 'k', 'e', 'け', 'ケ'),
  createLetter('KO', 'k', 'o', 'こ', 'コ'),
  
  createLetter('GA', 'g', 'a', 'が', 'ガ', true),
  createLetter('GI', 'g', 'i', 'ぎ', 'ギ', true),
  createLetter('GU', 'g', 'u', 'ぐ', 'グ', true),
  createLetter('GE', 'g', 'e', 'げ', 'ゲ', true),
  createLetter('GO', 'g', 'o', 'ご', 'ゴ', true),
  
  createLetter('SA', 's', 'a', 'さ', 'サ'),
  createLetter('SHI', 's', 'i', 'し', 'シ'),
  createLetter('SU', 's', 'u', 'す', 'ス'),
  createLetter('SE', 's', 'e', 'せ', 'セ'),
  createLetter('SO', 's', 'o', 'そ', 'ソ'),
  
  createLetter('ZA', 'z', 'a', 'ざ', 'ザ', true),
  createLetter('JI', 'z', 'i', 'じ', 'ジ', true),
  createLetter('ZU', 'z', 'u', 'ず', 'ズ', true),
  createLetter('ZE', 'z', 'e', 'ぜ', 'ゼ', true),
  createLetter('ZO', 'z', 'o', 'ぞ', 'ゾ', true),
  
  createLetter('TA', 't', 'a', 'た', 'タ'),
  createLetter('CHI', 't', 'i', 'ち', 'チ'),
  createLetter('TSU', 't', 'u', 'つ', 'ツ'),
  createLetter('TE', 't', 'e', 'て', 'テ'),
  createLetter('TO', 't', 'o', 'と', 'ト'),
  
  createLetter('DA', 'd', 'a', 'だ', 'ダ', true),
  createLetter('DJI', 'd', 'i', 'ぢ', 'ヂ', true),
  createLetter('DZU', 'd', 'u', 'づ', 'ヅ', true),
  createLetter('DE', 'd', 'e', 'で', 'デ', true),
  createLetter('DO', 'd', 'o', 'ど', 'ド', true),
  
  createLetter('NA', 'n', 'a', 'な', 'ナ'),
  createLetter('NI', 'n', 'i', 'に', 'ニ'),
  createLetter('NU', 'n', 'u', 'ぬ', 'ヌ'),
  createLetter('NE', 'n', 'e', 'ね', 'ネ'),
  createLetter('NO', 'n', 'o', 'の', 'ノ'),
  
  createLetter('HA', 'h', 'a', 'は', 'ハ'),
  createLetter('HI', 'h', 'i', 'ひ', 'ヒ'),
  createLetter('FU', 'h', 'u', 'ふ', 'フ'),
  createLetter('HE', 'h', 'e', 'へ', 'ヘ'),
  createLetter('HO', 'h', 'o', 'ほ', 'ホ'),
  
  createLetter('BA', 'b', 'a', 'ば', 'バ', true),
  createLetter('BI', 'b', 'i', 'び', 'ビ', true),
  createLetter('BU', 'b', 'u', 'ぶ', 'ブ', true),
  createLetter('BE', 'b', 'e', 'べ', 'ベ', true),
  createLetter('BO', 'b', 'o', 'ぼ', 'ボ', true),
  
  createLetter('PA', 'p', 'a', 'ぱ', 'パ', true),
  createLetter('PI', 'p', 'i', 'ぴ', 'ピ', true),
  createLetter('PU', 'p', 'u', 'ぷ', 'プ', true),
  createLetter('PE', 'p', 'e', 'ぺ', 'ペ', true),
  createLetter('PO', 'p', 'o', 'ぽ', 'ポ', true),
  
  createLetter('MA', 'm', 'a', 'ま', 'マ'),
  createLetter('MI', 'm', 'i', 'み', 'ミ'),
  createLetter('MU', 'm', 'u', 'む', 'ム'),
  createLetter('ME', 'm', 'e', 'め', 'メ'),
  createLetter('MO', 'm', 'o', 'も', 'モ'),
  
  createLetter('YA', 'y', 'a', 'や', 'ヤ'),
  createLetter('YU', 'y', 'u', 'ゆ', 'ユ'),
  createLetter('YO', 'y', 'o', 'よ', 'ヨ'),
  
  createLetter('RA', 'r', 'a', 'ら', 'ラ'),
  createLetter('RI', 'r', 'i', 'り', 'リ'),
  createLetter('RU', 'r', 'u', 'る', 'ル'),
  createLetter('RE', 'r', 'e', 'れ', 'レ'),
  createLetter('RO', 'r', 'o', 'ろ', 'ロ'),
  
  createLetter('WA', 'w', 'a', 'わ', 'ワ'),
  createLetter('WO', 'w', 'o', 'を', 'ヲ'),
  
  createLetter('N', '', '', 'ん', 'ン'),
]

const createLetterElement = (letter: Letter) => {
  const secondaryClass = (letter.secondary) ? ' secondary' : ''
  return (
    `<div
      class="letter${secondaryClass}"
      data-col="${letter.column}"
      data-row="${letter.row}"
      data-name="${letter.name}"
      style="grid-area: ${letter.name};">
      <span class="letter-hiragana">${letter.hiragana}</span>
      <span class="letter-katakana">${letter.katakana}</span>
      <span class="letter-name">${letter.name}</span>
    </div>`
  )
}

const lettersElements = letters.map(createLetterElement)

const domLetters = document.querySelector('.letters')

domLetters.innerHTML = lettersElements.join('')

// Controls
const toggleLettersCssClass = (cssClass) => {
  domLetters.classList.contains(cssClass) ?
    domLetters.classList.remove(cssClass) :
    domLetters.classList.add(cssClass)
}

const toggleSecondary = document.querySelector('.toggle-secondary')
const toggleSerif = document.querySelector('.toggle-serif')
const toggleKana = document.querySelector('.toggle-kana')

toggleSecondary.addEventListener('click', (evt) => {
 toggleLettersCssClass('hide-secondary')
})

toggleSerif.addEventListener('click', (evt) => {
 toggleLettersCssClass('serif')
})

toggleKana.addEventListener('click', (evt) => {
 toggleLettersCssClass('show-katakana')
})

// Search By Name
const findLetterByName = (name: string): Letter => {
  return letters.filter((letter: Letter) => {
    return letter.name.toLowerCase() === name.toLowerCase()
  })
}

const nameInput = document.querySelector('#name-input')
const nameSearch = document.querySelector('.name-search')

nameInput.addEventListener('input', (evt) => {
  const result = findLetterByName(nameInput.value)
  nameSearch.innerHTML = (result.length) ? `${result[0].hiragana} - ${result[0].katakana}` : ''
})

// Search By Hiragana
const findLetterByHiragana = (hiragana: string): Letter => {
  return letters.filter((letter: Letter) => {
    return letter.hiragana.toLowerCase() === hiragana.toLowerCase()
  })
}

const hiraganaInput = document.querySelector('#hiragana-input')
const hiraganaSearch = document.querySelector('.hiragana-search')

hiraganaInput.addEventListener('input', (evt) => {
  const result = findLetterByHiragana(hiraganaInput.value)
  hiraganaSearch.innerHTML = (result.length) ? `${result[0].name} - ${result[0].katakana}` : ''
})

// Search By Katakana
const findLetterByKatakana = (katakana: string): Letter => {
  return letters.filter((letter: Letter) => {
    return letter.katakana.toLowerCase() === katakana.toLowerCase()
  })
}

const katakanaInput = document.querySelector('#katakana-input')
const katakanaSearch = document.querySelector('.katakana-search')

katakanaInput.addEventListener('input', (evt) => {
  const result = findLetterByKatakana(katakanaInput.value)
  katakanaSearch.innerHTML = (result.length) ? `${result[0].name} - ${result[0].hiragana}` : ''
})

// Handle quizz popup display
const quizzContainer = document.querySelector('.quizz')
const showQuizzButton = document.querySelector('.show-quizz')
const closeQuizzButton = document.querySelector('.quizz .close')

showQuizzButton.addEventListener('click', (evt) => {
 quizzContainer.classList.add('active')
})

closeQuizzButton.addEventListener('click', (evt) => {
 quizzContainer.classList.remove('active')
})

// Handle quizz answer reveal
const quizzQuestion = document.querySelector('.quizz-question')
const quizzAnswer = document.querySelector('.quizz-answer')
const showQuizzAnswerButton = document.querySelector('.quizz-show-answer')

showQuizzAnswerButton.addEventListener('click', (evt) => {
 quizzAnswer.classList.add('revealed')
})

const hideQuizzAnswer = () => {
  quizzAnswer.classList.remove('revealed')
}


// Handle quizz content generation
const quizzHiraganaButton = document.querySelector('.quizz-hiragana')
const quizzKatakanaButton = document.querySelector('.quizz-katakana')
const quizzNameButton = document.querySelector('.quizz-name')

const getRandomLetter = (): Letter => {
  const randomIndex = Math.round(Math.random() * letters.length)
  return letters[randomIndex]
}

const changeQuizzContent = (questionProperty, answerProperty1, answerProperty2) => {
  hideQuizzAnswer()
  const letter: Letter = getRandomLetter()
  quizzQuestion.innerHTML = letter[questionProperty]
  quizzAnswer.innerHTML = `${letter[answerProperty1]} - ${letter[answerProperty2]}`
}

quizzHiraganaButton.addEventListener('click', (evt) => {
  changeQuizzContent('hiragana', 'name', 'katakana')
})

quizzKatakanaButton.addEventListener('click', (evt) => {
  changeQuizzContent('katakana', 'name', 'hiragana')
})

quizzNameButton.addEventListener('click', (evt) => {
  changeQuizzContent('name', 'hiragana', 'katakana')
})

              
            
!
999px

Console