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.
<div id="contents">
<h1>Garden of Contents</h1>
<p>Welcome to the fabled garden, where you'll hopefully be able to find a flower suitable to your liking!</p>
<!-- These nested unordered lists are the Table of Contents itself. -->
<ul>
<!-- below is an important part - the link at the very top of the index that toggles opening and closing all sections of the index at once. you can change the text it displays below -->
<li id="unfolder"><span id="uneclipse">Unfold all sections...</span><span id="uneclipsed" class="hidden">Hide all sections...</span></li>
<li><a href="#" name="Roses">Roses</a></li>
<!-- Lacking an href, they're clickable titles for nested sections within the table itself, ie, this one. To do this, you're going to want to apply that class (.eclipse) to the title of every nested part of list, as shown below -->
<li><a class="eclipse">Seasonal Blooms</a>
<ul>
<li><a href="#">Perpetual Flowerings</a></li>
<!-- As you can see below, applying the class .gray to any ul or li (nested or not) will gray it out and add a null symbol (configurable in the CSS) to indicate that it is unfinished -->
<li class="gray"><a class="eclipse">Hazards and Joys</a>
<!-- As you'll notice here, you can comfortably have a table of contents nested three levels deep. If you edit the CSS yourself, you can probably make it work for four levels or so, if absolutely necessary. -->
<ul>
<li><a href="#">Beagles and Digging</a></li>
<li><a href="#">Birds and Stuff</a></li>
</ul>
</li>
<!-- Here are some more examples of both nested, unnested, and grayed-out links -->
<li><a href="#">Spring</a></li>
<li><a href="#">Summer</a></li>
<li><a href="#">Autumn</a></li>
<li class="gray"><a href="#">Winter</a></li>
</ul>
</li>
<li class="gray"><a href="#">Growing Herbs</a></li>
<li><a href="#">Pollinators</a></li>
<li><a class="eclipse">Exotic Flowers</a>
<ul>
<li><a href="#">What are exotic flowers?</a></li>
<li><a href="#">Orchids</a></li>
<li><a href="#">Lotus</a></li>
</ul>
</li>
<li><a class="eclipse">Wildflowers</a>
<ul>
<li><a href="#">Why wildflowers?</a></li>
<li><a href="#">Daisies</a></li>
<li><a href="#">Dandelion</a></li>
</ul>
</li>
<li class="gray"><a href="#">Lawncare</a></li>
</ul>
</div>
<!-- we here have jquery, which MUST BE INCLUDED in order for this to work, but it really ought go at the bottom of your site -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
/* this is a fancified demonstrative version of the CSS. all colors, text, etc, is for demonstration purposes only and can be changed - that is, of course, precisely the point. */
body {
background-color: #f8c8c8;
}
/* we begin styling of the box which contains the table of contents. here, it's just in the middle of the page, and called "#contents," but could easily be renamed or removed, since it serves primarily an aesthetic function here, as does everything else between this and the unordered list styling itself */
#contents {
width: 40%;
background-color: white;
font-family: Helvetica;
margin: auto;
padding: 0 0 1.5em;
color: #400;
border: 1px dashed #f8c8c8;
}
#contents p {
padding: 1em;
text-align: justify;
margin: 0px;
}
/* a little fancy title, nothing more, dearies */
#contents h1 {
color: #ffffff;
background: #b35a60;
padding: 0.4em;
margin-bottom: 0px;
font-size: 4em;
font-variant: small-caps;
font-style: oblique;
font-family: impact;
letter-spacing: 0.1em;
line-height: 0.7em;
text-align: center;
margin-top: 0px;
text-shadow: 4px 3px 10px #8f484c;
}
/* and the chaos of unordered lists begins, which will allow, ultimately, for a pleasing appearance to the form itself. we shall begin with this tidbit, which makes sure that the menu is collapsed when it loads and that the interior sections don't initially display */
#unfolder {
font-weight: bold;
text-decoration: underline;
cursor: pointer;
} /* this particular portion styles the initial link to open the index completely */
.hidden {
display: none;
}
.shown {
display: visible;
}
.eclipse + ul {
display: none;
}
/*the below part is important, though, because it provides feedback to the user - lets 'em know they can click on certain parts to see more. */
.eclipse {
cursor: pointer;
}
/* below organizes colors, padding, margins, etc, for the nested unordered lists within the table of contents. you can play with these a bit to */
#contents ul {
margin: 1em;
width: 84%;
margin: auto;
margin-top: 0em;
margin-bottom: 0em;
}
#contents ul ul li,
#contents ul ul ul li {
border: 0px;
}
#contents ul,
#contents ul ul,
#contents ul ul ul {
color: #b35a60;
padding-left: 0em;
padding-top: 0.4em;
padding-bottom: 0em;
}
/* the entry for list-style-type below will be the symbol to the left of top-level items */
#contents ul li {
list-style-type: "❁";
padding: 0.5em;
border-bottom: 1px dashed #f8c8c8;
text-align: left;
}
#contents ul li:last-child {
border-bottom: 0;
}
/* below, list-style-type designates the symbol of second-level items */
#contents ul ul li {
list-style-type: "➺";
}
/* and below, you can change the symbol for third-level items */
#contents ul ul ul li {
list-style-type: "❀";
}
/* i'm here going to style the links a bit, including their color, whether they're underlined, and a nice background color on hover; you can remove this if you want your theme to supersede it */
#contents li a {
color: #b35a60;
text-decoration: underline;
}
#contents li a:hover {
background-color: #f8c8c8;
color: #b35a60;
transition: 1s;
}
/* this part creates the .gray class, which you add to any list item (or an entire nested list) to turn it gray and demonstrate that it isn't finished. */
#contents .gray a {
color: #e3bec7;
text-decoration: none;
}
#contents .gray * {
color: #e3bec7;
}
#contents .gray a::before {
content: "∅";
font-weight: bold;
color: #e3bec7;
margin-right: 0.3em;
color: "#E3BEC7";
}
//THIS PORTION WILL CONTROL THE SPEED AT WHICH YOUR MENU EXPANDS AND CONTRACTS WHEN SINGLE SECTIONS ARE OPENED, USING THE JQUERY SLIDETOGGLE SPELL. I JUST SET IT TO "SLOW," BUT IT CAN BE LISTED IN SECONDS (IE, 1S), OR MILLISECONDS, (IE 300MS).DITTO FOR THE SPEED OF SLIDEUP AND SLIDEDOWN USED BELOW, TOO.
$(document).ready(function () {
$(".eclipse").click(function () {
$(this).next("ul").slideToggle("slow");
});
var concealed = $(".eclipse");
var revealed = false;
//THE #UNFOLDER IS THE ELEMENT THAT ONE CLICKS TO... UNFOLD EVERYTHING. I APPLIED IT TO THE FIRST LIST ITEM...
$("#unfolder").click(function (event) {
event.preventDefault();
if (revealed) {
concealed.each(function () {
$(this).next("ul").slideUp("slow");
});
//#UNECLIPSE AND #UNECLIPSED ARE IDS APPLIED TO SPAN TAGS THAT APPEAR WITHIN #UNFOLDER DEPENDING ON WHETHER THE TABLE IS HIDDEN OR UNFOLDED, RESPECTIVELY. THIS LETS YOU TELL THE USER WHERE TO CLICK TO TOGGLE. CONTENTS OF THESE TAGS CAN BE CHANGED WITHIN THE HTML...
$("#uneclipse").removeClass("hidden").addClass("shown");
$("#uneclipsed").removeClass("shown").addClass("hidden");
revealed = false;
} else {
concealed.each(function () {
$(this).next("ul").slideDown("slow");
});
$("#uneclipsed").removeClass("hidden").addClass("shown");
$("#uneclipse").removeClass("shown").addClass("hidden");
revealed = true;
}
});
});
Also see: Tab Triggers