Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                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: "❀";
}

              
            
!

JS

              
                //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;
	}
});

              
            
!
999px

Console