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.
//- To see the process of how I made this dark mode toggle, watch this tutorial video:
//- https://youtu.be/42gltu11wb8
//- It explains choosing dark mode colors, how to set up the CSS in SASS, creating the transition effect in CSS and making the dark mode persistent across pages and refreshes.
header.masthead
.masthead-inner
h1.logo Logo
nav.nav
ul
li
button.dark-button Dark <i class="zmdi zmdi-brightness-2 zmdi-hc-fw"></i>
li
button.light-button(hidden) Light <i class="zmdi zmdi-sun zmdi-hc-fw"></i>
main
h2 Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus, non.
img(src="https://source.unsplash.com/1600x900?Chicago")
p Marley was dead: to begin with. There is no doubt whatever about that. The register of his burial was signed by the clergyman, the clerk, the undertaker, and the chief mourner. Scrooge signed it: and Scrooge’s name was good upon ’Change, for anything he chose to put his hand to. Old Marley was as dead as a door-nail.
p Mind! I don’t mean to say that I know, of my own knowledge, what there is particularly dead about a door-nail. I might have been inclined, myself, to regard a coffin-nail as the deadest piece of ironmongery in the trade. But the wisdom of our ancestors is in the simile; and my unhallowed hands shall not disturb it, or the Country’s done for. You will therefore permit me to repeat, emphatically, that Marley was as dead as a door-nail.
p Scrooge knew he was dead? Of course he did. How could it be otherwise? Scrooge and he were partners for I don’t know how many years. Scrooge was his sole executor, his sole administrator, his sole assign, his sole residuary legatee, his sole friend, and sole mourner. And even Scrooge was not so dreadfully cut up by the sad event, but that he was an excellent man of business on the very day of the funeral, and solemnised it with an undoubted bargain.
p The mention of Marley’s funeral brings me back to the point I started from. There is no doubt that Marley was dead. This must be distinctly understood, or nothing wonderful can come of the story I am going to relate. If we were not perfectly convinced that Hamlet’s Father died before the play began, there would be nothing more remarkable in his taking a stroll at night, in an easterly wind, upon his own ramparts, than there would be in any other middle-aged gentleman rashly turning out after dark in a breezy spot—say Saint Paul’s Churchyard for instance—literally to astonish his son’s weak mind.
p Scrooge never painted out Old Marley’s name. There it stood, years afterwards, above the warehouse door: Scrooge and Marley. The firm was known as Scrooge and Marley. Sometimes people new to the business called Scrooge Scrooge, and sometimes Marley, but he answered to both names. It was all the same to him.
img.small(src="https://source.unsplash.com/1600x900?wrigley")
p Oh! But he was a tight-fisted hand at the grindstone, Scrooge! a squeezing, wrenching, grasping, scraping, clutching, covetous, old sinner! Hard and sharp as flint, from which no steel had ever struck out generous fire; secret, and self-contained, and solitary as an oyster. The cold within him froze his old features, nipped his pointed nose, shrivelled his cheek, stiffened his gait; made his eyes red, his thin lips blue; and spoke out shrewdly in his grating voice. A frosty rime was on his head, and on his eyebrows, and his wiry chin. He carried his own low temperature always about with him; he iced his office in the dog-days; and didn’t thaw it one degree at Christmas.
p External heat and cold had little influence on Scrooge. No warmth could warm, no wintry weather chill him. No wind that blew was bitterer than he, no falling snow was more intent upon its purpose, no pelting rain less open to entreaty. Foul weather didn’t know where to have him. The heaviest rain, and snow, and hail, and sleet, could boast of the advantage over him in only one respect. They often “came down” handsomely, and Scrooge never did.
footer.footer
.footer-inner
h1.logo Logo
nav.nav
ul
li
a(href="https://cdpn.io/brianhaferkamp/debug/KKgGWog") Page 2
li
button.dark-button Dark <i class="zmdi zmdi-brightness-2 zmdi-hc-fw"></i>
li
button.light-button(hidden) Light <i class="zmdi zmdi-sun zmdi-hc-fw"></i>
//- To see the process of how I made this dark mode toggle, watch this tutorial video:
//- https://youtu.be/42gltu11wb8
@import url("https://fonts.googleapis.com/css?family=Raleway:400,400i,700")
body
font-family: Raleway, sans-serif
font-size: 18px
line-height: 1.7
background:
color: #eaeaea
color: #333
transition: background-color 800ms ease
&.dark
background:
color: #222
color: #eaeaea
.masthead,
.footer
background:
color: #121212
img
// filter: saturate(50%)
filter: brightness(70%)
h2
font-size: 3rem
line-height: 1.2
img
width: 100%
&.small
width: 60%
float: right
padding: 1rem
.masthead,
.footer
padding: 0 1rem
background:
color: #ddd
transition: background-color 800ms ease
.masthead-inner,
.footer-inner
display: flex
justify-content: space-between
align-items: center
max-width: 900px
margin: auto
.nav
ul
list-style: none
padding: 0
margin: 0
button
border: 1px solid #333
padding: .5rem
background: #333
border-radius: 5px
transition: background 200ms ease
color: #eaeaea
&:hover
background: rgba(#333, 0.8)
.dark-button
i
transform: rotate(35deg)
margin-left: .3rem
main
padding: 1rem
max-width: 900px
margin: auto
//- To see the process of how I made this dark mode toggle, watch this tutorial video:
//- https://youtu.be/42gltu11wb8
// Dark Mode Setup
var darkMode;
if (localStorage.getItem('dark-mode')) {
// if dark mode is in storage, set variable with that value
darkMode = localStorage.getItem('dark-mode');
} else {
// if dark mode is not in storage, set variable to 'light'
darkMode = 'light';
}
// set new localStorage value
localStorage.setItem('dark-mode', darkMode);
if (localStorage.getItem('dark-mode') == 'dark') {
// if the above is 'dark' then apply .dark to the body
$('body').addClass('dark');
// hide the 'dark' button
$('.dark-button').hide();
// show the 'light' button
$('.light-button').show();
}
// Toggle dark UI
$('.dark-button').on('click', function() {
$('.dark-button').hide();
$('.light-button').show();
$('body').addClass('dark');
// set stored value to 'dark'
localStorage.setItem('dark-mode', 'dark');
});
$('.light-button').on('click', function() {
$('.light-button').hide();
$('.dark-button').show();
$('body').removeClass('dark');
// set stored value to 'light'
localStorage.setItem('dark-mode', 'light');
});
//--------------------------------------------------
// Below is all that is neede for the basic toggle
//--------------------------------------------------
// $('.dark-button').on('click', function() {
// $('.dark-button').hide();
// $('.light-button').show();
// $('body').addClass('dark');
// });
// $('.light-button').on('click', function() {
// $('.light-button').hide();
// $('.dark-button').show();
// $('body').removeClass('dark');
// });
Also see: Tab Triggers