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="content">
<div class="section">
<h2>Default Buttons</h2>
<div class="section-content">
<button>Hello</button>
<button class="primary">Click me</button>
<button class="accent focus-me">Focused</button>
<button>
<i class="material-icons">local_pizza</i>
Gimme pizza
</button>
<a class="md-button success" href="https://material.io/guidelines/components/buttons.html#buttons-button-types" target="_blank">I'm a link</a>
<button disabled>Disabled</button>
</div>
</div>
<div class="section">
<h2>Stroke Buttons</h2>
<div class="section-content">
<button class="md-stroke">Many buttons</button>
<button class="primary md-stroke">wow</button>
<button class="accent md-stroke">much ripple</button>
<button class="md-stroke">
<i class="material-icons">cake</i>
Gimme cake
</button>
<a class="md-button md-stroke success" href="https://material.io/guidelines/components/buttons.html#buttons-button-types" target="_blank">very goog</a>
<button class="md-stroke" disabled>no click 4 u</button>
</div>
</div>
<div class="section">
<h2>Icon Buttons</h2>
<div class="section-content">
<button class="md-icon-button">
<i class="material-icons">cake</i>
</button>
<button class="md-icon-button primary">
<i class="material-icons">favorite</i>
</button>
<button class="md-icon-button accent">
<i class="material-icons">local_pizza</i>
</button>
<button class="md-icon-button accent" disabled>
<i class="material-icons">accessible</i>
</button>
</div>
</div>
<div class="section">
<h2>Raised Buttons</h2>
<div class="section-content">
<div>
<button class="raised">Good heavens</button>
<button class="raised primary">Hey there</button>
<button class="raised accent">Click for hugs</button>
<button class="raised">
<i class="material-icons">favorite_border</i>
Love me
</button>
<button class="raised" disabled>Aw shucks</button>
</div>
<div>
<button class="md-icon-button raised">
<i class="material-icons">cake</i>
</button>
<button class="md-icon-button primary raised">
<i class="material-icons">favorite</i>
</button>
<button class="md-icon-button accent raised">
<i class="material-icons">local_pizza</i>
</button>
<button class="md-icon-button accent raised" disabled>
<i class="material-icons">android</i>
</button>
</div>
</div>
</div>
<div class="section">
<h2>FAB Buttons</h2>
<div class="section-content">
<button class="md-fab">
<i class="material-icons">settings</i>
</button>
<button class="md-fab primary">
<i class="material-icons">close</i>
</button>
<button class="md-fab accent">
<i class="material-icons">pets</i>
</button>
<button class="md-fab accent" disabled>
<i class="material-icons">local_bar</i>
</button>
</div>
</div>
<div class="section">
<h2>Disable Button Ripple</h2>
<div class="section-content">
<button class="accent" data-no-ripple="true">Aw no fun</button>
</div>
</div>
<div class="section">
<h2>Add Ripples to Anything!</h2>
<div class="section-content">
<div class="ripple-image">
<img src="//images-na.ssl-images-amazon.com/images/I/81-yKbVND-L.png" />
</div>
</div>
</div>
<div class="section">
<h2>Custom Ripple Color</h2>
<div class="section-content">
<button class="party-button raised" data-ripple-color="#E91E63">Party time</button>
</div>
</div>
</div>
/**
* Variables
**/
@button-raised-default__background-color: @light-color;
@button__border-radius: 2px;
@button__font-family: "Roboto Slab", "Roboto", "Roboto Mono", "Roboto",
"sans-serif";
@button__font-size: 14px;
@button__font-weight: 500;
@button__line-height: 36px;
@button__margin: 8px;
@button-icon__font-size: 24px;
@icon-font__line-height: 40px;
@swift-ease-out: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
@transition-timing: cubic-bezier(0.25, 0.8, 0.25, 1);
@whiteframe-shadow-2dp: 0px 1px 5px 0px rgba(0, 0, 0, 0.2),
0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12);
@whiteframe-shadow-4dp: 0px 2px 4px -1px rgba(0, 0, 0, 0.2),
0px 4px 5px 0px rgba(0, 0, 0, 0.14), 0px 1px 10px 0px rgba(0, 0, 0, 0.12);
/** Colors **/
// Font Dark
@primary-dark-color: rgba(0, 0, 0, 0.87);
@secondary-dark-color: rgba(0, 0, 0, 0.54);
@disabled-dark-color: rgba(0, 0, 0, 0.38);
@inactive-dark-color: rgba(0, 0, 0, 0.24);
@divider-dark-color: rgba(0, 0, 0, 0.12);
// Font Light
@primary-light-color: rgb(255, 255, 255);
@secondary-light-color: rgba(255, 255, 255, 0.7);
@disabled-light-color: rgba(255, 255, 255, 0.5);
@inactive-light-color: rgba(255, 255, 255, 0.24);
@divider-light-color: rgba(255, 255, 255, 0.12);
// Theme
@primary-color: #673ab7;
@secondary-color: #d32f2f;
@accent-color: #2979ff;
@light-color: #fafafa;
@base-color: #f5f5f5;
@dark-color: #424242;
@success-color: #00c853;
@warn-color: #ff6d00;
@error-color: #d50000;
//Social Media
@facebook-blue: #3b5999;
@twitter-blue: #55acee;
@linkedin-blue: #0077b5;
@tumblr-blue-grey: #34465d;
@googleplus-red: #dd4b39;
@pinterest-red: #bd081c;
@youtube-red: #cd201f;
@reddit-orange: #ff5700;
@whatsapp-green: #25d366;
@instagram-pink: #e4405f;
@behance-black: #131418;
@snapchat-yellow: #fffc00;
// For mixin use (i.e. generating button themes)
// css-class-name, color
@theme-colors: primary @primary-color, secondary @secondary-color,
accent @accent-color, success @success-color, error @error-color,
behance-black @behance-black, facebook-blue @facebook-blue,
googleplus-red @googleplus-red, snapchat-yellow @snapchat-yellow,
reddit-orange @reddit-orange, twitter-blue @twitter-blue;
/**
* Styles
**/
/////////////////////////////
// Button Styles
button,
a.md-button {
.button-base-styles();
&:not([disabled]) {
&.raised {
box-shadow: @whiteframe-shadow-2dp;
background-color: @button-raised-default__background-color;
&:active {
box-shadow: @whiteframe-shadow-4dp;
}
}
.button-theme(@theme-colors);
}
&.md-icon-button {
border-radius: 50%;
display: inline-block;
width: @icon-font__line-height;
height: @icon-font__line-height;
letter-spacing: 0;
min-width: @icon-font__line-height;
text-overflow: clip;
.material-icons {
font-size: @button-icon__font-size;
line-height: @icon-font__line-height;
}
}
&.md-fab {
box-shadow: @whiteframe-shadow-2dp;
width: 56px;
height: 56px;
letter-spacing: 0;
min-width: 56px;
border-radius: 50%;
&:not([disabled]) {
background-color: @button-raised-default__background-color;
color: contrast(
@button-raised-default__background-color,
@primary-dark-color,
@primary-light-color
);
&:active {
box-shadow: @whiteframe-shadow-4dp;
background-color: contrast(
shade(@button-raised-default__background-color, 12%),
shade(@button-raised-default__background-color, 12%),
tint(@button-raised-default__background-color, 12%)
);
}
&:hover,
&:focus {
background-color: shade(@button-raised-default__background-color, 12%);
}
}
.material-icons {
line-height: 56px !important;
}
&.mini {
width: 40px;
height: 40px;
min-width: 40px;
.material-icons {
line-height: 40px !important;
}
}
}
&[disabled] {
&.raised,
&.md-fab {
background-color: @divider-dark-color;
}
.md-ripple-container {
svg circle {
opacity: 0 !important;
}
}
}
&:not(.md-icon-button):not(.md-fab):not(.raised) {
&.md-stroke {
box-shadow: 0 0 0 1px @divider-dark-color;
}
}
}
.button-base-styles() {
-webkit-tap-highlight-color: transparent;
align-items: center;
background-color: transparent;
border: none;
border-radius: @button__border-radius;
transition: @swift-ease-out;
user-select: none;
border-radius: @button__border-radius;
color: @primary-dark-color;
display: inline-flex;
font-size: @button__font-size;
font-weight: @button__font-weight;
height: @button__line-height;
justify-content: center;
letter-spacing: 0.1em;
line-height: @button__line-height;
margin: @button__margin;
min-width: 64px;
outline: none;
overflow: hidden;
padding: 0 0;
position: relative;
text-align: center;
text-decoration: none;
text-overflow: ellipsis;
text-transform: uppercase;
vertical-align: middle;
white-space: nowrap;
&:not([disabled]) {
box-shadow: none;
cursor: pointer;
&:hover,
&:focus {
background-color: rgba(0, 0, 0, 0.12);
}
}
&[disabled] {
color: @disabled-dark-color;
pointer-events: none;
.material-icons {
color: @disabled-dark-color;
}
}
&:not(.md-fab):not(.md-icon-button):not(.raised):not(.md-stroke),
&.raised:not(.md-icon-button):not(.md-fab),
&.md-stroke {
i:first-child {
font-size: 18px;
height: 18px;
margin: 0 8px 0 0;
min-height: 18px;
min-width: 18px;
width: 18px;
}
}
&:not(.md-fab):not(.md-icon-button):not(.raised):not(.md-stroke) {
padding: 0 8px;
i:first-child {
margin-left: 0;
}
}
&.raised:not(.md-icon-button):not(.md-fab),
&.md-stroke {
padding: 0 16px;
i:first-child {
margin-left: -4px;
}
}
}
.button-theme(@theme) {
.loop(length(@theme));
.loop(@index) when(@index > 0) {
@themeSet: extract(@theme, @index);
@type: extract(@themeSet, 1);
@color: extract(@themeSet, 2);
&.@{type} {
color: @color;
&:active,
&:focus {
background-color: fade(@color, 20%);
}
.md-ripple-container {
svg circle {
fill: @color;
}
}
&.raised,
&.md-fab {
background-color: @color;
&:hover,
&:focus {
background-color: shade(@color, 12%);
}
&:active {
background-color: contrast(
shade(@color, 12%),
shade(@color, 12%),
tint(@color, 12%)
);
}
.md-ripple-container {
svg circle {
fill: contrast(shade(@color, 12%), #000, #fff);
}
}
}
&.raised,
&.md-fab {
color: contrast(
shade(@color, 12%),
@primary-dark-color,
@primary-light-color
);
}
}
.loop(@index - 1);
}
}
.md-ripple-active {
transition: @swift-ease-out;
position: relative;
overflow: hidden;
background-clip: padding-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
.md-ripple-container {
pointer-events: none;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
position: absolute;
background-clip: padding-box;
overflow: hidden;
-webkit-mask-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC");
.md-ripple,
.md-focus {
transition-duration: 0.8s;
transition-timing-function: @transition-timing;
transition-property: opacity, transform;
border-radius: 50%;
position: absolute;
top: 0;
left: 0;
margin: 0;
}
.md-focus {
animation: focusPulse 2.5s infinite;
left: 50%;
top: 50%;
}
}
.md-ripple-container {
border-radius: 2px;
}
&.md-icon-button,
&.md-fab {
.md-ripple-container {
border-radius: 50%;
}
}
&:not([disabled]) {
.md-ripple-container {
svg {
fill: #000000;
fill-opacity: 0.16;
}
}
}
}
// Focus animation
@keyframes focusPulse {
.pulseFrames;
}
.pulseFrames() {
0% {
transform: translate(-50%, -50%) scale(1, 1);
}
50% {
transform: translate(-50%, -50%) scale(0.9, 0.9);
}
100% {
transform: translate(-50%, -50%) scale(1, 1);
}
}
// Demo specific styles
body *,
button,
a {
font-family: @button__font-family;
}
h2 {
font-weight: 400;
line-height: 32px;
margin: 8px 0 0;
}
.content {
margin: auto;
text-align: center;
.section {
padding: 16px;
&-content {
padding: 16px 0 0;
}
}
}
.ripple-image {
display: inline-block;
img {
width: 160px;
height: auto;
}
}
.ripple-image {
cursor: pointer;
border-radius: 30px;
font-size: 0;
}
(function($){
"use strict";
$.fn.extend({
mdRipple: function(options){
options = $.extend({
// Default options
}, options);
var namespace = 'mdRipple',
coreClasses = {
button: 'md-ripple-active',
iconButton: 'md-icon-button',
container: 'md-ripple-container',
ripple: 'md-ripple',
focus: 'md-focus'
},
coreAttributes = {
color: 'ripple-color',
noRipple: 'no-ripple'
},
rippleTemplate = '<svg preserveAspectRatio="none" viewBox="25 25 50 50"><circle cx="50" cy="50" r="25"/></svg>',
mouseDown = false;
// General element actions
_initialize(this);
// Individual element actions
this.each(function(){
var elem = $(this);
elem.on(_namespaceEvents('mousedown'), _mouseDown);
elem.on(_namespaceEvents('focus'), _drawFocus);
elem.on(_namespaceEvents('blur'), _clearContainer);
});
return this;
/////////////////////////////////
function _initialize(elems){
// Unbind anything within plugin namespace to prevent duplicate event bindings
elems.off('.' + namespace);
_addRippleContainerTo(elems);
}
function _addRippleContainerTo(elem) {
var rippleContainer = elem.find('.' + coreClasses.container).get(0);
if (!rippleContainer) {
rippleContainer = document.createElement('div');
rippleContainer.className = coreClasses.container;
elem.addClass(coreClasses.button).append($(rippleContainer));
}
}
function _getMouseClickCoords(elem, e) {
var container = elem,
coords = {};
if (!e || elem.hasClass(coreClasses.iconButton)){
coords.x = container.outerWidth() / 2;
coords.y = container.outerHeight() / 2;
} else {
coords.x = e.pageX - container.offset().left;
coords.y = e.pageY - container.offset().top;
}
return coords;
}
function _mouseDown(e) {
var elem = $(this);
if (!mouseDown && !elem.is(":disabled") && !elem.data(coreAttributes.noRipple)) {
mouseDown = true;
var coords = _getMouseClickCoords(elem, e);
_removeFocus(elem);
_drawRipple(elem, coords);
}
e.preventDefault();
}
function _drawRipple(elem, coords) {
var container = elem.find('.' + coreClasses.container).first(),
color = elem.data(coreAttributes.color),
ripple = $(rippleTemplate),
containerDims = {
width: container.outerWidth(),
height: container.outerHeight()
},
initialDiameter = (containerDims.width > containerDims.height ? containerDims.width : containerDims.height) * .5,
greatestWidth, greatestHeight, diameter = 1, scale = 1,
vm = this;
ripple.addClass(coreClasses.ripple).css({
'fill': !!color ? color : '',
'transform': 'translate(' + coords.x + 'px, ' + coords.y + 'px) translate(-50%, -50%)',
'opacity': .5,
'width': initialDiameter,
'height': initialDiameter
});
container.append(ripple);
if(coords.x >= containerDims.width / 2){
greatestWidth = coords.x;
}
else{
greatestWidth = containerDims.width - coords.x;
}
if(coords.y >= containerDims.height / 2){
greatestHeight = coords.y;
}
else{
greatestHeight = containerDims.height - coords.y;
}
diameter = Math.sqrt(Math.pow(greatestWidth, 2) + Math.pow(greatestHeight, 2)) * 2.05;
scale = (diameter / initialDiameter);
// Forces the browser to calculate an actual value
ripple.css('opacity');
ripple.css('transform');
ripple.css({
'opacity': 1,
'transform': 'translate(' + coords.x + 'px,' + coords.y + 'px) translate(-50%,-50%) scale(' + scale + ')'
});
elem.bind(_namespaceEvents('mouseup mouseleave'), function(e){
mouseDown = false;
_hideRipple(ripple);
$(this).unbind(_namespaceEvents('mouseup mouseleave'));
});
}
function _drawFocus(){
var elem = $(this);
if(!elem.is(":active")) {
var container = elem.find('.' + coreClasses.container).first(),
color = elem.data(coreAttributes.color),
ripple = $(rippleTemplate),
coords = _getMouseClickCoords(elem);
// Destroy all previous instances of focus ripple
container.find('.' + coreClasses.focus).remove();
ripple.addClass(coreClasses.focus).css({
'fill': !!color ? color : '',
'transform': 'translate(' + coords.x + 'px, ' + coords.y + 'px) translate(-50%,-50%)',
'width': coords.x * 2 * .9,
'height': coords.x * 2 * .9
});
container.append(ripple);
}
}
function _hideRipple(elem) {
elem.css('opacity', 0);
elem.one(_namespaceEvents('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'), function() {
$(this).remove();
});
}
function _removeFocus(elem) {
elem.find('.' + coreClasses.container + ' .' + coreClasses.focus).remove();
}
function _clearContainer() {
$(this).find('.' + coreClasses.container).find('.' + coreClasses.focus + ', .' + coreClasses.ripple).remove();
}
function _namespaceEvents(eventString) {
return eventString.trim().split(/\s+/).map(function(a){ return a + '.' + namespace; }).reduce(function(a, b){ return a + ' ' + b });
}
}
});
})(jQuery);
(function(){
$(document).ready(function(){
$('button, a.md-button, .ripple-image').mdRipple();
$('.party-button').on('click focus', function(){
$(this).data('ripple-color', '#' + ("000000" + Math.random().toString(16).slice(2, 8).toUpperCase()).slice(-6));
});
$('.focus-me').focus();
});
})();
Also see: Tab Triggers