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.
<ul id="garden">
<!-- 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">
<!-- The next lines determine what displays when the table is folded/unfolded respectively -->
<span id="uneclipse">Unfold all sections...</span>
<span id="uneclipsed">Hide all sections...</span>
</li>
<li><a href="#">This is a top level link.</a></li>
<!-- apply an anchor tag with the class "eclipse" (<a class="eclipse">) to every top level link that will open a nested list of links, but no others. -->
<li><a class="eclipse">This opens a nested list.</a>
<ul>
<li><a href="#">This is a second level link.</a></li>
<!-- As you can see below, applying the class .gray to any ul or li (nested or not) will gray it out to signify it's unfinished -->
<li><a class="eclipse">This opens a nested list.</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="#">This is a third level link.</a></li>
<li class="gray"><a href="#">This is an unfinished third level link.</a></li>
<li><a class="eclipse">This is opens a nested list.</a>
<ul>
<li class="gray"><a href="#">This is an unfinished fourth level link.</a></li>
<li><a href="#">This is a fourth level link.</a></li>
</ul>
</li>
<li><a href="#">This is a third level link.</a></li>
</ul>
</li>
<!-- Here are some more examples of both nested, unnested, and grayed-out links -->
<li><a href="#">This is a second level link.</a></li>
<li class="gray"><a href="#">This is an unfinished second level link.</a></li>
</ul>
</li>
<li><a href="#">This is a top level link</a></li>
<li><a class="eclipse">This opens a nested list.</a>
<ul>
<li><a href="#">This is a second level link.</a></li>
<li><a href="#">This is a second level link.</a></li>
<li><a href="#">This is a second level link.</a></li>
</ul>
</li>
<li class="gray"><a class="eclipse">This opens a nested list (of unfinished pages).</a>
<ul>
<li><a href="#">This is a second level link.</a></li>
<li><a href="#">This is a second level link.</a></li>
<li><a href="#">This is a second level link.</a></li>
</ul>
</li>
<li class="gray"><a href="#">This is an unfinished top level link.</a></li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
body {
width: 40%;
margin: auto;
}
/* within this CSS, the assumption has been made that your table of contents list is labeled with the id "#garden", ie "id=garden", but you can choose another and change it, of course. using a specific id for the entire list makes it easy to customize without messing up any other lists on your page */
/* the below portion styles the very first list item, which you can click to toggle whether the menu is completely open or closed */
#unfolder {
font-weight: bold;
text-decoration: underline;
cursor: pointer;
}
/* to style the clickable headings themselves, do so below */
#garden a.eclipse {
color: teal;
}
/* to style all other links, do so below */
#garden a {
color: green;
}
/* 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. */
#garden .gray a {
color: lightgray;
}
/* below is the css necessary - yes, necessary, to hide the menu initially prior to opening/closing it with javascript */
#garden .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. */
#garden .eclipse {
cursor: pointer;
}
/* the padding setting here will control the indentation effect of each nested list in the sequence that displays when you click a top level list item */
#garden ul,
#garden ul ul,
#garden ul ul ul {
padding-left: 1.4em;
}
/* the entry for list-style-type below will be the symbol to the left of top-level items */
#garden li {
list-style-type: "❁";
padding: 0.2em;
text-align: left;
}
/* below, list-style-type designates the symbol of second-level items */
#garden ul li {
list-style-type: "✹";
}
/* below, list-style-type designates the symbol of third-level items */
#garden ul ul li {
list-style-type: "➺";
}
/* and below, you can change the symbol for fourth-level items, if you have any... */
#garden ul ul ul li {
list-style-type: "❀";
}
//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.
$(".eclipse").click(function () {
$(this).next("ul").slideToggle("slow");
});
let concealed = $(".eclipse");
let revealed = false;
$("#uneclipsed").hide();
//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...
//HERE, WE'RE HIDING THE <SPAN> TAG LABELED #UNECLIPSED WHEN THE MENU IS ECLIPSED STILL, AND SHOW THE ONE LABELED #UNECLIPSE, PROMPTING THE USER TO CLICK IT TO UNFOLD IT...
$("#uneclipsed").hide();
$("#uneclipse").show();
revealed = false;
} else {
concealed.each(function () {
$(this).next("ul").slideDown("slow");
});
//ONCE THE MENU HAS BEEN UNFOLDED, WE HIDE #UNECLIPSE AND SHOW #UNECLIPSED TO, INSTEAD, PROMPT THE USER TO CLICK IF THEY WANT TO CLOSE THE MENU
$("#uneclipsed").show();
$("#uneclipse").hide();
revealed = true;
}
});
Also see: Tab Triggers