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.
<blockquote class="random-quote">
<p id="new-quote"></p>
<cite id="author"></cite>
</blockquote>
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/*************************************************************************************************************************/
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #23074d; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #cc5333, #23074d); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #cc5333, #23074d); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
.random-quote {
-webkit-filter: drop-shadow(-1px -1px 2px rgba(0, 0, 0, 0.1)) drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.15));
filter: drop-shadow(-1px -1px 2px rgba(0, 0, 0, 0.1)) drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.15));
margin: 1rem;
margin-bottom: 40px;
position: relative;
font-family: 'Montserrat', sans-serif;
font-size: 1.2rem;
font-weight: 400;
background: #C95233;
color: white;
max-width: 40vw;
line-height: 1.4;
}
#new-quote {
padding: 1.5rem 2rem;
cursor: pointer;
min-width: 10vw;
display: flex;
}
p#new-quote {
justify-content: center;
}
.random-quote::before {
border: 12.5px solid transparent;
border-top: 12.5px solid #C95233;
border-bottom: 0;
height: 0;
width: 0;
border-top-width: 25px;
content: '';
display: block;
position: absolute;
left: 3rem;
bottom: -25px;
-webkit-transform-origin: center;
transform-origin: center;
-webkit-transform: rotate(90deg) skew(-25deg) translateY(16.6666666667px);
transform: rotate(90deg) skew(-25deg) translateY(16.6666666667px);
}
.random-quote cite {
position: absolute;
bottom: -2rem;
left: 4.5rem;
font-size: 1rem;
font-style: normal;
font-weight: 300;
letter-spacing: 0.5px;
color: white;
}
/*
Random Quote Generator - Pulls a random from the array of quotes
*/
let quoteArray = [
{
content: "Let's get crazy!",
author: "Bob Ross"
},
{
content: "Wash the brush, just beats the devil out of it!",
author: "Bob Ross"
},
{
content: "Nah.",
author: "Rosa Parks"
},
{
content: "That is the key to navigating this life — don't take it too seriously. That's when the party begins.",
author: "Ru Paul"
},
{
content: "May the forces of evil become confused on the way to your house",
author: "George Carlin"
},
{
content: "Just cause you got the monkey off your back doesn't mean the circus has left town.",
author: "George Carlin"
},
{
content: "Life is 10% what happens to you and 90% how you react to it.",
author: "Charles R. Swindoll"
},
{
content: "Cynicism masquerades as wisdom, but it is the furthest thing from it. Because cynics don't learn anything. Because cynicism is a self-imposed blindness: a rejection of the world because we are afraid it will hurt us or disappoint us. Cynics always say 'no.' But saying 'yes' begins things. Saying 'yes' is how things grow.",
author: "Stephen Colbert"
},
{
content: "You can't really be passionately moderate. It's like wearing an 'Extra Medium' - it doesn't exist.",
author: "Stephen Colbert"
},
{
content: "There's an old saying about those who forget history. I don't remember it, but it's good.",
author: "Stephen Colbert"
},
{
content: "The Internet is just a world passing around notes in a classroom.",
author: "Jon Stewart"
},
{
content: "Confidence is 10% hard work and 90% delusion.",
author: "Tina Fey"
},
{
content: "The evil that is in the world almost always comes of ignorance, and good intentions may do as much harm as malevolence if they lack understanding.",
author: "Albert Camus"
},
{
content: "Blessed are the hearts that can bend; they shall never be broken.",
author: "Albert Camus"
}
];
//Setup html elements
let button = document.getElementById('new-quote'),
quote = document.getElementById('new-quote'),
author = document.getElementById('author');
//Generate a Random Quote
window.onload = randomQuote;
button.addEventListener('click', randomQuote);
//Random quote function
function randomQuote (){
//Get a random number to pick a random quote object
const random = Math.floor(Math.random() * quoteArray.length);
//Get the quote content
quote.innerHTML = quoteArray[random].content;
//Get the quote author
author.innerHTML = '— ' + quoteArray[random].author;
}
Also see: Tab Triggers