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.
<h1>HTML, CSS, Forms - A Test</h1>
<p>When using <code>::placeholder</code> in connection with the attribute of the same name (<code>placeholder="your text"</code>) being put in an input field, we can tell our users what or how they should fill an input field in our precious webforms.</p>
<p>On top of that we love to tell people which fields they <strong>have to</strong> fill out in order to be able to submit said webform to us. Therefore we got the <code>:required</code> pseudo-class to style form elements which we deem important – you sure want to write <em>required</em> into the input then for the styling to take effect. <code><input required /></code> will do by the way, as it is a boolean and therefore it defaults to <em>true</em> when it's there.</p>
<p>I think I found a nice way to combine both the pesudo-element with the pseudo-class in order to give people a hint on required fields.</p>
<p><strong>Notice:</strong> <a href="http://caniuse.com/#feat=form-validation">Browser Support</a> is an issue when it comes to IE. <em class="spoken">"&#$§¥ you IE!."</em> Anything lower than IE10 won't understand those selectors. <em>*shakes fist towards the sky*</em></p>
<p>Enough with the chatter, here we go with the example form:</p>
<hr />
<form class="myform" action="" method="post" name="bestformeva">
<fieldset>
<legend>Please tell me a few things about you! Required fields are marked with a blue border.</legend>
<label for="name">First, I need your full name.</label>
<input type="text" id="name" name="name" required placeholder="Your Name"/>
<label for="street">It's optional but if you wanted to be very accurate, you may enter your street address here. Otherwise you can also skip this field.</label>
<input type="text" id="street" name="street" placeholder="Optional: Street Address" />
<label for="city">Now, I do need to know which city you live in.</label>
<input type="text" id="city" name="city" required placeholder="Name the city you live in" />
<label for="zip">Please provide the zip-code for your city. This field accepts only numbers.</label>
<input type="number" id="zip" name="zip" required placeholder="ZIP Code. Numbers only" />
<label for="email">Now, please tell me your email address so I can get back to you when needed.</label>
<input type="email" id="email" name="email" placeholder="[email protected]" required />
<label for="textarea">If there is anything else you want to tell me, hack away on your keyboard like there's no tomorrow after focussing the following textarea. Maximum characters is 4000.</label>
<textarea id="textarea" name="textarea" placeholder="This empty textarea is valid, as it is not required to fill it with text in order to submit the form."></textarea>
<label for="submit">You may now submit your form by hitting the button below.</label>
<button id="submit" type="submit" name="submit">Submit</button>
</fieldset>
</form>
<hr />
<p>Interestingly enough the placeholder text for <code><input type="number" /></code> does not change its color although the field is set to required in the HTML. The border color though did change.</p>
<h2>Update:</h2>
<p>Now, that I added the <code>:valid</code> and <code>:invalid</code> selectors to the CSS, there's another funky thing going on. The <code><number></code> input is now marked as invalid although it's empty (apart from the placeholder, which now received the color I set for invalid input values). <strong>STRRRRAAAAANNNGE!</strong></p>
<p>Apart from that you would have to know Regular Expressions in order to prevent the <code>type="text"</code> inputs to take any character. You'd want to prevent people from using numbers for their name, right? <small>There might be a use-case for this (numbers in names that is) but I honestly don't know, so I'd go the way of not preventing the user from typing whatever he thinks his name really is. <em>- Yours Batman1982-0H-Y34H</em></small></p>
<p><strong>Interesting find:</strong> When setting the submit button styles related to the form being valid or invalid you can give users visible feedback on whether they can submit the form or not.</p>
/*
Let's say Firefox has issues, okay?
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/*
As little styling as we need
*/
body {
font-family: sans-serif;
font-size: 1.25em;
line-height: 1.55;
padding: 1.618em 5%;
max-width: 900px;
margin: 0 auto;
}
code {
font-family: Consolas, Monaco, "Courier New", Courier, monospace;
background: #f0f0f0;
font-size: .875em;
color: #333;
padding: .25em;
}
.spoken {
font-family: "Comic Sans MS";
text-align: center;
float: right;
padding: 2em;
margin: 1em 0 1em 1em;
background: #ffa;
border: .3125em solid #333;
border-radius: 50% 75%;
width: 300px;
transform: rotate(-15deg);
}
hr {
border: 0;
height: .08em;
background: #ebc533;
margin: 2em
}
small {
font-size: .75em;
display: block;
margin: .5em 0;
}
small em {
color: #595959;
}
/*
The actual form - finally
*/
form {
margin: 2em 0;
}
fieldset {
margin: 0 0 2em;
}
legend {
font-weight: bold;
padding: 0 .5em;
}
label {
display: block;
margin: 1em 0 0;
cursor: pointer;
color: #595959;
}
input,
textarea {
border: .125em solid #e5e5e5;
padding: .5em;
}
textarea {
box-sizing: border-box;
resize: vertical;
width: 50%;
height: 8em;
}
input:not(:focus):valid,
textarea:not(:focus):valid{
border-color: green;
color: green;
}
input:not(:focus):invalid,
textarea:not(:focus):invalid {
border-color: red;
color: red;
}
input:required,
textarea:required {
border-color: darkblue;
}
::placeholder {
color: #777;
}
input:required::placeholder,
textarea:required::placeholder{
color: orange;
opacity: 1;
}
button {
color: darkblue;
border: 2px solid darkblue;
padding: .309em .618em;
}
form:valid button {
color: green;
border-color: green;
}
form:invalid button {
color: red;
border-color: red;
}
Also see: Tab Triggers