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.
<!-- Content wrapper -->
<div class="wrapperOutside">
<div class="wrapperInside">
<!-- Dialog -->
<div class="dialogContainer">
<!-- Dialog title and body -->
<div class="dialogContent">
<div class="dialogContentTitle">Use Google's location service?</div>
<div class="dialogContentBody">Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.</div>
</div>
<!-- Dialog action bar -->
<div class="dialogActionBar">
<!-- Buttons -->
<a class="buttonTouchTarget" id="buttonOneTouchTarget" href="#">
<div class="buttonFlat" id="buttonOne" fit>DISAGREE</div>
</a><!-- This comment removes 4px gap between buttons
--><a class="buttonTouchTarget" id="buttonTwoTouchTarget" href="#">
<div class="buttonFlat" id="buttonTwo">AGREE</div>
</a>
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="javascript.js"></script>
body {
background-color: #9CCC65;
/* Remove space around window edge */
margin-top: 0;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
}
/*
The attributes below style the css
property transitions.
*/
div {
-webkit-transition-property: all;
-webkit-transition-duration: 0.2s;
-webkit-transition-timing-function: ease;
-webkit-transition-delay: 0s;
}
/*
The two classes below work together
to center the content vertically and
horizontally on the screen.
*/
.wrapperOutside {
display: table;
width: 100vw;
height: 100vh;
}
.wrapperInside {
display: table-cell;
text-align: center;
vertical-align: middle;
}
/*
The attributes below style the css
dialog window, and content.
*/
.dialogContainer {
/* Form */
width: 280px;
height: auto;
/*
Drop Shadow
a. Horizontal shadow
b. Vertical shadow
c. Blur
d. Spread
e. Color
*/
-webkit-box-shadow: 0 -2px 25px 0 rgba(0, 0, 0, 0.15), 0 13px 25px 0 rgba(0, 0, 0, 0.3);
background-color: #FFFFFF;
/* Internal padding */
padding-top: 0;
padding-left: 0;
padding-right: 0;
padding-bottom: 0;
/* External padding */
margin-top: 0;
margin-left: auto;
margin-right: auto;
margin-bottom: 0;
}
.dialogContent {
/* Form */
width: auto;
height: auto;
background-color: #FFFFFF;
/* Corner radius */
border-top-left-radius:2px;
border-top-right-radius:2px;
border-bottom-right-radius:0;
border-bottom-left-radius:0;
/* Internal padding */
padding-top: 21px;
padding-left: 24px;
padding-right: 24px;
padding-bottom: 12px;
/* External padding */
margin-top: 0;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
}
.dialogContentTitle {
/* Form */
background-color: #FFFFFF;
/* Typography */
font-family: 'Roboto', sans-serif;
font-weight: 500;
font-size: 20px;
color: rgba(0,0,0,.8);
line-height: 24px;
text-align: left;
letter-spacing: 0.03px;
/* Internal padding */
padding-top: 0;
padding-left: 0;
padding-right: 0;
padding-bottom: 0;
/* External padding */
margin-top: 0;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
}
.dialogContentBody {
/* Typography */
font-family: 'Roboto', sans-serif;
font-weight: 400;
font-size: 16px;
color: rgba(0,0,0,.5);
line-height: 24px;
text-align: left;
letter-spacing: 0.03px;
/* Internal padding */
padding-top: 14px;
padding-left: 0;
padding-right: 0;
padding-bottom: 0;
/* External padding */
margin-top: 0;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
}
.dialogActionBar {
/* Form */
width: auto;
height: 48px;
background-color: #FFFFFF;
text-align: right;
/* Corner radius */
border-top-left-radius:0;
border-top-right-radius:0;
border-bottom-right-radius:2px;
border-bottom-left-radius:2px;
/* Internal padding */
padding-top: 0;
padding-left: 16px;
padding-right: 15px;
padding-bottom: 8px;
/* External padding */
margin-top: 0;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
}
/*
The attributes below style the
hit target.
*/
.buttonTouchTarget {
display: inline-block;
background-color: rgba(0,0,0,0);
/* Remove grey background on link clicked in ios safari */
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
/*
The attributes below style the
flat button based on the Google
material design language.
*/
.buttonFlat {
/* Form */
display: inline-block;
height: 36px;
background-color: rgba(9,9,9,0);
/* Typography */
font-family: 'Roboto', sans-serif;
font-weight: 500;
font-size: 14px;
color: rgba(33,150,243,0.9);
line-height: 36px;
text-align: center;
letter-spacing: 0.4px;
/* Internal padding */
padding-top: 0;
padding-left: 8px;
padding-right: 8px;
padding-bottom: 0;
/* External padding – Touch target size */
margin-top: 6px;
margin-left: 4px;
margin-right: 4px;
margin-bottom: 6px;
}
/*
The code below will manage
the mouseover, onclick, and
mouseout events.
*/
// Capture touch capability
var touchEnabled = false;
//
// DIV BUTTON ONE
//
// First add the button id found in the html
var buttonOneTouchTarget = "buttonOneTouchTarget";
var buttonOne = "buttonOne";
// Declare function to manage mouse over event.
var buttonOneOnMouseOver = document.getElementById(buttonOneTouchTarget);
buttonOneOnMouseOver.onmouseover = function(){
console.log("Div button " + buttonOne + " on mouse over");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0.2)";
}
// Declare function to manage mouse down event.
var buttonOneOnMouseDown = document.getElementById(buttonOneTouchTarget);
buttonOneOnMouseDown.onmousedown = function(){
console.log("Div button " + buttonOne + " on mouse down");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0.4)";
}
// Declare function to manage mouse down event on iOS Safari
var buttonOneOnTouchStart = document.getElementById(buttonOneTouchTarget);
buttonOneOnTouchStart.ontouchstart = function(){
console.log("Div button " + buttonOne + " on touch start");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0.4)";
touchEnabled = true;
}
// Declare function to manage mouse up event.
var buttonOneOnMouseUp = document.getElementById(buttonOneTouchTarget);
buttonOneOnMouseUp.onmouseup = function(){
if(touchEnabled === false){
console.log("Div button " + buttonOne + " on mouse up" + " A");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0.2)";
}else{
console.log("Div button " + buttonOne + " on mouse up" + " B");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0)";
}
}
// Declare function to manage mouse on click event.
var buttonOneOnClick = document.getElementById(buttonOneTouchTarget);
buttonOneOnClick.onclick = function(){
if(touchEnabled === false){
console.log("Div button " + buttonOne + " on click" + " A");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0.2)";
}else{
console.log("Div button " + buttonOne + " on cick" + " B");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0)";
}
}
// Declare function to manage mouse out event.
var buttonOneOnMouseOut = document.getElementById(buttonOneTouchTarget);
buttonOneOnMouseOut.onmouseout = function(){
console.log("Div button " + buttonOne + " on mouse out");
document.getElementById(buttonOne).style.backgroundColor = "rgba(99,99,99,0)";
}
//
// DIV BUTTON TWO
//
// First add the button id found in the html
var buttonTwoTouchTarget = "buttonTwoTouchTarget";
var buttonTwo = "buttonTwo";
// Declare function to manage mouse over event.
var buttonTwoOnMouseOver = document.getElementById(buttonTwoTouchTarget);
buttonTwoOnMouseOver.onmouseover = function(){
console.log("Div button " + buttonTwo + " on mouse over");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0.2)";
}
// Declare function to manage mouse down event.
var buttonTwoOnMouseDown = document.getElementById(buttonTwoTouchTarget);
buttonTwoOnMouseDown.onmousedown = function(){
console.log("Div button " + buttonTwo + " on mouse down");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0.4)";
}
// Declare function to manage mouse down event on iOS Safari
var buttonTwoOnTouchStart = document.getElementById(buttonTwoTouchTarget);
buttonTwoOnTouchStart.ontouchstart = function(){
console.log("Div button " + buttonTwo + " on touch start");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0.4)";
touchEnabled = true;
}
// Declare function to manage mouse up event.
var buttonTwoOnMouseUp = document.getElementById(buttonTwoTouchTarget);
buttonTwoOnMouseUp.onmouseup = function(){
if(touchEnabled === false){
console.log("Div button " + buttonTwo + " on mouse up" + " A");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0.2)";
}else{
console.log("Div button " + buttonTwo + " on mouse up" + " B");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0)";
}
}
// Declare function to manage mouse on click event.
var buttonTwoOnClick = document.getElementById(buttonTwoTouchTarget);
buttonTwoOnClick.onclick = function(){
if(touchEnabled === false){
console.log("Div button " + buttonTwo + " on click" + " A");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0.2)";
}else{
console.log("Div button " + buttonTwo + " on cick" + " B");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0)";
}
}
// Declare function to manage mouse out event.
var buttonTwoOnMouseOut = document.getElementById(buttonTwoTouchTarget);
buttonTwoOnMouseOut.onmouseout = function(){
console.log("Div button " + buttonTwo + " on mouse out");
document.getElementById(buttonTwo).style.backgroundColor = "rgba(99,99,99,0)";
}
Also see: Tab Triggers