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>Styling Forms</h1>
<h2>If <code>[type=textish]</code>, <code>[type=buttonish]</code>, & <code>[type=togglable]</code> Existed in CSS</h2>
<!--
HTML has a lot of great input types, but it's hard to style all of them the way you want without accidentally styling other things. The dozen input types, checkboxes, radio buttons, select boxes, textareas - all of these elements really only fall three 'categories' of input that we can grab and style accordingly:
- textish
- buttonish
- togglable
So why can't we style all things that look like <input type=text> with something like: input[type=textish]?
This is my experiment to see if there are more effective ways of selecting input elements to style them.
I created a list of selectors we want to target in JavaScript, and then used EQCSS to allow us to use that variable name in our CSS and insert the entire list of selectors. This also allows us to write functions that alter how that list of selectors is returned to us, so we can easily add :hover, :focus, :active and other modifications to our selectors fairly easily.
-->
<!-- Text-like -->
<input type=hidden placeholder=hidden>
<input type=text placeholder=text>
<input type=search placeholder=search>
<input type=tel placeholder=tel>
<input type=url placeholder=url>
<input type=email placeholder=email>
<input type=password placeholder=password>
<input type=date placeholder=date>
<input type=month placeholder=month>
<input type=week placeholder=week>
<input type=time placeholder=time>
<input type=datetime-local placeholder=datetime-local>
<input type=number placeholder=number>
<input type=range placeholder=range>
<input type=color placeholder=color>
<textarea>textarea</textarea>
<!-- Toggle-like -->
<input type=checkbox value=checkbox>
<input type=checkbox value=checkbox>
<input type=checkbox value=checkbox>
<input type=radio name=radio value=radio>
<input type=radio name=radio value=radio>
<input type=radio name=radio value=radio>
<!-- Button-like-->
<input type=file value=file>
<input type=submit value=submit>
<input type=reset value=reset>
<input type=button value=button>
<button>real button</button>
<select>
<option>option</option>
<option>option</option>
<option>option</option>
</select>
@element input, textarea, select, button {
/* set width for most inputs */
eval('textish'),
[type=range],
[type=file],
textarea,
select {
display: block;
width: 100%;
}
/* Give default style to text inputs and buttons */
eval('textish'),
eval('buttonish'),
eval('togglable'),
select {
-webkit-appearance: none;
appearance: none;
padding: .5em;
min-height: 2em;
margin: .5em 0;
color: #555;
background-color: white;
border: 1px solid rgba(0,0,0,.3);
border-radius: 0;
line-height: 1;
font-size: 12pt;
font-weight: 400;
font-family: 'Source Sans', sans-serif;
}
/* Set border radius on buttons and select */
eval('buttonish'),
select {
min-height: 0;
border-radius: 3px;
cursor: pointer;
}
/* enhance button styles */
eval('buttonish') {
background-color: transparent;
}
/* size togglable inputs */
eval('togglable') {
min-height: 1em;
display: inline-block;
cursor: pointer;
}
[type=radio] {
border-radius: 100%;
}
eval('action("checked",togglable)') {
background-color: #999;
box-shadow: inset white 0 1px 0,
inset white 1px 0 0,
inset white -1px 0 0,
inset white 0 -1px 0;
}
/* add min-height to textarea */
textarea {
min-height: 5em;
}
/* enhance select */
select {
padding-right: 1.5em;
text-indent: 0.01px;
text-overflow: '';
background-repeat: no-repeat;
background-position: calc(100% - .5em) 50%;
background-size: 12px;
background-image: url("data:image/svg+xml;charset=utf8, %3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E %3Cpolygon opacity='0.6' points='0,4 16,4 8,12'/%3E %3C/svg%3E ");
}
select::-ms-expand {
display: none;
}
/* input & select hover styles */
eval("action('hover',textish)"),
eval("action('hover',togglable)"),
select:hover {
border: 1px solid gold;
}
/* input & select focus styles */
eval("action('focus',textish)"),
select:focus {
background-color: lightyellow;
}
/* button hover styles */
eval("action('hover',buttonish)") {
color: white;
background-color: #999;
}
/* button focus styles */
eval("action('active',buttonish)") {
color: white;
background-color: #555;
}
/* fix type=search padding */
[type=search] {
padding-right: 0;
}
}
/* selector lists */
var textish = [
'[type=text]', '[type=search]', '[type=tel]', '[type=url]', '[type=email]', '[type=password]', '[type=date]', '[type=month]', '[type=week]', '[type=time]', '[type=datetime-local]', '[type=number]', '[type=color]', 'textarea'
]
var togglable = [
'[type=checkbox]', '[type=radio]'
]
var buttonish = [
'[type=submit]', '[type=reset]', '[type=button]', 'button'
]
/* return selectors with :states using action('state',arrayName) */
function action(state,array){
var selectors ='';
for(i=0;i<array.length;i++){
selectors += array[i]+':'+state
if (i<array.length-1) {
selectors += ', '
}
}
return selectors
}
Also see: Tab Triggers