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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<h1>Quote Generator</h1>
<h3 id="intro">Hello! My name is Brent and I am a programmer. This app allows me to share some of my favorite quotes. Just click the button to have one of my favorite quotes randomly generated.</h3>
<div class="quoteBox">
<div id="quote"><p>Press the button below to fill me with one of Brent's favorite quotes!</p></div>
</div>
<div id="click"></div><div id="centered"><button onClick="showQuote()" id="getQuote">Get my first quote!</button>
</div></div>
h1 {
text-align: center;
}
#intro {
text-align: center;
}
.quoteBox {
padding: 15px;
text-align: center;
margin: auto;
width: 60%;
border-style: solid;
border-width: 1px;
border-radius: 35px;
}
#click {
text-align: center;
margin: auto;
}
#centered {
text-align: center;
margin: auto;
}
function showQuote() {
var index = Math.floor(Math.random() * 20);
switch(index) {
case 0: randQuote = "<p><i>We look forward to the time when the Power of Love will replace the Love of Power. Then will our world know the blessings of peace.</i></p><h3 style = 'text-align: right'>-William Ewart Gladstone</h3>";
break;
case 1: randQuote = "<p><i>When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment, and I told them they didn’t understand life.</i></p><h3 style = 'text-align: right'>-Anonymous</h3>";
break;
case 2: randQuote = "<p><i>Never doubt that a small group of thoughtful, committed citizens can change the world. Indeed, it’s the only thing that ever has.</i></p><h3 style = 'text-align: right'>-Margaret Mead</h3>";
break;
case 3: randQuote = "<p><i>People are illogical, unreasonable, and self-centered. Love them anyway.</i></p><h3 style = 'text-align: right'>-Kent M. Keith</h3>";
break;
case 4: randQuote = "<p><i>The next time you’re faced with something that’s unexpected, unwanted and uncertain, consider that it just may be a gift.</i></p><h3 style = 'text-align: right'>-Stacey Kramer</h3>";
break;
case 5: randQuote = "<p><i>To avoid criticism, say nothing, do nothing, be nothing.</i></p><h3 style = 'text-align: right'>-Fred Shero</h3>";
break;
case 6: randQuote = "<p><i>If opportunity doesn’t knock, build a door.</i></p><h3 style = 'text-align: right'>-Milton Berle</h3>";
break;
case 7: randQuote = "<p><i>I believe in the sacredness of a promise, that a man’s word should be as good as his bond; that character — not wealth or power or position — is of supreme worth.</i></p><h3 style = 'text-align: right'>-John D. Rockefeller (JR.)</h3>";
break;
case 8: randQuote = "<p><i>I don’t feel threatened by people who ask questions. It’s those who refuse to answer them that frighten me.</i></p><h3 style = 'text-align: right'>-Jason Bacchetta</h3>";
break;
case 9: randQuote = "<p><i>All our dreams can come true, if we have the courage to pursue them.</i></p><h3 style = 'text-align: right'>-Walt Disney</h3>";
break;
case 10: randQuote = "<p><i>As a well-spent day brings happy sleep, so a life well spent brings happy death.</i></p><h3 style = 'text-align: right'>-Leonardo Da Vinci</h3>";
break;
case 11: randQuote = "<p><i>Courage is contagious. When a brave man takes a stand, the spines of others are stiffened.</i></p><h3 style = 'text-align: right'>-Billy Graham</h3>";
break;
case 12: randQuote = "<p><i>Patience is something you admire in the driver behind you, but not in one ahead.</i></p><h3 style = 'text-align: right'>-Bill McGlashen</h3>";
break;
case 13: randQuote = "<p><i>Not everything that can be counted counts, and not everything that counts can be counted.</i></p><h3 style = 'text-align: right'>-William Bruce Cameron</h3>";
break;
case 14: randQuote = "<p><i>I never took a day off in my twenties. Not one.</i></p><h3 style = 'text-align: right'>-Bill Gates</h3>";
break;
case 15: randQuote = "<p><i>Perfection is not attainable, but if we chase perfection we can catch excellence.</i></p><h3 style = 'text-align: right'>-Vince Lombardi</h3>";
break;
case 16: randQuote = "<p><i>What lies behind us and what lies before us are tiny matters compared to what lies within us.</i></p><h3 style = 'text-align: right'>-Henry S. Haskins</h3>";
break;
case 17: randQuote = "<p><i>How wonderful it is that nobody need wait a single moment before beginning to improve the world.</i></p><h3 style = 'text-align: right'>-Anne Frank</h3>";
break;
case 18: randQuote = "<p><i>Waiting for perfect is never as smart as making progress.</i></p><h3 style = 'text-align: right'>-Seth Godin</h3>";
break;
case 19: randQuote = "<p><i>It is the mark of an educated mind to be able to entertain a thought without accepting it.</i></p><h3 style = 'text-align: right'>-Aristotle</h3>";
}
document.getElementById("quote").innerHTML = randQuote;
document.getElementById("getQuote").innerHTML = "Next quote>";
var textArray1 = randQuote.split(">");
randQuote = textArray1[2].slice(0,-3);
randQuote = randQuote + " " + textArray1[5].slice(0,-4);
textArray1 = randQuote.split(" ");
randQuote = textArray1.join("+");
document.getElementById("click").innerHTML = `<button id='tweetQuote' onClick=(tweet(randQuote))>Tweet it!</button>`;
}
function tweet(randQuote) {
randQuote = 'https://twitter.com/intent/tweet?text=' + randQuote
window.open(randQuote);
}
Also see: Tab Triggers