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.
<div class="grid">
<div class="grid__col--12">
12 Columns
</div>
</div>
<div class="grid">
<div class="grid__col--6">
6 Columns
</div>
<div class="grid__col--6">
6 Columns
</div>
</div>
<div class="grid">
<div class="grid__col--4">
4 Columns
</div>
<div class="grid__col--4">
4 Columns
</div>
<div class="grid__col--4">
4 Columns
</div>
</div>
<div class="grid">
<div class="grid__col--5">
5 Columns
</div>
<div class="grid__col--5">
5 Columns
</div>
<div class="grid__col--2">
2 Columns
</div>
</div>
<!-- semantic version -->
<h2>Semantic Code Below</h2>
<div class="home">
<div class="home__left">
Content
</div>
<div class="home__center">
Content
</div>
<div class="home__right">
Content
</div>
</div>
/* file structure
base
_base.scss
_index.scss
_reset.scss
layout
_extends.scss
_grid-columns.scss
_grid-container.scss
_index.scss
_panel.scss
modules
_buttons.scss
_extends.scss
_forms.scss
_icons.scss
_img.scss
_index.scss
_nav.scss
_navbar.scss
states
_index.scss
utilities
_config.scss (ie variables)
_functions.scss
_helpers.scss
_index.scss
_mixins.scss
application (final import file)
*/
/* naming conventions
BEM - block, element, modifier
.block {
&__element {
border:2px solid red;
&--modifier {
border: none;
}
}
}
*/
// ==========================================================================
// Folder - Utilities
// ==========================================================================
// ==========================================================================
// Global Config
// ==========================================================================
// Font Stacks
$font-url--google : 'https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900';
$font-family--primary : 'Lato', 'Helvetica Neue', Helvetica, Arial, sans-serif;
$font-family--secondary : 'Helvetica Neue', Helvetica, Arial, sans-serif;
// Font Weights
$font-weight--thin : 100;
$font-weight--light : 300;
$font-weight--medium : 400;
$font-weight--bold : 700;
$font-weight--ultra-bold : 900;
// Descriptive Base Colors
$white : #fff;
$black : #0b0b0b;
$grey : #797e83;
$fountain-blue : #52bab3;
$emerald : #5ece7f;
$sunglo : #e67478;
$coral : #ff784f;
$purple-majesty : #9279c3;
$scooter : #39add1;
// Color Usage
$color-primary : $fountain-blue;
$color-secondary : $scooter;
$color-accent : $emerald;
$color-shadow : rgba($black, .2);
// Color Palette Modifiers
$color-palettes: (
grey: (
xx-light : lighten($grey, 43%),
x-light : lighten($grey, 35%),
light : lighten($grey, 12%),
base : $grey,
dark : darken($grey, 8%),
x-dark : darken($grey, 16%)
),
black: (
light : lighten($black, 10%),
base : $black,
dark : darken($black, 10%)
)
);
// UI Colors
$ui-colors: (
default : $fountain-blue,
success : $emerald,
error : $sunglo,
warning : $coral,
info : $purple-majesty
);
// Text
$basefont: 16;
$base__font-size : 16px;
$base__line : 24px;
$letter-space : 1px;
// Border radius
$br--default : .4em;
$br--round : 50%;
// Transitions
$trns-duration : .3s;
// Path to Assets
$path--rel : "../img";
// Grid
$g-col-width : 65px;
$g-gutter-width : 20px;
$g-col-count : 12;
$g-cont-max-w : 1050px;
//breakpoints - variables file
$break-xs: 360px; //em(360);
$break-sm: 480px; //em(480);
$break-md: 767px; //em(767);
$break-lg: 992px; //em(992);
$break-xlg: 1200px; //em(1200);
// ==========================================================================
// Functions
// ==========================================================================
//PX to EM function - function file
@function em($pixels, $context: $basefont) {
@return #{$pixels/$context}em
}
// Import if Google Fonts URL is defined
@if variable-exists(font-url--google) {
@import url($font-url--google);
}
// Calculate em values
@function em($target, $context: $base__font-size) {
@return ($target / $context) * 1em;
}
// Call the color palette modifiers in color values
@function palette($palette, $shade: 'base') {
@return map-get(map-get($color-palettes, $palette), $shade);
}
// Set the "context" width for the grid
@function g-context($g-col-width, $g-col-count ,$g-gutter-width) {
$g-context: ($g-col-width * $g-col-count) + ($g-gutter-width * ($g-col-count - 1));
@return $g-context;
}
// ==========================================================================
// Helpers
// ==========================================================================
// Clearfix
%clearfix {
&:after {
content: "";
display: table;
clear: both;
}
}
// Screen reader text
.srt {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
// Center alignment
%center-align {
text-align: center;
}
// For pseudo-elements
%pseudos {
display: block;
content: '';
position: absolute;
}
// Center elements
.centered {
float: none;
margin-left: auto;
margin-right: auto;
}
// ==========================================================================
// Mixins
// ==========================================================================
// breakpoint mixin - mixins file
@mixin breakpoint($media) {
@if $media == mobile-portrait {
@media only screen and (max-width:$break-xs) { @content; }
}
@if $media == mobile-landscape {
@media only screen and (min-width:$break-xs + 1) and (max-width: $break-sm) { @content; }
}
@if $media == tablet-portrait {
@media only screen and (min-width:$break-sm + 1) and (max-width: $break-md) { @content; }
}
@if $media == tablet-landscape {
@media only screen and (min-width:$break-md + 1) and (max-width: $break-lg) { @content; }
}
@if $media == desktop {
@media only screen and (min-width:$break-lg + 1) and (max-width: $break-xlg) { @content; }
}
@if $media == desktop-large {
@media only screen and (min-width:$break-xlg) { @content; }
}
}
// BEM selectors
@mixin e($element) {
&__#{$element} {
@content;
}
}
@mixin m($modifier) {
&--#{$modifier} {
@content;
}
}
// Generate modifier color classes
@mixin bg-colors($map) {
@each $theme, $color in $map {
&--#{$theme} {
background-color: $color;
}
}
}
// Generating :before or :after pseudo-element shapes
@mixin p-el(
$el,
$el-w: null,
$el-h: null) {
@if $el == "before" or $el == "after" {
&:#{$el} {
@extend %pseudos;
width: $el-w;
height: $el-h;
@content;
}
}
@else {
@error "`#{$el}` is not a valid pseudo-element.";
}
}
// Image replacement
@mixin img-replace($img, $w, $h, $disp: block) {
background-image: url('#{$path--rel}/#{$img}');
background-repeat: no-repeat;
width: $w;
height: $h;
display: $disp;
}
// Adjacent sibling margins
@mixin doubly($margin: 1em) {
& + & {
margin-left: $margin;
@content;
}
}
// semantic grid
@mixin semantic-grid() {
@extend .grid;
@content;
}
@mixin semantic-grid-column($i) {
@extend .grid__col--#{$i};
@extend [class^="grid__col--"];
@content;
}
// ==========================================================================
// Folder - Layout
// ==========================================================================
// ==========================================================================
// Placeholders
// ==========================================================================
// Panel
%panel-default {
padding-top: em(30px);
padding-bottom: em(20px);
}
%panel-padding {
padding-top: em(80px);
padding-bottom: em(34px);
}
// ==========================================================================
// Grid Container
// ==========================================================================
.grid {
@extend %clearfix;
@extend .centered;
width: 100%;
background:blue;
margin-top:20px;
color:white;
// make nested grid 100%
[class*="grid__col--"] > & {
width:100%;
//width:90%;
}
// set a max width grid container
@media (min-width: 1100px) {
max-width:1600px;
}
}
// ==========================================================================
// Grid Columns
// ==========================================================================
// Calculate grid columns
@media (min-width: 769px) {
@for $i from 1 through $g-col-count {
$context: g-context($g-col-width, $g-col-count ,$g-gutter-width) !global;
$target: ($g-col-width * $i) + ($g-gutter-width * ($i - 1));
// Generate column modifier classes
.grid__col--#{$i} {
width: percentage($target / $context);
background:red;
}
}
}
// Column styles
[class^="grid__col--"] {
@media (min-width: 1px) and (max-width: 768px) {
margin-top: em(12px);
margin-bottom: em(12px);
}
@media (min-width: 769px) {
@include doubly(percentage($g-gutter-width / $context));
float: left;
min-height: 1px;
//padding-left: 10px;
//padding-right: 10px;
&:last-of-type {
float: right;
}
}
}
// ==========================================================================
// Panels
// ==========================================================================
.panel {
@extend %panel-default;
@include m(centered) {
@extend %panel-default;
@extend %center-align;
}
@include m(padded) {
@extend %panel-padding;
@include m(centered) {
@extend %center-align;
@extend %panel-padding;
}
}
}
// ==========================================================================
// Semantic Grid @extend examples
// ==========================================================================
.home {
@include semantic-grid();
}
.home__left {
@include semantic-grid-column(8);
}
.home__center {
@include semantic-grid-column(2);
}
.home__right {
@include semantic-grid-column(2);
}
// ==========================================================================
// Semantic Grid Media Querie examples
// ==========================================================================
body {
// em function
font-size: em(16px);
// declaring breakpoint mixins
@include breakpoint(mobile-portrait) {
background:red;
}
@include breakpoint(mobile-landscape) {
background:blue;
}
@include breakpoint(tablet-portrait) {
background:green;
}
@include breakpoint(tablet-landscape) {
background:orange;
}
@include breakpoint(desktop) {
background:purple;
}
@include breakpoint(desktop-large) {
background:violet;
}
}
Also see: Tab Triggers