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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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 class="main">
<h2> Lorem, ipsum dolor.</h2>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nesciunt, sint odit. Esse, magnam quas fugit suscipit facilis ut rem numquam aliquid tempore maxime aliquam quo expedita reprehenderit eligendi est sint totam quae sunt molestiae neque, omnis incidunt blanditiis provident corporis? Recusandae, velit aliquid quasi quas saepe ullam dolorum! Molestias, amet!</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Cum sequi aliquid accusamus corrupti. Placeat, consequatur.
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis ducimus magni labore dolor saepe quisquam odio! Molestias veritatis beatae, nulla recusandae iure dolorum nihil sunt culpa delectus distinctio! Cumque perspiciatis eaque dolore architecto at doloribus quisquam delectus minus ab aperiam exercitationem nobis eum eligendi fugiat nam, id aspernatur dicta nihil fugit maxime? Rem deserunt asperiores sapiente quae ex placeat assumenda nam, nostrum, neque facere, rerum consequuntur maxime unde perferendis excepturi?
</p>
<h3>Lorem, ipsum.</h3>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis ducimus magni labore dolor saepe quisquam odio! Molestias veritatis beatae, nulla recusandae iure dolorum nihil sunt culpa delectus distinctio! Cumque perspiciatis eaque dolore architecto at doloribus quisquam delectus minus ab aperiam exercitationem nobis eum eligendi fugiat nam, id aspernatur dicta nihil fugit maxime? Rem deserunt asperiores sapiente quae ex placeat assumenda nam, nostrum, neque facere, rerum consequuntur maxime unde perferendis excepturi?
</p>
<h3> Lorem ipsum dolor sit amet consectetur.</h3>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Adipisci, laudantium?
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita ducimus optio maiores, obcaecati laborum magnam dolore fuga eum accusantium minus. Dolores accusamus culpa labore, reiciendis odio nemo id blanditiis enim laboriosam corrupti praesentium accusantium unde optio repellat delectus debitis quisquam sequi iste deserunt quod quibusdam molestias nobis! Voluptatem at eos distinctio esse perferendis, blanditiis quae velit aspernatur illum tempora consequuntur, amet nisi recusandae. Cumque officiis quidem temporibus expedita sequi obcaecati laborum labore. Officia maxime ad laborum perspiciatis unde pariatur rem, error distinctio, vitae commodi, fuga illo quae eligendi impedit! Ut vitae numquam sapiente officia mollitia veniam aperiam optio error voluptas, quasi saepe porro a labore dolorem! Quaerat sit, impedit blanditiis provident incidunt in necessitatibus minus assumenda, quo, aspernatur amet quia eveniet? Natus, nam? Architecto, similique omnis. Ipsum, nulla dignissimos? Illum, veritatis saepe vel sapiente nisi in eum alias perspiciatis qui sit dolorem itaque maxime voluptas corporis ullam ab optio doloremque natus. Praesentium aut molestias, iste quia quibusdam velit provident magni quae? Hic, laboriosam dolor, odit dolores, sapiente qui alias sequi ipsam nostrum consequatur amet pariatur molestias. Veritatis autem obcaecati ducimus libero officia facere dolore accusamus aliquid omnis, vero optio atque possimus, voluptate ad, modi soluta corrupti. Iste nobis mollitia asperiores?
</p>
<h3>Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt, voluptas.</h3>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Iure corporis, amet dolorem voluptatum facilis accusamus id porro ea consequuntur eligendi sapiente rem fugiat rerum omnis odit atque quo quod facere. Minus expedita quisquam, voluptates officia veritatis consequuntur. Soluta, distinctio! Distinctio, maiores ab fugit tempore eum, error ut dolorum exercitationem minima laborum omnis facilis reiciendis illum assumenda id obcaecati iure eos eligendi amet nostrum voluptatum asperiores ipsum quia modi! Mollitia numquam accusamus, qui quisquam consequatur sapiente nihil quibusdam repudiandae corrupti deserunt porro quidem consectetur inventore, incidunt et quos quia autem expedita soluta odio. Ipsum soluta, molestias expedita autem voluptatum cum quas repudiandae unde. Quisquam aliquam rem saepe dicta totam distinctio minima accusamus quos placeat? Doloribus voluptatibus provident illo, magni enim doloremque, quasi similique eveniet facilis quo, id consequatur ea molestias obcaecati? Debitis magnam dolorum excepturi saepe molestiae, asperiores earum velit ullam minima cumque id corporis omnis nam adipisci distinctio sed? Ipsum quam porro neque illo quos, cum iure minus excepturi molestiae distinctio vel corporis autem provident modi sed magni voluptate eveniet odit et officia debitis? Ut commodi praesentium illum aliquid labore dignissimos cupiditate aliquam. Error nemo velit, tempora beatae ratione dolorem enim adipisci sequi, animi exercitationem vitae mollitia blanditiis, eaque inventore.
</p>
<h4>Lorem ipsum dolor sit.</h4>
</div>
.main {
max-width:500px;
margin:0 auto;
}
.list-toc{
background:#ccc;
padding:10px 10px;
border-radius:5px;
list-style:none;
}
.list-toc .h3{margin-left:5px;}
.list-toc .h4{margin-left:10px;}
.list-toc .h5{margin-left:15px;}
.list-toc .h6{margin-left:20px;}
function ListTOC(selectInsert){
let hlist = [];
const listheadings = ['h1','h2','h3','h4','h5'];
const selectorInsert = selectInsert; // селектор куда будем вставляти наш зміст
let list = document.querySelectorAll(listheadings.join());
list.forEach((el, index) => {
const tagname = el.localName;
hlist.push({
'tagname':tagname,
'index': index,
'el':el
});
})
let groups = hlist.reduce(function (r, a) {
r[a.tagname] = r[a.tagname] || [];
r[a.tagname].push(a);
return r;
}, Object.create(null));
let hNavigator = `<ul class="list-toc">`;
for (el in groups){
hNavigator += render(groups[el])
}
hNavigator += `</ul>`
document.querySelector(selectorInsert).insertAdjacentHTML('afterbegin', hNavigator)
/**
*/
function renderTocEl(el,index){
return `<li class="${el.localName}"><a href="#it${index}">${el.textContent}</a></li>`
}
function render(data){
let hNavigator = `<ul>`;
data.map(el=>{
el.el.id = `it${el.index}`
hNavigator += renderTocEl(el.el,el.index);
})
hNavigator += `</ul>`
return hNavigator;
}
}
ListTOC('.main')
Also see: Tab Triggers