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.
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<div class="frame">
<div class="center">
<div class="notification -danger">
<div class="notification__content">
<i class="notification__icon fas fa-exclamation-circle"></i>
<h3 class="notification__title">Oh snap!</h3>
<p class="notification__text">
An error has occured while creating an error report.
</p>
</div>
<button class="notification__button">
Dismiss
</button>
</div>
</div>
<div class="colors">
<a href="#" data-status="-danger" class="-active"></a>
<a href="#" data-status="-warning"></a>
<a href="#" data-status="-success"></a>
<a href="#" data-status="-info"></a>
</div>
</div>
// delete the following line if no text is used
// edit the line if you wanna use other fonts
@import url(https://fonts.googleapis.com/css?family=Open+Sans:700,600,300);
:root {
--color-info : #34b5f0;
--color-success : #31e284;
--color-warning : #f0a834;
--color-danger : #ff3f3f;
--color-notification : white;
--color-dark : #131821;
}
html { font-size : 62.5%; }
body { font-size : 1.6rem; }
// use only the available space inside the 400x400 frame
.frame {
position: absolute;
top: 50%;
left: 50%;
width: 400px;
height: 400px;
margin-top: -200px;
margin-left: -200px;
border-radius: 2px;
box-shadow: 4px 8px 16px 0 rgba(0,0,0,0.1);
overflow: hidden;
background: var( --color-dark );
color: #333;
font-family: 'Open Sans', Helvetica, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.notification {
$this : &;
// Variables
--padding : 3rem 4rem 1rem 4rem;
--color : var( --color-info );
--bezier : cubic-bezier( .75,.21,.25,.78 );
position : relative;
text-align : center;
width : 30rem;
background-color : var( --color-notification );
box-shadow : 0px 10px 10px black;
border-radius : 5px;
// Transition
transition : transform .5s ease .4s;
// Tranform
transform-origin : 50% 0%;
transform : scaleY( 0 );
// Notification styles
&.-danger { --color : var( --color-danger ); }
&.-info { --color : var( --color-info ); }
&.-success { --color : var( --color-success ); }
&.-warning { --color : var( --color-warning ); }
// Actions
&.-open {
transition : all .5s ease;
transform-origin : 50% 50%;
transform : scale( 1 );
&::before {
transition : all .4s var( --bezier ) .4s;
transform : scaleY( 0 );
}
#{$this}__button {
color : #fff;
transition : color .3s ease .8s, background-color .3s ease;
}
}
// Overlay
&::before {
content : "";
position : absolute;
top : 0;
left : 0;
width : 100%;
height : 100%;
z-index : 1;
transform-origin : 0% 100%;
transition : all .5s var( --bezier );
background : var( --color );
border-radius : 5px;
}
&__content {
box-sizing : border-box;
padding : var( --padding );
width : 100%;
margin : 0 auto;
}
&__icon {
font-size : 5.2rem;
color : var( --color );
margin-bottom : 2rem;
transition : color .3s ease;
}
&__title, &__text, &__icon {
margin-top : 0;
}
&__title {
font-weight : 600;
margin-bottom : 1rem;
}
&__text {
color : var( --color-dark );
font-size : 1.4rem;
}
&__button {
background : var( --color );
color : var( --color );
width : 100%;
border : none;
padding : 1.4rem 2rem;
font-size : 1.4rem;
font-weight : 600;
transition : color .3s ease, background-color .3s ease;
cursor : pointer;
outline : none;
position : relative;
top : 1px;
border-bottom-left-radius : 5px;
border-bottom-right-radius : 5px;
}
}
.colors {
position : absolute;
bottom : 1rem;
left : 0;
width : 100%;
display : flex;
align-items : center;
justify-content : center;
flex-flow : row nowrap;
a {
--color : var( --color-danger );
width : 1.6rem;
height : 1.6rem;
display : block;
margin : .5rem;
background : var( --color );
border-radius : 50%;
transition : box-shadow .3s ease;
&[data-status="-warning"] {
--color : var( --color-warning );
}
&[data-status="-success"] {
--color : var( --color-success );
}
&[data-status="-info"] {
--color : var( --color-info );
}
&.-active {
box-shadow : 0 0 4px 2px var( --color );
}
}
}
// jQuery v3.3.1 is supported
jQuery( function( $ ) {
// Notification element
var _notification = $( '.notification' );
// Notification icon
var _nIcon = $( '.notification__icon' );
// Notification title
var _nTitle = $( '.notification__title' );
// Notification text
var _nText = $( '.notification__text' );
// Notification button
var _button = $( '.notification__button' );
// Statuses
var _statuses = $( '.colors a' );
// Notification button click
_button.click( function( event ) {
event.preventDefault( );
_notification.removeClass( '-open' );
autoOpen( );
})
// On status click
_statuses.click( function( event ) {
event.preventDefault( );
// Get the color
var _status = $( this ).data( 'status' );
// Check if status found
if( !_status.length )
return;
_statuses.removeClass( '-active' );
// Check if open
var _open = _notification.hasClass( '-open' );
// Remove all classes besides the notification class
_notification.attr( 'class', 'notification' + ( _open ? ' -open' : '' ) );
// Add the status
_notification.addClass( _status );
// Change text
var _title = 'Oh snap!';
var _text = 'An error has occured while creating an error report.';
var _buttonText = 'Dismiss';
var _icon = 'fas fa-exclamation-circle';
switch( _status ) {
case '-warning' :
_title = 'Invalid data provided';
_text = 'You have provided invalid data when submitting a form';
_buttonText = 'Let\'s fix it';
_icon = 'fas fa-exclamation-triangle';
break;
case '-info' :
_title = 'Hey there!';
_text = 'When accessing the hidden data you should enable some options';
_buttonText = 'Got it!';
_icon = 'fas fa-info-circle';
break;
case '-success' :
_title = 'Success!';
_text = 'Your profile was succesfully updated and new data will appear on your timeline.';
_buttonText = 'Thank you!';
_icon = 'far fa-check-circle';
break;
}
_nTitle.text( _title );
_nText.text( _text );
_button.text( _buttonText );
_nIcon.attr( 'class', 'notification__icon ' + _icon );
$( this ).addClass( '-active' );
});
// Auto open notification
function autoOpen( $ms = 2000 ) {
setTimeout( function( ) {
_notification.addClass( '-open' );
}, $ms );
}
autoOpen( 300 );
});
Also see: Tab Triggers