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.
<div class="responsive-container">
<div class="device">
<div class="display">
<div class="glass">
<div class="viewport"></div>
</div>
</div>
</div>
<p class="instructions">Resize the window to view the responsive transformations</p>
</div>
$bp-sm: 480px;
$bp-md: 768px;
$bp-lg: 1024px;
$tr-duration: 550ms;
$tr-easing: cubic-bezier(0.68, -0.55, 0.265, 1.55);
@function tr($property) {
@return #{$property} #{$tr-duration} #{$tr-easing};
}
* {
box-sizing: border-box;
}
html, body {
height: 100%;
overflow: hidden;
}
body {
font-family: 'Dosis', sans-serif;
font-weight: 500;
background-color: #4a24a2;
background-image: radial-gradient(circle at 50% 40%, rgba(#fff, 0.225), transparent 400px);
}
.device {
position: absolute;
top: 50%;
left: 50%;
transition: tr(all);
transform: translate(-50%,-50%) rotate(-90deg);
@media (min-width: $bp-sm) {
transform: translate(-50%,-50%) rotate(0deg);
}
@media (min-width: $bp-lg) {
padding: 0 40px 5px;
}
&::before, &::after {
content: '';
position: absolute;
transition: tr(all);
}
&::before {
top: 10px;
left: 50%;
width: 5px;
height: 5px;
border-radius: 100%;
background-color: rgba(#fff, 0.25);
transform: scale(0) translateX(-50%);
z-index: 1;
@media (min-width: $bp-lg) {
transform: scale(1) translateX(-50%);
}
}
&::after {
bottom: 0;
left: 30px;
right: 30px;
height: 0;
z-index: 1;
border-radius: 4px 4px 20px 20px;
background-color: #757575;
background-repeat: no-repeat;
background-size: 100px 6px, auto auto;
background-position: top center, top center;
background-image:
linear-gradient(to bottom, rgba(#000, 0.2) 50%, rgba(#000, 0.05) 100%),
linear-gradient(to bottom, rgba(#000, 0.2) 10%, transparent 15%, rgba(#000, 0.1) 68%, rgba(#000, 0.275) 73%);
box-shadow: 0px 3px 5px 3px transparent;
@media (min-width: $bp-lg) {
height: 17px;
left: 0;
right: 0;
opacity: 1;
box-shadow: 0px 10px 10px -5px rgba(black, 0.3);
}
}
}
.display {
display: flex;
align-items: stretch;
overflow: hidden;
width: 255px;
height: 128px;
border: 2px solid #383838;
border-radius: 18px;
box-shadow: -3px 0px 5px 3px rgba(black, 0.2);
transition: tr(all);
@media (min-width: $bp-sm) {
box-shadow: 0px 3px 5px 3px rgba(black, 0.2);
}
@media (min-width: $bp-md) {
width: 440px;
height: 340px;
}
@media (min-width: $bp-lg) {
width: 520px;
height: 370px;
}
}
.glass {
position: relative;
flex: 1 1 auto;
display: flex;
align-items: stretch;
background-color: #000;
padding: 7px 20px 7px 25px;
transition: tr(padding);
@media (min-width: $bp-md) {
padding: 15px 25px 15px 30px;
}
@media (min-width: $bp-lg) {
padding: 20px 10px;
}
&::before, &::after {
content: '';
position: absolute;
z-index: 1;
}
&::before {
top: -125%;
right: 0;
bottom: -125%;
left: -30%;
transform-origin: 100% 50%;
background-image:
linear-gradient(to left,
transparent 10%,
rgba(white, 0.3) 10%,
rgba(white, 0.4) 15%,
transparent 15%,
transparent 20%,
rgba(white, 0.3) 20%,
rgba(white, 0.4) 25%,
transparent 25%
),
linear-gradient(to left,
rgba(black, 0.0) 0%,
rgba(black, 0.6) 100%
);
transform: translate(0%,#{(100% / 6)}) rotate(45deg);
transition: tr(transform);
@media (min-width: $bp-sm) {
transform: translate(0%,#{(-100% / 6)}) rotate(-45deg);
}
}
&::after {
top: 40px;
bottom: 40px;
left: 5px;
right: 7px;
border-radius: 3px;
background-image:
linear-gradient(to left, #333 0%, #000 3px, transparent 3px),
radial-gradient(circle at 8px, transparent 6px, #333 6px, #333 8px, transparent 8px);
transition: tr(all);
@media (min-width: $bp-md) {
top: 100px;
bottom: 100px;
right: 10px;
left: 7px;
}
@media (min-width: $bp-lg) {
right: -5px;
left: -20px;
}
}
}
.viewport {
position: relative;
z-index: 0;
flex: 1 1 auto;
background-color: #fff;
overflow: hidden;
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 200%;
transform-origin: top right;
transform: rotate(90deg) translateX(110px);
transition: background-size 0ms #{$tr-duration / 2}, transform 0ms #{$tr-duration / 2};
background-repeat:
no-repeat,
no-repeat,
no-repeat,
no-repeat,
no-repeat,
repeat-y,
repeat-y;
background-image:
linear-gradient(to bottom, transparent, white),
radial-gradient(circle at center, yellow 10px, transparent 10px),
linear-gradient(to bottom left, #a3e2f5 45%, transparent 45%),
linear-gradient(to bottom right, #a3e2f5 35%, #64b46b 35%),
linear-gradient(to bottom, white, white),
linear-gradient(to bottom, #ddd 5px, transparent 5px, transparent 10px, #ddd 10px, #ddd 15px, transparent 15px, transparent 20px, #ddd 20px, #ddd 25px, transparent 25px),
linear-gradient(to bottom, transparent 30px, #ddd 30px, #ddd 35px, transparent 35px);
background-size:
100% 30px,
20px 20px,
90px 90px,
90px 90px,
100px 100px,
calc(90px) 50px,
calc(50px) 50px;
background-position:
bottom left,
right 22px top 23px,
right 10px top 10px,
right 10px top 10px,
right 10px top 10px,
right 10px top 10px,
right 50px top 10px;
@media (min-width: $bp-sm) {
background-size:
100% 30px,
20px 20px,
90px 90px,
90px 90px,
100px 100px,
calc(100% - 20px) 50px,
calc(100% - 60px) 50px;
transform: rotate(0deg) translateX(0px);
}
}
}
.instructions {
position: absolute;
top: 50%;
left: 50%;
width: 290px;
z-index: -1;
font-size: 1.5rem;
text-align: center;
color: rgba(white, 0.3);
transform: translate(-50%, 150px);
transition: tr(transform), tr(opacity);
@media (min-width: $bp-sm) {
transform: translate(-50%, 80px);
}
@media (min-width: $bp-md) {
transform: translate(-50%, 180px);
}
@media (min-width: $bp-lg) {
transform: translate(-50%, 200px);
}
}
Also see: Tab Triggers