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.
<form action="#login" class="Form">
<h1 class="Form-title">Login</h1>
<p class="Form-description">This form will allow you to login and validate with HTML5 + CSS.</p>
<div class="Form-fields">
<input type="email"
id="email"
class="ControlInput ControlInput--email"
placeholder=" "
required
>
<label for="email"
class="Control-label Control-label--email"
>Email</label>
<div class="Control-requirements Control-requirements--email">
Must be a valid email
</div>
<!-- this is here to give power to the :checked css selector -->
<input type="checkbox"
id="show-password"
class="show-password"
>
<label for="show-password"
class="Control-label Control-label--showPassword"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="32" height="32" class="svg-toggle-password" title="Toggle Password Security">
<title>Hide/Show Password</title>
<path d="M24,9A23.654,23.654,0,0,0,2,24a23.633,23.633,0,0,0,44,0A23.643,23.643,0,0,0,24,9Zm0,25A10,10,0,1,1,34,24,10,10,0,0,1,24,34Zm0-16a6,6,0,1,0,6,6A6,6,0,0,0,24,18Z"/>
<rect x="20.133" y="2.117" height="44" transform="translate(23.536 -8.587) rotate(45)" class="closed-eye"/>
<rect x="22" y="3.984" width="4" height="44" transform="translate(25.403 -9.36) rotate(45)" style="fill:#fff" class="closed-eye"/>
</svg>
</label>
<input type="text"
id="password"
placeholder=" "
autocomplete="off"
autocapitalize="off"
autocorrect="off"
required
pattern=".{6,}"
class="ControlInput ControlInput--password"
>
<label for="password"
class="Control-label Control-label--password"
>Password</label>
<div class="Control-requirements">
Must contain at least 6 characters. We did this for your own sake.
</div>
<button type="submit" class="Button Form-submit">
Login
<svg width='26px' height='26px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="Button-spinner">
<rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
<circle cx="50" cy="50" r="40" stroke="#fff" fill="none" stroke-width="18" stroke-linecap="round"></circle>
<circle cx="50" cy="50" r="40" stroke="#e7542b" fill="none" stroke-width="9" stroke-linecap="round" class="spinner"></circle>
</svg>
</button>
</div>
</form>
.Form {
width: 100%;
max-width: 400px;
margin: auto;
}
.Form-title {
color: #00386a;
margin: 0 0 15px;
}
.Form-description {
color: rgba(#6d6665, 50%) ;
}
.Form-fields {
border-radius: 15px;
border: 1px solid #c5c1c0;
background-color: #fff;
display: flex;
flex-direction: column;
padding: 24px 15px;
}
.Control-label {
color: #423e3d;
font-weight: bold;
transition: color 300ms ease;
}
.Control-requirements {
// display: none;
background: pink;
border-top: none;
margin: -14px 0 15px;
max-height: 0;
overflow: hidden;
transition: all 200ms ease;
padding: 0 9px;
}
.ControlInput {
border-radius: 3px;
box-shadow: 0 1px 3px rgba(#c5c1c0, 0%) inset;
color: #6d6665;
margin: 0.8em 0;
border: 1px solid #c5c1c0;
padding: 0.6em 0.6em;
transition: box-shadow 300ms ease-out;
&:hover {
box-shadow: 0 1px 3px rgba(#c5c1c0, 40%) inset;
}
&:focus {
outline: #2bbee7 auto 3px;
}
// only show the invalid input if we aren't focusing on the element
// and there is no placeholder
&:invalid:not(:focus):not(:placeholder-shown) {
border-color: red;
border-bottom: none;
// box-shadow: 0 1px 3px rgba(#f00, 3%) inset;
& + .Control-label {
color: red;
& + .Control-requirements {
// display: block;
max-height: 100px;
padding: 9px;
border: 1px solid red;
}
}
}
&:valid:not(:focus):not(:placeholder-shown) {
border-color: #5fa550;
& + .Control-label {
color: #5fa550;
}
}
}
.Control-requirements--email,
.ControlInput--email {
order: -1;
}
.Control-label--email {
order: -2;
}
.ControlInput--password {
order: 0;
padding-right: 50px;
}
.Control-label--password {
order: -1;
margin-bottom: -32px; // pull up the offset of the hide password button
}
.Control-label--showPassword {
width: 32px;
position: relative;
top: 52px;
left: 100%;
text-align: right;
margin-left: -36px;
}
.Form-submit {
border: 1px solid #e7542b;
background-color: #e7542b;
border-radius: 3px;
color: #fff;
display: block;
width: 100%;
max-width: 100%;
pointer-events: none;
opacity: 0.6;
cursor: default;
transition: opacity 300ms ease-out, max-width 150ms ease-out;
outline: none;
position: relative;
margin: auto;
&:hover {
background-color: darken(#e7542b, 10%);
}
&:active {
background-color: darken(#e7542b, 20%);
max-width: 50px;
overflow: hidden;
text-indent: 300px;
.Button-spinner {
opacity: 1;
}
}
.ControlInput--email:valid ~ .ControlInput--password:valid ~ & {
cursor: pointer;
pointer-events: auto;
opacity: 1;
}
}
//SVG
.Button-spinner {
position: absolute;
top: 50%;
left: 50%;
margin-left: -13px;
margin-top: -13px;
opacity: 0;
}
// show password checkbox hack
.show-password {
display: none;
&:checked {
// background: purple;
& ~ .ControlInput--password {
text-security: disc;
-webkit-text-security: disc;
-moz-text-security: disc; // doesn't work :'|
}
& ~ .Control-label--showPassword {
.svg-toggle-password {
.closed-eye {
opacity: 1;
transition: opacity 300ms ease, height 400ms ease;
width: 4px;
height: 44px;
}
}
}
}
}
// default eye position
.svg-toggle-password {
fill: rgba(#008ed6, 50%);
.closed-eye {
opacity: 0;
height: 0;
}
}
.Button {
padding: 10px;
user-select: none;
}
.spinner {
animation: dash 2s linear infinite;
animation-direction: normal;
}
@keyframes dash {
0% {
stroke-dashoffset: 0;
stroke-dasharray: 150.6 100.4;
}
50% {
stroke-dasharray: 1 250;
}
100% {
stroke-dashoffset: 502;
stroke-dasharray: 150.6 100.4;
}
}
@keyframes spinner-in {
0% {
opacity: 0;
}
20%, 80% {
opacity: 1;
}
100% {
opacity: 0;
}
}
html {
box-sizing: border-box;
height: 100%;
}
body {
background-color: #f1f2f1;
background-image: linear-gradient(#e7e8e7, #f1f2f1);
display: flex;
min-height: 100%;
}
*, *:before, *:after {
box-sizing: inherit;
}
// CSS Only Concept.
// Please note I wouldn't call this "production" code use at your own risk.
//
// A few sibling selectors + checkbox hacks + a CSS property `text-security: disc;` I didn't previously know about
//
// Note the password secruit
//
//https://css-tricks.com/form-validation-ux-html-css/
Also see: Tab Triggers