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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" />
<article id="artboard" class="artboard" role="img" role="img" aria-labelledby="image-alt" aria-describedby="image-info">
<header>
<h1 id="image-alt">Apple | Magic Keyboard</h1>
<p id="image-info">
<address>
Created by
<a href="https://twitter.com/ricksdev">
Ricardo Ferreira
</a>
</address>
on
<time datetime="2023-03-14">March 14th, 2023</time>
</p>
</header>
<!-- HTML of the image -->
<div class="wall"></div>
<div class="grid-place">
<div class="placement">
<div id="keyboard" class="keyboard">
<div class="key-rows">
<div class="row"> <!-- top row -->
<div class="esc">
<span></span>
<span class="f15 lh-28">esc</span>
</div>
<div class="f1">
<span class="ico material-symbols-outlined">light_mode</span>
<span class="f8 lh-29">F1</span>
</div>
<div class="f2">
<span class="ico material-symbols-outlined">light_mode</span>
<span class="f8 lh-29">F2</span>
</div>
<div class="f3">
<span class="ico material-symbols-outlined">dashboard</span>
<span class="f8 lh-29">F3</span>
</div>
<div class="f4">
<span class="ico material-symbols-outlined">search</span>
<span class="f8 lh-29">F4</span>
</div>
<div class="f5">
<span class="ico material-symbols-outlined">mic</span>
<span class="f8 lh-29">F5</span>
</div>
<div class="f6">
<span class="ico material-symbols-outlined">clear_night</span>
<span class="f8 lh-29">F6</span>
</div>
<div class="f7">
<span class="ico material-symbols-outlined">fast_rewind</span>
<span class="f8 lh-29">F7</span>
</div>
<div class="f8">
<span class="ico material-symbols-outlined">skip_next</span>
<span class="f8 lh-29">F8</span>
</div>
<div class="f9">
<span class="ico material-symbols-outlined">fast_forward</span>
<span class="f8 lh-29">F9</span>
</div>
<div class="f10">
<span class="ico material-symbols-outlined">volume_mute</span>
<span class="f8 lh-29">F10</span>
</div>
<div class="f11">
<span class="ico material-symbols-outlined">volume_down</span>
<span class="f8 lh-29">F11</span>
</div>
<div class="f12">
<span class="ico material-symbols-outlined">volume_up</span>
<span class="f8 lh-29">F12</span>
</div>
<div class="lock">
<span class="ico material-symbols-outlined">lock</span>
</div>
</div>
<div class="row"> <!-- 2 row -->
<div>
<span class="f15 lh-28">±</span>
<span class="f13 lh-18 ss">§</span>
</div>
<div>
<span class="f15 lh-28">!</span>
<span class="f16 lh-21">1</span>
</div>
<div>
<span class="f25 lh-37">"</span>
<span class="f16 lh-21">2</span>
<span class="f13 lh-18">@</span>
</div>
<div>
<span class="f19 lh-29">#</span>
<span class="f16 lh-21">3</span>
<span class="f16 lh-21">€</span>
</div>
<div>
<span class="f19 lh-29">$</span>
<span class="f16 lh-21">4</span>
</div>
<div>
<span class="f19 lh-29">%</span>
<span class="f16 lh-21">5</span>
</div>
<div>
<span class="f19 lh-29">&</span>
<span class="f16 lh-21">6</span>
</div>
<div>
<span class="f19 lh-29">/</span>
<span class="f16 lh-21">7</span>
</div>
<div>
<span class="f17 lh-29">(</span>
<span class="f16 lh-21">8</span>
</div>
<div>
<span class="f17 lh-29">)</span>
<span class="f16 lh-21">9</span>
</div>
<div>
<span class="f17 lh-28">=</span>
<span class="f16 lh-21">0</span>
</div>
<div>
<span class="f15 lh-28">?</span>
<span class="f25 lh-37">'</span>
</div>
<div>
<span class="f18 lh-32">*</span>
<span class="f16 lh-21">+</span>
</div>
<div class="backspace">
<span class=""></span>
<span class="ico material-symbols-outlined">backspace</span>
</div>
</div>
<div class="row"> <!-- 3 row -->
<div class="tab">
<span class=""></span>
<span class="ico material-symbols-outlined">vertical_align_top</span>
</div>
<div class="s"><span>Q</span></div>
<div class="s"><span>W</span></div>
<div class="s"><span>E</span></div>
<div class="s"><span>R</span></div>
<div class="s"><span>T</span></div>
<div class="s"><span>Y</span></div>
<div class="s"><span>U</span></div>
<div class="s"><span>I</span></div>
<div class="s"><span>O</span></div>
<div class="s"><span>P</span></div>
<div>
<span class="f19 lh-36">ª</span>
<span class="f19 lh-27">º</span>
</div>
<div>
<span class="f32 lh-36">`</span>
<span class="f32 lh-27">´</span>
</div>
</div>
<div class="row"> <!-- 4 row -->
<div class="caps">
<span class=""></span>
<span class="ico material-symbols-outlined">keyboard_capslock</span>
</div>
<div class="s"><span>A</span></div>
<div class="s"><span>S</span></div>
<div class="s"><span>D</span></div>
<div class="s"><span>F</span></div>
<div class="s"><span>G</span></div>
<div class="s"><span>H</span></div>
<div class="s"><span>J</span></div>
<div class="s"><span>K</span></div>
<div class="s"><span>L</span></div>
<div class="s"><span>Ç</span></div>
<div>
<span class="f19 lh-36">^</span>
<span class="f17 lh-13">~</span>
</div>
<div>
<span class="f19 lh-29">|</span>
<span class="f19 lh-21">\</span>
</div>
</div>
<div class="row"> <!-- 5 row -->
<div class="lshift">
<span class=""></span>
<span class="ico material-symbols-outlined">shift</span>
</div>
<div>
<span class="f19 lh-28">></span>
<span class="f19 lh-20"><</span>
</div>
<div class="s"><span>z</span></div>
<div class="s"><span>X</span></div>
<div class="s"><span>C</span></div>
<div class="s"><span>V</span></div>
<div class="s"><span>B</span></div>
<div class="s"><span>N</span></div>
<div class="s"><span>M</span></div>
<div>
<span class="f19 lh-26">;</span>
<span class="f19 lh-18">,</span>
</div>
<div>
<span class="f19 lh-26">:</span>
<span class="f19 lh-18">.</span>
</div>
<div>
<span class="f22 lh-15">_</span>
<span class="f22 lh-20">-</span>
</div>
<div class="rshift">
<span class=""></span>
<span class="ico material-symbols-outlined">shift</span>
</div>
</div>
<div class="row"> <!-- bottom row -->
<div class="fn">
<span class="f12 lh-28 tx">fn</span>
<span class="ico material-symbols-outlined">language</span>
</div>
<div class="lcontrol">
<span class="ico material-symbols-outlined">expand_less</span>
<span class="f12 lh-28 tx">control</span>
</div>
<div class="loption">
<span class="ico material-symbols-outlined">keyboard_option_key</span>
<span class="f12 lh-28 tx">option</span>
</div>
<div class="lcommand">
<span class="ico material-symbols-outlined">keyboard_command_key</span>
<span class="f12 lh-28 tx">command</span>
</div>
<div class="space">
<span></span>
</div>
<div class="rcommand">
<span class="ico material-symbols-outlined">keyboard_command_key</span>
<span class="f12 lh-28 tx">command</span>
</div>
<div class="roption">
<span class="ico material-symbols-outlined">keyboard_option_key</span>
<span class="f12 lh-28 tx">option</span>
</div>
<div class="left">
<span class="ico material-symbols-outlined">arrow_left</span>
</div>
<div class="updown">
<span class="ico material-symbols-outlined">arrow_drop_up</span>
<span class="ico material-symbols-outlined">arrow_drop_down</span>
</div>
<div class="right">
<span class="ico material-symbols-outlined">arrow_right</span>
</div>
</div>
<div class="enter-position">
<div class="enter"></div>
<span class="ico material-symbols-outlined">keyboard_return</span>
</div>
</div>
</div>
</div>
</div>
</article>
*{
margin: 0;
}
header{
padding: 5%;
display: none;
h1{
margin-bottom: 3px;
}
}
/* Similar fonts for letters and icons */
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;1,700&display=swap');
*{
font-family: 'Roboto', sans-serif;
font-weight: 300;
color: #999;
}
.ico{
font-family: 'Material Symbols Outlined';
font-weight: normal;
font-style: normal;
text-align: center;
}
.artboard{
width: 100%;
height: 100%;
min-height: 100vh;
background: #fff;
position: relative;
display: block;
overflow: hidden;
.wall{
width:100%;
height:100%;
display: block;
position: absolute;
inset: 0;
background: linear-gradient(90deg, rgba(255,255,255,1) 9%, rgba(222,222,222,1) 34%, rgba(215,215,215,1) 49%, rgba(210,210,210,1) 68%, rgba(200,200,200,1) 100%);
opacity: 0.6;
&:before{
content:"";
width: 100%;
height: 100%;
display: block;
position: absolute;
background: radial-gradient(1000px 115% at 50% 80%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 90%);
}
&:after{
content:"";
width: 100%;
height: 100%;
display: block;
position: absolute;
background: radial-gradient(600px 115% at 35% 80%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 80%);
}
}
.grid-place{
display:flex;
position: relative;
width: 100%;
height: 100vh;
align-items: center;
flex-direction: column;
justify-content: center;
.placement{
display: flex;
width: 936px;
}
}
.keyboard{
width: 100%;
height: auto;
min-width: 936px;
background-color: #C2C3C5;
display: flex;
flex-direction: column;
border-top-right-radius: 3.35% 7.2%;
border-bottom-right-radius: 3.35% 7.2%;
border-bottom-left-radius: 3.35% 7.2%;
border-top-left-radius: 3.35% 7.2%;
box-shadow: 0px 0px 1px 1px #00000050, 2px 2px 1px 1px #00000050, 50px 10px 50px 20px #00000010;
.key-rows{
padding: 1.3% 1.12%;
display: flex;
flex-direction: column;
gap: 9px;
position:relative;
.row{
display: flex;
width: 100%;
gap: 1.13%;
div{
width: 5.85%;
aspect-ratio: 1/0.99;
border-radius: 9%;
background: linear-gradient(0deg, rgba(237,237,237,1) 0%, rgba(226,226,226,1) 100%);
box-shadow: 0px 0px 1.5px 1.5px #666;
position: relative;
> span:nth-child(1){
height:50%;
position: absolute;
top: 0;
width: 100%;
text-align:center;
}
> span:nth-child(2){
height:50%;
position: absolute;
top: 50%;
width: 100%;
text-align:center;
}
> span:nth-child(3){
height:50%;
position: absolute;
top: 50%;
width: 90%;
text-align:right;
}
@for $i from 8 through 25 {
.f#{$i} {
font-size: #{$i}px;
}
}
@for $i from 8 through 38 {
.lh-#{$i} {
line-height: #{$i}px;
}
}
.ico{
top: 4px;
position: relative;
}
&.esc{
width: 9.45%;
aspect-ratio: 1/0.62;
border-radius: 28%/48%;
border-top-right-radius: 10% 14%;
border-bottom-right-radius: 10% 14%;
border-bottom-left-radius: 10% 14%;
> span{
padding-left: 10%;
text-align: left;
font-size: 13px;
}
}
&.f1, &.f6{
.ico{
font-size: 15px;
line-height: 37px;
}
}
&.f4, &.f5{
.ico{
font-size: 16px;
line-height: 38px;
}
}
&.f2, &.f3, &.f7, &.f8, &.f9, &.f10, &.f11, &.f12{
.ico{
font-size: 18px;
line-height: 37px;
}
}
&.lock{
border-radius: 10% 14%;
border-top-right-radius: 35% 35%;
.ico{
font-size: 18px;
line-height: 55px;
}
}
&.backspace{
width: 9.2%;
aspect-ratio: 9/1;
border-top-left-radius: 4% 9%;
border-top-right-radius: 4% 9%;
border-bottom-right-radius: 4% 9%;
border-bottom-left-radius: 4% 9%;
span{
font-size: 19px;
line-height: 24px;
text-align: right;
width: 93%;
}
}
&.tab{
width: 9.4%;
aspect-ratio: 9.4/1;
span{
font-size: 18px;
line-height: 24px;
text-align: right;
width: 33%;
margin-top: -6px;
transform: rotate(90deg)
}
}
&.s{
span{
font-size: 20px;
line-height: 54px;
text-align:center;
}
}
&.caps{
width: 11%;
aspect-ratio: 2/1;
border-top-left-radius: 4% 9%;
border-top-right-radius: 4% 9%;
border-bottom-right-radius: 4% 9%;
border-bottom-left-radius: 4% 9%;
&:after{
content:"";
width: 2px;
height: 2px;
border-radius: 2px;
border: 1px solid #666;
display: block;
position: absolute;
top: 10px;
left: 10px;
}
span{
font-size: 25px;
line-height: 24px;
text-align: right;
width: 29%;
}
}
&.lshift{
width: 7.5%;
aspect-ratio: 2/1;
span{
font-size: 18px;
line-height: 24px;
text-align: right;
width: 38%;
}
}
&.rshift{
width: 14.6%;
aspect-ratio: 3/1;
border-top-left-radius: 3% 9%;
border-top-right-radius: 3% 9%;
border-bottom-right-radius: 3% 9%;
border-bottom-left-radius: 3% 9%;
span{
font-size: 18px;
line-height: 24px;
text-align: right;
width: 95%;
}
}
&.fn{
border-radius: 10% 14%;
border-bottom-left-radius: 35% 35%;
.tx{
text-align: right;
width: 84%;
}
.ico{
font-size: 17px;
line-height: 20px;
text-align: left;
padding-left: 14%;
}
}
&.lcontrol{
.tx{
text-align: right;
width: 84%;
}
.ico{
font-size: 22px;
line-height: 23px;
text-align: right;
width: 92%;
}
}
&.loption{
.tx{
text-align: right;
width: 84%;
}
.ico{
font-size: 20px;
line-height: 30px;
text-align: right;
width: 90%;
}
}
&.lcommand{
width: 7.6%;
aspect-ratio: 3/1;
.tx{
text-align: right;
width: 88%;
}
.ico{
font-size: 17px;
line-height: 30px;
text-align: right;
width: 91%;
}
}
&.space{
width: 33.7%;
aspect-ratio: 9/1;
border-top-left-radius: 1.3% 9%;
border-top-right-radius: 1.3% 9%;
border-bottom-right-radius: 1.3% 9%;
border-bottom-left-radius: 1.3% 9%;
}
&.rcommand{
width: 7.6%;
aspect-ratio: 3/1;
.tx{
text-align: right;
width: 88%;
}
.ico{
font-size: 17px;
line-height: 30px;
text-align: right;
width: 34%;
}
}
&.roption{
.tx{
text-align: right;
width: 78%;
}
.ico{
font-size: 20px;
line-height: 30px;
text-align: right;
width: 45%;
}
}
&.left{
.ico{
font-size: 20px;
line-height: 55px;
text-align: right;
width: 69%;
}
}
&.updown{
.ico{
font-size: 20px;
line-height: 28px;
text-align: center;
width: 100%;
overflow: hidden;
&:nth-child(1){
box-shadow: inset 0px -2px 2px #666
}
&:nth-child(2){
box-shadow: inset 0px 2px 2px #666;
}
}
}
&.right{
border-bottom-right-radius: 35% 35%;
.ico{
font-size: 20px;
line-height: 55px;
text-align: right;
width: 69%;
}
}
}
}
.enter-position{
position: absolute;
right: 7.55%;
top: 34%;
.enter{
display: block;
width: 68px;
height: 125px;
filter: drop-shadow(0px 0px 1.5px rgba(0, 0, 0, 1)) drop-shadow(0px 0px 1.5px rgba(0, 0, 0, 0.3));
position: absolute;
left: 0;
top: 0;
&:before {
content: "";
position: absolute;
display: block;
width: 371px;
height: 355px;
top: 0;
background: linear-gradient(0deg, rgba(237,237,237,1) 0%, rgba(226,226,226,1) 100%);
clip-path: path(
"m 5,10 c 0,0 -0.15205,-1.87544 1.58759,-3.61507 1.73964,-1.73964 3.68,-1.65252 3.68,-1.65252 h 45.08195 c 0,0 2.22583,-0.15171 3.84249,1.46494 1.61666,1.61666 1.46666,3.84421 1.46666,3.84421 v 105.15391 c 0,0 0.10488,2.47467 -1.2701,3.81466 -1.37498,1.33998 -3.79055,1.246 -3.79055,1.246 h -29.27781 c 0,0 -2.45427,0.003 -4.08794,-1.63112 -1.63366,-1.63366 -1.41309,-3.86992 -1.41309,-3.86992 v -53.27924 c 0,0 0.0344,-1.12283 -0.96343,-2.19788 -0.99773,-1.07506 -2.22845,-0.994 -2.22845,-0.994 h -8.56522 c 0,0 -1.38731,0.077 -2.65842,-1.2066 -1.27111,-1.28362 -1.20801,-2.65982 -1.20801,-2.65982 z");
}
}
.ico{
font-size: 20px;
line-height: 55px;
text-align: right;
position:absolute;
left: 34px;
top: 16px;
}
}
}
}
}
let outer = document.getElementById('keyboard'),
wrapper = document.getElementById('artboard'),
maxWidth = outer.clientWidth,
maxHeight = outer.clientHeight;
window.addEventListener("resize", resize);
resize();
function resize(){let scale,
width = window.innerWidth,
height = window.innerHeight,
isMax = width >= maxWidth && height >= maxHeight;
scale = Math.min(width/maxWidth, height/maxHeight);
outer.style.transform = isMax?'':'scale(' + (scale*0.95) + ')';
wrapper.style.width = isMax?'':maxWidth * (scale*0.95);
wrapper.style.height = isMax?'':maxHeight * (scale*0.95);
}
Also see: Tab Triggers