Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <main class="container pt-3">
	<section class="row">
		<div class="col">
			<h1>Bootstrap 4 Responsive Type Scale</h1>
			<p class="lead mb-4">This is a simple <code>SCSS</code> mixin that will let you quickly change the default Bootstrap type scale based on examples from the <a href="http://type-scale.com/">Type Scale</a> website.</p>
			<table class="table table-bordered">
				<thead>
					<tr>
						<th class="w-25" scope="col">Class</th>
						<th scope="col">Example</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td class="align-middle w-25"><code>.display-1</code></td>
						<td><h1 class="display-1">Bootstrap Type Scale</h1></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.display-2</code></td>
						<td><h2 class="display-2">Bootstrap Type Scale</h2></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.display-3</code></td>
						<td><h3 class="display-3">Bootstrap Type Scale</h3></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.display-4</code></td>
						<td><h4 class="display-4">Bootstrap Type Scale</h4></td>
					</tr>
				</tbody>
			</table>
			<table class="table table-bordered">
				<thead>
					<tr>
						<th class="w-25" scope="col">Heading</th>
						<th scope="col">Example</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td class="align-middle w-25"><code>&lt;h1&gt;&lt;/h1&gt;</code></td>
						<td><h1>Bootstrap Type Scale</h1></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>&lt;h2&gt;&lt;/h2&gt;</code></td>
						<td><h2>Bootstrap Type Scale</h2></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>&lt;h3&gt;&lt;/h3&gt;</code></td>
						<td><h3>Bootstrap Type Scale</h3></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>&lt;h4&gt;&lt;/h4&gt;</code></td>
						<td><h4>Bootstrap Type Scale</h4></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>&lt;h5&gt;&lt;/h5&gt;</code></td>
						<td><h5>Bootstrap Type Scale</h5></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>&lt;h6&gt;&lt;/h6&gt;</code></td>
						<td><h6>Bootstrap Type Scale</h6></td>
					</tr>
				</tbody>
			</table>
			<table class="table table-bordered">
				<thead>
					<tr>
						<th class="w-25" scope="col">Class</th>
						<th scope="col">Example</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td class="align-middle w-25"><code>.h1</code></td>
						<td><p class="h1">Bootstrap Type Scale</p></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.h2</code></td>
						<td><p class="h2">Bootstrap Type Scale</p></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.h3</code></td>
						<td><p class="h3">Bootstrap Type Scale</p></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.h4</code></td>
						<td><p class="h4">Bootstrap Type Scale</p></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.h5</code></td>
						<td><p class="h5">Bootstrap Type Scale</p></td>
					</tr>
					<tr>
						<td class="align-middle w-25"><code>.h6</code></td>
						<td><p class="h6">Bootstrap Type Scale</p></td>
					</tr>
				</tbody>
			</table>
		</div>
	</section>
</main>
              
            
!

CSS

              
                // Default Font Size
//
// This is the default font size as set by Bootstrap V4 in /_reboot.scss
$font-size-base: 1rem;

// Type Scales
//
// Create a map of pre-defined typographic scales as found on
// type-scale.com. These scales can be passed to the mixin that
// creates the font sizes by using their key from the key: value
// pairs.
//
// After the map of scales, two variables are defined.
// $heading-type-scale-base and $display-type-scale-base, these
// variables hold the initial scales that are used from a 0 width
// viewport or browser and upward. These variables accept a key 
// from the $type-scales map or can be passed a unitless value.
// 
// By default Bootstraps .display-4 font size is 1rem larger than
// the h1.  
$type-scales : (
	minor-second: 1.067,
	major-second: 1.125,
	minor-third: 1.200,
	major-third: 1.250,
	perfect-fourth: 1.333,
	augmented-fourth: 1.414,
	perfect-fifth: 1.500,
	golden-ratio: 1.618
);

$heading-type-scale-base : minor-third;
$display-type-scale-base : minor-third;

// Function That Checks For A Valid Type Scale Value
//
// It is important that you are not restricted to only
// the values in the map as the may not be suitable for
// your design.
//
// For this reason, the function below will check if
// the value passed to the mixin is one of the values
// set in the $type-scales map or it must be a unitless
// value to create the type scale.
@function check-type-scale-value($scale) {
	
	// Check $scale against the values in $type-scales.
	@if map-has-key($type-scales, $scale) {
		
		// If the value of $scale is defined in
		// $type-scales, return the value of $scale.
	    @return map-get($type-scales, $scale);
		
	// If the value of $scale is not defined in the 
	// $type-scales map, check if the value is a number
	// and that the number is a unitless value.
	} @else if type-of($scale) == number and unitless($scale) {
		
		// If the value of $scale is a unitless number, 
		// return the number.
		@return $scale;
		
	// Lastly, should the value passed to $scale be neither
	// found in the $type-scales map nor a unitless number,
	// throw a Sass error to explain the issue.
	} @else {
		
		// Throw a Sass error if the $scale value is
		// neither found in the $type-scales map nor
		// a unitless number.
		@error "Sorry, `#{$scale}` is not a unitless number value or a pre-defined key in the $type-scales map.";
	}
	
}

// Mixins That Create Font Sizes
//
// Below are two mixin's that do very similar things.
// They both take a type scale value either from the $type-scales
// map or a custom unitless number.
//
// From there it uses the checkTypeScaleValue() function to 
// evaluate the $scale value and then create the font sizes.
@mixin create-heading-type-scale($scale) {
	
	// Check the $scale value and store in a variable to be 
	// used when calculating the font sizes.
	$the-heading-type-scale: check-type-scale-value($scale);
	
	// Starting from h6, multiply each previous value by the scale
	// to get the next font size
	$font-size-h6 : $font-size-base;
	$font-size-h5 : $font-size-h6 * $the-heading-type-scale;
	$font-size-h4 : $font-size-h5 * $the-heading-type-scale;
	$font-size-h3 : $font-size-h4 * $the-heading-type-scale;
	$font-size-h2 : $font-size-h3 * $the-heading-type-scale;
	$font-size-h1 : $font-size-h2 * $the-heading-type-scale;
	// $font-size-display-base is made global to allow for accessing the 
	// varibale in the next mixin.
	$font-size-display-base : $font-size-h1 !global;
	
	// Add the created font sizes to the elements and classes
	h1, .h1 { font-size: $font-size-h1; }
	h2, .h2 { font-size: $font-size-h2; }
	h3, .h3 { font-size: $font-size-h3; }
	h4, .h4 { font-size: $font-size-h4; }
	h5, .h5 { font-size: $font-size-h5; }
	h6, .h6 { font-size: $font-size-h6; }
	
}

@mixin create-display-type-scale($scale) {

	// Store default type scale in a variable for calculations
	$the-display-type-scale: check-type-scale-value($scale);
	
	// Create variables to reference the previous font size
	$font-size-display-4 : $font-size-display-base + $font-size-base;
	$font-size-display-3 : $font-size-display-4 * $the-display-type-scale;
	$font-size-display-2 : $font-size-display-3 * $the-display-type-scale;
	$font-size-display-1 : $font-size-display-2 * $the-display-type-scale;

	// Add the created font sizes to the elements and classes
	.display-4 { font-size: $font-size-display-4; }
	.display-3 { font-size: $font-size-display-3; }
	.display-2 { font-size: $font-size-display-2; }
	.display-1 { font-size: $font-size-display-1; }
	
}

// Create the base heading and display font sizes to be used
// from 0px width viewports and up.
// These can be adjusted through the use of media queries
// by simply using the mixin again at your desired breakpoint

// Set the root font size in px on the html element to 14px,
// so that it is 2px lower that the aprox default for browsers.
// Then the font size is bumped up 2px at the md and then lg
// breakpoints.
html {
	font-size: 14px;
	@media (min-width: 768px) {
		font-size: 16px;
	}
	@media (min-width: 992px) {
		font-size: 18px;
	}
}

// Create the heading font sizes
@include create-heading-type-scale($heading-type-scale-base);

// Create the display font sizes
@include create-display-type-scale($display-type-scale-base);

// At the Bootstrap md breakpoint, adjust the heading dont sizes.
@media (min-width: 768px) {
	@include create-heading-type-scale(minor-third);
}
              
            
!

JS

              
                
              
            
!
999px

Console