HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
@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)
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')
})
Also see: Tab Triggers