123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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&nbsp;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&nbsp;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&nbsp;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`;
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console