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

              
                <div class="content-container">
  <h1>The Odyssey, Book I</h1>
  <p>Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely home; but do what he might he could not save his men, for they perished through their own sheer folly in eating the cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all these things, O daughter of Jove, from whatsoever source you may know them. 
  </p>
  <h2>Somewhere in the middle, another header appeared</h2>
  <p>So now all who escaped death in battle or by shipwreck had got safely home except Ulysses, and he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who had got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods settled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles were not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted him without ceasing and would not let him get home. </p>
</div>

              
            
!

CSS

              
                /* Note below that you can find min and max */
/* values for width and weight */
@font-face {
  font-family: 'Frutiger VF';
  src: url('https://rwt.io/_demo_fonts/monotype/frutiger/FrutigerNeueVariable-Roman.subset.woff2') format('woff2-variations');
  font-display: swap;
  font-stretch: 75% 100%;
  font-style: normal;
  font-weight: 250 900;
}

:root {
  /* font stack variables */
  --font-stack-sans-vf: "Frutiger VF", Helvetica, arial, sans-serif;
  
  /* assign font stacks for headings and text */
  --font-stack-heading: var(--font-stack-sans-vf);
  --font-stack-body: var(--font-stack-sans-vf);

  /* breakpoint variables */
  --bp-small: 25;
  --bp-medium: 45;
  --bp-large: 55;
  --bp-xlarge: 65;
  
  /* color variables */
  
  --blue-dark: #313161;
  --blue-lightest: #e1f1ff;

  --text-color: var(--blue-dark);
  --background-color: var(--blue-lightest);
  
  /* set px value sizes */
  /* initial px value for text */
  --rem-px: 16;

  /* EDIT HERE to set px value sizes */
  --p-size-s-px: 16;
  --p-size-l-px: 20;
  --h1-size-s-px: 40;
  --h1-size-l-px: 72;
  --h2-size-s-px: 32;
  --h2-size-l-px: 48;

  /* set scale values */
  
  /* calcs to create values for the formulas */
  --p-size-min: calc( var(--p-size-s-px) / var(--rem-px) );
  --p-size-max: calc( var(--p-size-l-px) / var(--rem-px) );
  --p-lh-min: 1.3;
  --p-lh-max: 1.6;
  
  /* values to scale across breakpoint range */
  --p-wdth-min: 90;
  --p-wdth-max: 100;
  --p-wght-min: 350;
  --p-wght-max: 400;

  /* default starting scale value */
  --p-wdth: var(--p-wdth-min);
  --p-wght: var(--p-wght-min);

  /* calcs to create values for the formulas */
  --h1-size-min: calc( var(--h1-size-s-px) / var(--rem-px) );
  --h1-size-max: calc( var(--h1-size-l-px) / var(--rem-px) );
  --h1-lh-min: 1.05;
  --h1-lh-max: 1.1;
  
  /* values to scale across breakpoint range */
  --h1-wdth-min: 75;
  --h1-wdth-max: 85;
  --h1-wght-min: 700;
  --h1-wght-max: 225;

  /* default starting scale value */
  --h1-wdth: var(--h1-wdth-min);
  --h1-wght: var(--h1-wght-min);

  /* calcs to create values for the formulas */
  --h2-size-min: calc( var(--h2-size-s-px) / var(--rem-px) );
  --h2-size-max: calc( var(--h2-size-l-px) / var(--rem-px) );
  --h2-lh-min: 1.05;
  --h2-lh-max: 1.1;
  
  /* values to scale across breakpoint range */
  --h2-wdth-min: 85;
  --h2-wdth-max: 100;
  --h2-wght-min: 575;
  --h2-wght-max: 675;

  /* default starting scale value */
  --h2-wdth: var(--h2-wdth-min);
  --h2-wght: var(--h2-wght-min);
}

  html {
    box-sizing: border-box;
  }
  *, *:before, *:after {
    box-sizing: inherit;
  }
  
  
body {
  background-color: var(--background-color);
  color: var(--text-color);
}

h1 {
  font-family: var(--font-stack-heading);
  /* set low-end scale values for smallest screens */
  font-size: calc( var(--h1-size-min) * 1rem);
  line-height: var(--h1-lh-min); 
  /* JS will scale the next two values dynamically */
  font-stretch: calc( var(--h1-wdth) * 1%);
  font-weight: var(--h1-wght);
}
  @media screen and (min-width: 25em) {
    h1 {
      /* use formula to scale from low value to high between breakpoints */
      line-height: calc(( var(--h1-lh-min) * 1em ) + ( var(--h1-lh-max) - var(--h1-lh-min) ) * ((100vw - ( var(--bp-small) * 1em )) / ( var(--bp-xlarge) - var(--bp-small) )));
      font-size: calc(( var(--h1-size-min) * 1em ) + ( var(--h1-size-max) - var(--h1-size-min) ) * ((100vw - ( var(--bp-small) * 1em )) / ( var(--bp-xlarge) - var(--bp-small) ))); 
    } 
  }
  @media screen and (min-width: 65em) {
    h1 {
      /* set high end values to cap scale for largest screens */
      font-size: calc( var(--h1-size-max) * 1em);
      font-stretch: calc( var(--h1-wdth-max) * 1%);
      font-weight: var(--h1-wght-max); 
      line-height: var(--h1-lh-max); 
    }
  }

h2 {
  font-family: var(--font-stack-heading);
  /* set low-end scale values for smallest screens */
  font-size: calc( var(--h2-size-min) * 1rem);
  line-height: var(--h2-lh-min); 
  /* JS will scale the next two values dynamically */
  font-stretch: calc( var(--h2-wdth) * 1%);
  font-weight: var(--h2-wght);
}
  @media screen and (min-width: 25em) {
    h2 {
      /* use formula to scale from low value to high between breakpoints */
      line-height: calc(( var(--h2-lh-min) * 1em ) + ( var(--h2-lh-max) - var(--h2-lh-min) ) * ((100vw - ( var(--bp-small) * 1em )) / ( var(--bp-xlarge) - var(--bp-small) )));
      font-size: calc(( var(--h2-size-min) * 1em ) + ( var(--h2-size-max) - var(--h2-size-min) ) * ((100vw - ( var(--bp-small) * 1em )) / ( var(--bp-xlarge) - var(--bp-small) ))); 
    } 
  }
  @media screen and (min-width: 65em) {
    h2 {
      /* set high end values to cap scale for largest screens */
      font-size: calc( var(--h2-size-max) * 1em);
      font-stretch: calc( var(--h2-wdth-max) * 1%);
      font-weight: var(--h2-wght-max);
      line-height: var(--h2-lh-max);
    } 
  }


p {
  font-family: var(--font-stack-body);
  /* set low-end scale values for smallest screens */
  font-size: calc( var(--p-size-min) * 1rem);
  line-height: var(--p-lh-min); 
  /* JS will scale the next two values dynamically */
  font-stretch: calc( var(--p-wdth) * 1%);
  font-weight: var(--p-wght);
}
  @media screen and (min-width: 25em) {
    p {
      /* use formula to scale from low value to high between breakpoints */
      line-height: calc(( var(--p-lh-min) * 1em ) + ( var(--p-lh-max) - var(--p-lh-min) ) * ((100vw - ( var(--bp-small) * 1em )) / ( var(--bp-xlarge) - var(--bp-small) )));
      font-size: calc(( var(--p-size-min) * 1em ) + ( var(--p-size-max) - var(--p-size-min) ) * ((100vw - ( var(--bp-small) * 1em )) / ( var(--bp-xlarge) - var(--bp-small) )));
    }
  }
  @media (min-width: 65em) {
    p {
      /* set high end values to cap scale for largest screens */
      font-size: calc( var(--p-size-max) * 1em);
      font-stretch: calc( var(--p-wdth-max) * 1%);
      font-weight: var(--p-wght-max);
      line-height: var(--p-lh-max);
    }
  }

* + p {
  margin-top: 1em; 
} 
    

.content-container {
  margin: 2rem auto;
  max-width: 98vw;
}
  @media (min-width: 45em) {
    .content-container {
      max-width: 40rem; 
    }
  }
  @media (min-width: 55em) {
    .content-container {
      max-width: 42rem; 
    }
  }
  @media (min-width: 65em) {
    .content-container {
      max-width: 46rem; 
    }
  }

              
            
!

JS

              
                function variableResize() {

  // get the computed styles into an object
  let bodyStyles = window.getComputedStyle(document.body);	
	// set up a place to save new values back 
  let root = document.documentElement;
	
	// Minimum and Maximum viewport size - must be unitless em values
	const maxWindowSize = bodyStyles.getPropertyValue('--bp-xlarge') * 16;
	const minWindowSize = bodyStyles.getPropertyValue('--bp-small') * 16;
	
	// Get current viewport size
	const windowWidth = window.innerWidth
	
  // Scale elements and min/max values
  const pWidthVar = '--p-wdth';
	const pMinFontWidth = bodyStyles.getPropertyValue('--p-wdth-min');
	const pMaxFontWidth = bodyStyles.getPropertyValue('--p-wdth-max');
	scale(pWidthVar, pMinFontWidth, pMaxFontWidth);

  const pWeightVar = '--p-wght';
	const pMinFontWeight = bodyStyles.getPropertyValue('--p-wght-min');
	const pMaxFontWeight = bodyStyles.getPropertyValue('--p-wght-max');
	scale(pWeightVar, pMinFontWeight, pMaxFontWeight);
	
  const h1WidthVar = '--h1-wdth';
	const h1MinFontWidth = bodyStyles.getPropertyValue('--h1-wdth-min');
	const h1MaxFontWidth = bodyStyles.getPropertyValue('--h1-wdth-max');
	scale(h1WidthVar, h1MinFontWidth, h1MaxFontWidth);

  const h1WeightVar = '--h1-wght';
	const h1MinFontWeight = bodyStyles.getPropertyValue('--h1-wght-min');
	const h1MaxFontWeight = bodyStyles.getPropertyValue('--h1-wght-max');
	scale(h1WeightVar, h1MinFontWeight, h1MaxFontWeight);
	
  const h2WidthVar = '--h2-wdth';
	const h2MinFontWidth = bodyStyles.getPropertyValue('--h2-wdth-min');
	const h2MaxFontWidth = bodyStyles.getPropertyValue('--h2-wdth-max');
	scale(h2WidthVar, h2MinFontWidth, h2MaxFontWidth);

  const h2WeightVar = '--h2-wght';
	const h2MinFontWeight = bodyStyles.getPropertyValue('--h2-wght-min');
	const h2MaxFontWeight = bodyStyles.getPropertyValue('--h2-wght-max');
	scale(h2WeightVar, h2MinFontWeight, h2MaxFontWeight);
	
	function scale(varName, minValue, maxValue) {
		// Make sure min/max are numbers
		minValue = minValue * 1;
		maxValue = maxValue * 1;

		//Scale within a range
		const percent = (windowWidth - minWindowSize) / (maxWindowSize - minWindowSize);
		if (maxValue < minValue) {
			var valueScale = minValue - (percent * (minValue - maxValue));
		} else {
			var valueScale = (percent * (maxValue - minValue)) + minValue;
		}
	  
		// Get the new font width
		const newValue = windowWidth > maxWindowSize
		   ? maxValue 
		   : windowWidth < minWindowSize 
				? minValue 
				: valueScale;
	   
		// Set my CSS Custom Property for width to update.
		root.style.setProperty(varName, newValue);
	}
}

window.addEventListener("load", variableResize);
window.addEventListener("resize", variableResize);

              
            
!
999px

Console