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.
<nav class="toc">
<ul>
<li><a href="#intro">Intro</a></li>
<li>
<a href="#dev">Developer Mode</a>
<ul>
<li><a href="#dev-edit-html">Edit HTML</a></li>
<li><a href="#dev-element-classes">Element Classes</a></li>
<li><a href="#dev-slide-classes">Slide Classes</a></li>
<li><a href="#dev-export-html">Export HTML</a></li>
</ul>
</li>
<li>
<a href="#css">CSS Editor</a>
<ul>
<li><a href="#css-fonts">Custom Fonts</a></li>
<li><a href="#css-developer-mode">Developer Mode</a></li>
<li><a href="#css-examples">Examples</a></li>
</ul>
</li>
</ul>
<svg class="toc-marker" width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<path stroke="#444" stroke-width="3" fill="transparent" stroke-dasharray="0, 0, 0, 1000" stroke-linecap="round" stroke-linejoin="round" transform="translate(-0.5, -0.5)" />
</svg>
</nav>
<article class="contents">
<section id="intro">
<h2>Progress Nav</h2>
<p>
This page demonstrates an idea for how progress can be visualized inside of a standard page nav. Scroll the page and note how the marker animates to highlight all of the sections that are currently on screen.
</p>
<p>
The rest of the content below is taken from <a href="https://slides.com/developers" target="_top">slides.com/developers</a>. Take a look at that to see how the progress nav looks on a real page.
</p>
<p>
Created by Hakim El Hattab | <a href="http://hakim.se" target="_top">hakim.se</a> | <a href="https://twitter.com/hakimel" target="_top">@hakimel</a>
</p>
<h2>Slides for Developers</h2>
<p>
We strive to make Slides a great and flexible tool for developers. Presentations created on Slides are HTML documents under the hood, so generally anything that HTML can do, Slides can do. We make it easy to access and edit the underlying HTML and CSS through the <a href="#dev">Developer Mode</a>.
</p>
<p>
There's also an API for creating new presentations with preset content and we're aiming to add additional APIs in the future.
</p>
</section>
<section>
<div id="dev">
<h2>Developer Mode</h2>
<p>
The Slides editor has a developer mode which is useful if you know a bit of HTML and CSS. With this mode active you will be able to modify the underlying HTML of your deck, allowing you to make adjustments that the Slides editor does not provide interface options for.
</p>
<p>
To enable the developer mode open the editor settings in the bottom left corner:
</p>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-developer-mode-1.png">
</div>
<div id="dev-edit-html">
<h3>Editing HTML</h3>
<p>
The per-slide HTML editor can be accessed from the slide options area. It gives you raw access to the current slide's HTML, allowing you to change anything you like. Note that some elements, such as <script> and <link>, are not allowed for security reasons.
</p>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-developer-mode-2.png">
</div>
<div id="dev-element-classes">
<h3>Element Classes <a href="/pricing" class="header-secondary-text">(Requires Pro)</a></h3>
<p>
As a paying Slides customer you have access to the <a href="#css">CSS editor</a> which allows you to add custom styles to your deck. By turning on the developer mode a new "class name" field will appear for any block that you focus. This allows you to easily target a specific element with your CSS.
</p>
<p>
Here's an example that defines an "upside-down" class using custom CSS and applies it to a text block.
</p>
<pre class="code-block" data-highlight-theme="github-gist"><code class="hljs css">.upside-down {
transform: scale( 1, -1 );
}</code></pre>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-developer-mode-3.png">
</div>
<div id="dev-slide-classes">
<h3>Slide Classes <a href="/pricing" class="header-secondary-text">(Requires Pro)</a></h3>
<p>
Just like you can add custom classes to individual elements it's also possible to add custom classes at the slide level. This can used to apply broader changes to the whole slide like inverting text and icon colors or changing the slide transition.
</p>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-developer-mode-4.png">
<p>
Under the hood the slide background element is separate from the slide itself. Here are two examples showing how you'd target the slide contents or slide background using a custom class called "night-sky":
</p>
<pre class="code-block" data-highlight-theme="github-gist"><code class="hljs css">// Targets the slide contents
.slides .night-sky svg path {
fill: yellow;
}
// Target the slide background
.backgrounds .night-sky {
background: linear-gradient(0deg, #141528, #0b1bb2);
}</code></pre>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-developer-mode-5.png">
</div>
<div id="dev-export-html">
<h3>Export HTML</h3>
<p>
You can access the complete HTML for all slides in your deck inside of the export panel, under "Export to reveal.js". This provides a way of exporting your deck markup and the core Slides styles to reveal.js. There are a few limitations with exporting this way but it should provide a good starting point.
</p>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-developer-mode-6.png">
</div>
</section>
<section>
<div id="css">
<h2>CSS Editor <a href="/pricing" class="header-secondary-text">(Requires Pro)</a></h2>
<p>
The CSS editor lets you author custom styles for your presentation with a real-time preview of the result. It's available as an option inside of the Style panel of the presentation editor.
</p>
<p>
The editor preprocesses styles using <a href="http://lesscss.org/">LESS</a>, though you're free to write plain CSS as well. We apply the styles in real-time as you type so there's no need to leave the editor or even press a refresh button to see what you're getting. Note that when your styles are saved they will be automatically wrapped in a ".reveal {}" selector to avoid conflicts with other page styles.
</p>
</div>
<div id="css-fonts">
<h3>Custom Fonts</h3>
<p>
You can load custom fonts from Typekit and Google fonts and apply them using custom CSS. <a href="http://help.slides.com/knowledgebase/articles/1077976-custom-fonts-pro">Find out more</a>.
</p>
</div>
<div id="css-developer-mode">
<h3>Developer Mode</h3>
<p>
If you turn on the <a href="#dev">developer mode</a> you can also add custom classes to any focused element. This is a convenient way to easily apply your CSS to specific elements.
</p>
</div>
<div id="css-examples">
<h3>Examples</h3>
<pre class="code-block" data-highlight-theme="github-gist"><code class="hljs css">// Change presentation background
& {
background: #a83239;
}
// Change color of body text
.slides {
color: #009999;
}
// Turn text white if the slide has a dark background
.has-dark-background {
color: #fff;
}
// Add a blue border to all slides (each slide is a <section>)
.slides section {
outline: 1px solid blue;
}
// Add a red border to all vertical stacks of slides
.slides section.stack {
outline: 1px solid red;
}<br>
// Include a custom font<br>@font-face {<br> font-family: "Cabin Sketch";<br> src: url("https://s3.amazonaws.com/static.slid.es/fonts/cabinsketch/cabinsketch-regular.woff") format("woff"),<br> url("https://s3.amazonaws.com/static.slid.es/fonts/cabinsketch/cabinsketch-regular.ttf") format("truetype");<br>}
<br>.slides h1, .slides h2, .slides h3 {<br> font-family: "Cabin Sketch";<br>}
// Change color of controls and progress bar
@interactiveColor: rgb(200,105,119);
.progress span {
background: @interactiveColor !important;
}
.controls .navigate-left {
border-right-color: @interactiveColor !important;
}
.controls .navigate-right {
border-left-color: @interactiveColor !important;
}
.controls .navigate-up {
border-bottom-color: @interactiveColor !important;
}
.controls .navigate-down {
border-top-color: @interactiveColor !important;
}</code></pre>
</div>
<p>Here's where you can access the CSS editor from inside of the Style panel:</p>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-css-editor-1.png">
<p>A screenshot of the editor:</p>
<img class="developer-image" src="https://static.slid.es.s3.amazonaws.com/site/developers/slides-css-editor-2.png">
</section>
</article>
$menuWidth: 14em;
$menuPaddingLeft: 3em;
* {
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
overflow: auto;
}
body {
padding: 2em 2em 2em $menuWidth+$menuPaddingLeft;
font-size: 16px;
line-height: 1.6;
font-family: 'Roboto', sans-serif;
}
.toc {
position: fixed;
left: $menuPaddingLeft;
top: 5em;
padding: 1em;
width: $menuWidth;
line-height: 2;
ul {
list-style: none;
padding: 0;
margin: 0;
}
ul ul {
padding-left: 2em;
}
li a {
display: inline-block;
color: #aaa;
text-decoration: none;
transition: all 0.3s cubic-bezier(0.230, 1.000, 0.320, 1.000);
}
li.visible>a {
color: #111;
transform: translate( 5px );
}
}
.toc-marker {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
path {
transition: all 0.3s ease;
}
}
.contents {
padding: 1em;
max-width: 800px;
font-size: 1.2em;
font-family: 'Frank Ruhl Libre', sans-serif;
img {
max-width: 100%;
}
.code-block {
white-space: pre;
overflow: auto;
max-width: 100%;
code {
display: block;
background-color: #f9f9f9;
padding: 10px;
}
}
.code-inline {
background-color: #f9f9f9;
padding: 4px;
}
h2,
h3 {
padding-top: 1em;
}
}
@media screen and (max-width: 1200px) {
body {
font-size: 14px;
}
}
var toc = document.querySelector( '.toc' );
var tocPath = document.querySelector( '.toc-marker path' );
var tocItems;
// Factor of screen size that the element must cross
// before it's considered visible
var TOP_MARGIN = 0.1,
BOTTOM_MARGIN = 0.2;
var pathLength;
var lastPathStart,
lastPathEnd;
window.addEventListener( 'resize', drawPath, false );
window.addEventListener( 'scroll', sync, false );
drawPath();
function drawPath() {
tocItems = [].slice.call( toc.querySelectorAll( 'li' ) );
// Cache element references and measurements
tocItems = tocItems.map( function( item ) {
var anchor = item.querySelector( 'a' );
var target = document.getElementById( anchor.getAttribute( 'href' ).slice( 1 ) );
return {
listItem: item,
anchor: anchor,
target: target
};
} );
// Remove missing targets
tocItems = tocItems.filter( function( item ) {
return !!item.target;
} );
var path = [];
var pathIndent;
tocItems.forEach( function( item, i ) {
var x = item.anchor.offsetLeft - 5,
y = item.anchor.offsetTop,
height = item.anchor.offsetHeight;
if( i === 0 ) {
path.push( 'M', x, y, 'L', x, y + height );
item.pathStart = 0;
}
else {
// Draw an additional line when there's a change in
// indent levels
if( pathIndent !== x ) path.push( 'L', pathIndent, y );
path.push( 'L', x, y );
// Set the current path so that we can measure it
tocPath.setAttribute( 'd', path.join( ' ' ) );
item.pathStart = tocPath.getTotalLength() || 0;
path.push( 'L', x, y + height );
}
pathIndent = x;
tocPath.setAttribute( 'd', path.join( ' ' ) );
item.pathEnd = tocPath.getTotalLength();
} );
pathLength = tocPath.getTotalLength();
sync();
}
function sync() {
var windowHeight = window.innerHeight;
var pathStart = pathLength,
pathEnd = 0;
var visibleItems = 0;
tocItems.forEach( function( item ) {
var targetBounds = item.target.getBoundingClientRect();
if( targetBounds.bottom > windowHeight * TOP_MARGIN && targetBounds.top < windowHeight * ( 1 - BOTTOM_MARGIN ) ) {
pathStart = Math.min( item.pathStart, pathStart );
pathEnd = Math.max( item.pathEnd, pathEnd );
visibleItems += 1;
item.listItem.classList.add( 'visible' );
}
else {
item.listItem.classList.remove( 'visible' );
}
} );
// Specify the visible path or hide the path altogether
// if there are no visible items
if( visibleItems > 0 && pathStart < pathEnd ) {
if( pathStart !== lastPathStart || pathEnd !== lastPathEnd ) {
tocPath.setAttribute( 'stroke-dashoffset', '1' );
tocPath.setAttribute( 'stroke-dasharray', '1, '+ pathStart +', '+ ( pathEnd - pathStart ) +', ' + pathLength );
tocPath.setAttribute( 'opacity', 1 );
}
}
else {
tocPath.setAttribute( 'opacity', 0 );
}
lastPathStart = pathStart;
lastPathEnd = pathEnd;
}
Also see: Tab Triggers