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 URL's 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 it's URL and the proper URL extention.
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.
<div class="container">
<form id="theform" action="javascript:void(0);">
<label for="about-yourself">About yourself:</label>
<div class="ta-container">
<textarea id="about-yourself" class="ta" name="about-yourself" rows="6" cols="75" data-maxchars="20" data-over="false" placeholder="Enter text here..." required></textarea>
<div class="status-bar">
<table>
<tr><td>Characters:</td><td class="charcount"></td></tr>
<tr><td class="remaining-label">Remaining:</td><td class="remaining"></td></tr>
</table>
</div>
</div>
<label for="your-proposal">Your proposal:</label>
<div class="ta-container">
<textarea id="your-proposal" class="ta" name="your-proposal" rows="6" cols="75" data-maxchars="25" data-over="false" placeholder="Enter text here..." required></textarea>
<div class="status-bar">
<table>
<tr><td>Characters:</td><td class="charcount"></td></tr>
<tr><td class="remaining-label">Remaining:</td><td class="remaining"></td></tr>
</table>
</div>
</div>
<label for="supporting-info">Supporting information:</label>
<div class="ta-container">
<textarea id="supporting-info" class="ta" name="supporting-info" rows="6" cols="75" data-maxchars="40" data-over="false" placeholder="Enter text here..." required></textarea>
<div class="status-bar">
<table>
<tr><td>Characters:</td><td class="charcount"></td></tr>
<tr><td class="remaining-label">Remaining:</td><td class="remaining"></td></tr>
</table>
</div>
</div>
<input id="submitbtn" type="submit" value="Submit">
</form>
</div>
/* Import Google Font */
@import url(https://fonts.googleapis.com/css?family=Nunito+Sans);
/* RESET */
* {
padding: 0;
margin: 0;
font-size: 1em;
box-sizing: border-box;
font-family: 'Nunito Sans';
color: hsl(0, 0%, 50%);
}
/* Containing areas */
.container {
width: 600px;
margin: 1em auto;
}
.ta-container {
width: 100%;
border: 1px solid hsl(0, 0%, 70%);
border-radius: 0.25em;
margin: 0.25em 0 1.5em;
}
.hasfocus {
box-shadow: 0px 0px 6px hsl(210, 50%, 60%);
}
/* The textarea itself */
textarea {
padding: 0.25em;
width: 100%;
max-width: 100%;
border: none;
vertical-align:bottom;
color: hsl(0, 0%, 50%);
border-radius: 0.25em;
outline: none;
}
/* The status bar */
.status-bar {
background: hsl(0, 0%, 90%);
padding: 0.25em;
text-align: right;
font-family: sans-serif;
font-size: 0.7em;
width: 100%;
color: hsl(0, 0%, 50%);
border-radius: 0 0 0.25em 0.25em;
}
table {
width: auto;
margin-left: auto;
line-height: 1em;
}
.charcount, .remaining {
font-weight: bold;
}
.over {
color: hsl(0, 80%, 60%);
}
/* The submit button */
#submitbtn {
padding: 0.4em 1.2em;
background: hsl(0, 0%, 100%);
border: 1px solid hsl(0, 0%, 60%);
color: hsl(0, 0%, 50%);
border-radius: 0.25em;
}
#submitbtn:enabled:hover {
background: hsl(0, 0%, 90%);
}
#submitbtn:enabled:active {
background: hsl(0, 0%, 30%);
color: hsl(0, 0%, 90%)
}
#submitbtn:disabled {
border: 1px solid hsl(0, 0%, 90%);
color: hsl(0, 0%, 90%);
}
/**
* Functions to add/remove class on div.ta-container to emulate focus removed from textarea by CSS line 37 (outline:none)
*/
function setFocus(ta_container) {
ta_container.classList.add('hasfocus')
}
function removeFocus(ta_container) {
ta_container.classList.remove('hasfocus')
}
/**
* Function to enable or disable #submitbtn
* #submitbtn will be disabled if any of the textareas have data-over set
* to true due to exceeding the value specified in data-maxchars
*/
function setSubmitBtn() {
var tas = theform.querySelectorAll('.ta')
var disabled = false
tas.forEach(function(ta) {
if (ta.getAttribute('data-over') == 'true') {
disabled = true
}
})
if (disabled) {
theform.querySelector('#submitbtn').disabled = true
} else {
theform.querySelector('#submitbtn').disabled = false
}
}
/**
* Function to count the characters in .ta and update .ta_container.statusbar
* @param {Obj} ta_container - the .ta-container element
* @param {Obj} ta - the .ta textarea element
* @param {Integer} maxLength - the max number of characters allowed in the .ta textarea element
*/
function countChars(ta_container, ta, maxLength) {
var numChars = ta.value.length
ta_container.querySelector('.charcount').innerHTML = numChars + '/' + maxLength
ta_container.querySelector('.remaining').innerHTML = Math.abs( maxLength - numChars )
if ( numChars > maxLength ) {
ta_container.querySelector('.remaining-label').classList.add( 'over' )
ta_container.querySelector('.remaining-label').innerHTML = 'Over by:'
ta_container.querySelector('.remaining').classList.add( 'over' )
ta.style.color = 'hsl(0, 80%, 60%)'
ta.setAttribute('data-over', 'true')
setSubmitBtn()
} else {
ta_container.querySelector('.remaining-label').classList.remove( 'over' )
ta_container.querySelector('.remaining-label').innerHTML = 'Remaining:'
ta_container.querySelector('.remaining').classList.remove( 'over' )
ta.style.color = 'hsl(0, 0%, 50%)'
ta.setAttribute('data-over', 'false')
setSubmitBtn()
}
}
/**
* Initialisation function
*/
function initialise() {
var ta_containers = theform.querySelectorAll('.ta-container')
ta_containers.forEach( function(ta_container) {
var ta = ta_container.querySelector('.ta')
var maxLength = ta.getAttribute('data-maxchars')
var numChars = ta.value.length
ta_container.querySelector('.charcount').innerHTML = numChars + '/' + maxLength
ta_container.querySelector('.remaining').innerHTML = maxLength - numChars
ta.addEventListener( 'input', function() {
countChars(ta_container, ta, maxLength)
})
ta.addEventListener( 'focus', function(){
setFocus(ta_container)
})
ta.addEventListener( 'blur', function(){
removeFocus(ta_container)
})
})
}
/* Let's go! */
initialise()
Also see: Tab Triggers