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.
<h1 class="title">Typography ⌨️ Playground </h1>
<div class="container">
<h2>Recommendations</h2>
<ul>
<li>Font Size: 16px to 26px</li>
<li>Line-Height: 120% to 160%</li>
<li>Line-Length: 45 to 90 characters (including spaces)</li>
</ul>
<article class="paper">
<div class="slide-container">
<p class="input-description">Font Size</p>
<input type="range" min="8" max="42" value="19" class="slider" id="font-size-slider">
<p class="input-result" id="font-size-value">19px</p>
</div>
<div class="slide-container">
<p class="input-description">Line Height</p>
<input type="range" min="50" max="300" value="150" class="slider" id="line-height-slider">
<p class="input-result" id="line-height-value">150%</p>
</div>
<div class="slide-container">
<p class="input-description">Line Length</p>
<input type="range" min="0" max="15" value="0" class="slider" id="line-length-slider">
<p class="input-result" id="line-length-value">160%</p>
</div>
<hr style="margin: 1em 0; color: #333; opacity: .5; ">
<p class="demo-text" style="font-size: 19px; line-height: 1.5">The main part of this book was written during the dark days of the war, and this preface, cogitated during days which were darker still. During the war we could dream of peace, and we thought of it as if it would bring happiness and virtue. That would
have been possible if the greed for material things and for power had subsided, but it has not by any means, and in a sense one might say that the war is not over. Our technicians are arranging a new world free from the humanities, with a few atomic
bombs suspended above it. They seem to think that when bread has been given to the people, the essential has been done, but man cannot live by bread alone. (Millions of men and women lack even bread.) Nevertheless, we should not despair, but work
harder, with a deeper faith, cultivate the humanities, and defend the noble traditions without which life, however efficient or comfortable, is hardly worth living.</p>
</article>
</div>
<!-- End -->
/**
* index.scss
* - Add any styles you want here!
*/
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
$font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
$font-serif: Georgia, "Times New Roman", serif;
body {
background: #cccccc;
font-family: $font-serif;
font-size: calc(1em + 0.35vw);
line-height: 1.5;
}
h1 {
margin: 0.5em 1em;
color: #333;
// color: scale-color(#6b5b95, $lightness: -30%);
font-family: $font-sans;
font-size: 2.5em;
font-weight: 700;
letter-spacing: 2px;
line-height: 1.2;
text-align: center;
text-shadow: 1px 1px #fbaf08, 2.5px 2.5px #333;
text-transform: uppercase;
}
h2 {
font-family: $font-sans;
font-size: 1.5em;
font-weight: 600;
}
%margin-tb {
margin: 0.5em 0;
}
%page-padding {
margin: 0 auto;
max-width: 1040px;
padding: 1em 4vw;
}
.slide-container {
width: 100%;
align-items: center;
display: flex;
flex-shrink: 1;
flex-wrap: wrap;
margin-bottom: 1em;
}
.input-description,
.input-result {
margin: 0.5em 0;
font-family: $font-sans;
line-height: 1.1;
text-transform: uppercase;
font-weight: 600;
}
.input-description {
margin-right: 25px;
width: 6em;
}
.input-result {
width: 3em;
text-align: left;
}
.slider {
-webkit-appearance: none;
appearance: none;
flex: 100%;
height: 10px;
margin: 0.5em 0;
background: #4d4d4d;
border-radius: 10px;
outline: none;
opacity: 0.7;
-webkit-transition: 0.2s;
transition: opacity 0.2s;
}
@media screen and (min-width: 480px) {
.slider {
flex: 2;
}
.input-result {
margin-left: 25px;
text-align: right;
}
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none; /* Override default look */
appearance: none;
width: 25px; /* Set a specific slider handle width */
height: 25px; /* Slider handle height */
background: #4d4d4d; /* Green background */
border-radius: 50%;
cursor: grab; /* Cursor on hover */
line-height: 1;
}
.slider::-moz-range-thumb {
width: 25px; /* Set a specific slider handle width */
height: 25px; /* Slider handle height */
background: #4d4d4d; /* Green background */
cursor: grab; /* Cursor on hover */
border-radius: 50%;
border: 2px solid black;
line-height: 1;
box-shadow: 8px 8px 15px rgba(0, 0, 0, 0.08), 1px 1px 2px rgba(0, 0, 0, 0.15);
}
.slider::-moz-range-thumb:active {
cursor: grabbing;
}
.slider::-webkit-slider-thumb:active {
cursor: grabbing;
}
#font-size-value {
text-transform: lowercase;
}
.paper {
height: 1000px;
margin: 2em 0;
padding: 2em 2em;
background: #ddd;
border-radius: 10px;
box-shadow: 8px 8px 15px rgba(0, 0, 0, 0.08), 1px 1px 2px rgba(0, 0, 0, 0.15);
overflow: hidden;
}
.container {
@extend %page-padding;
}
.identifier {
margin-bottom: 1em;
padding: 5px;
font-size: calc(1em + 0.35vw);
font-family: $font-sans;
border-bottom: 3px solid #66806d;
.right {
float: right;
}
}
// Get demo text
const demoText = document.querySelector(".demo-text");
// Get Font Size slider and value
const fontSizeSlider = document.getElementById("font-size-slider");
const fontSizeValue = document.getElementById("font-size-value");
// Get Line Height
const lineHeightSlider = document.getElementById("line-height-slider");
const lineHeightValue = document.getElementById("line-height-value");
// Set font size and value on change
fontSizeSlider.addEventListener("input", e => {
demoText.style.fontSize = `${e.target.value}px`;
fontSizeValue.innerText = `${e.target.value}px`;
});
// Set line height and value on change
lineHeightSlider.addEventListener("input", e => {
demoText.style.lineHeight = `${e.target.value}%`;
lineHeightValue.innerText = `${e.target.value}%`;
});
//Calculate line height and words per line
const demoStyles = document.defaultView.getComputedStyle(demoText);
const inputs = document.querySelectorAll("input");
const wordsPerLine = document.getElementById("line-length-value");
function updateLines() {
let height = parseInt(demoStyles.getPropertyValue("height"));
let lineHeight = parseInt(demoStyles.getPropertyValue("line-height"));
let result = height / lineHeight;
let characterCount = demoText.innerText.length;
let lineResult = Math.round(characterCount / result);
wordsPerLine.innerText = lineResult;
}
updateLines();
inputs.forEach(item => {
item.addEventListener("input", updateLines);
});
// Update line length value
const lineLengthSlider = document.getElementById("line-length-slider");
lineLengthSlider.addEventListener("input", e => {
demoText.style.padding = `0 ${e.target.value}em`;
});
Also see: Tab Triggers