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.
//- source at https://github.com/bevacqua/untab
div.tv-tabs
label.tv-tab(for='tv-tab-1') Intro
label.tv-tab(for='tv-tab-2') Code
label.tv-tab(for='tv-tab-3') ?
input.tv-radio#tv-tab-1(name='tv-group', type='radio', checked)
div.tv-content
h1 Intro
p These are some awesome tabs!
ul
li No JavaScript
li 100% Healthy, Plain CSS
li Barely any hackery
li Kind of verbose, HTML-wise...
p
| Check out the
label.tv-link(for='tv-tab-2') source code
| !
input.tv-radio#tv-tab-2(name='tv-group', type='radio')
div.tv-content
h1 Code
p="Kind of verbose, here is the Jade source. Most JS libraries still ask for similar markup that's hardly any better, though."
h3 HTML (Jade) Code:
pre
code
| div.tv-tabs
| label.tv-tab(for='tv-tab-1') Tab Name!
| label.tv-tab(for='tv-tab-n') for attr equals the radio ids
|
| input.tv-radio#tv-tab-1(name='any-group-name', type='radio', checked)
| div.tv-content Content goes here!
|
| input.tv-radio#tv-tab-n(name='any-group-name', type='radio')
| div.tv-content More goes here!
h3 Relevant CSS (Stylus) Code:
pre
code
| .tv-content
| display none
|
| .tv-radio
| display none
|
| &:checked + .tv-content
| display block
p The trick is in the details.
ul
li Clicking on the labels is effectively the same as clicking on the input boxes
li The radio inputs are hidden with CSS
li When a radio is selected, their curious tab content neighbors show up
li="That's it! The only drawback is you won't be able to style the selected tab without resorting to some JS, but that shouldn't be a very big deal."
input.tv-radio#tv-tab-3(name='tv-group', type='radio')
div.tv-content
h1 ?
p Hey there!
ul
li
| I blog at
a(href='http://blog.ponyfoo.com') Pony Foo
li
| I tweet as
a(href='https://twitter.com/nzgb') @nzgb
li
| I push code to GitHub
a(href='https://github.com/bevacqua') @bevacqua
p
em Later...
.tv-content
display none
.tv-radio
display none
&:checked + .tv-content
display block
.tv-tab
display inline-block
cursor pointer
padding 8px
&:hover
opacity 0.9
// these styles used just for this presentation,
// but not required by the tab widget
// colors from flatuicolors.com
c_asphalt = #34495e
c_midnight = #2c3e50
c_clouds = #ecf0f1
c_wisteria = #8e44ad
c_greensea = #16a085
c_pumpkin = #d35400
c_sunflower = #f1c40f
body
margin 40px
font-family 'Georgia'
background-color #f3dc52
.tv-tabs
color c_clouds
:nth-child(odd)
background-color c_midnight
:nth-child(even)
background-color c_asphalt
.tv-content
padding 10px
max-width 600px
#tv-tab-1 + .tv-content
background-color c_wisteria
color c_clouds
#tv-tab-2 + .tv-content
background-color c_greensea
color c_clouds
#tv-tab-3 + .tv-content
background-color c_pumpkin
color c_clouds
a, .tv-link
display inline-block
padding 2px
color c_sunflower
background-color rgba(#fff, 0.2)
box-shadow 1px 1px 5px rgba(#fff, 0.2)
transition all 0.4s ease-in-out
&:hover
background-color transparent
box-shadow none
ul
list-style-type binary
pre
display block
overflow hidden
padding 8px
background-color rgba(#000, 0.2)
code
display block
margin-top -10px
margin-left -40px
Also see: Tab Triggers