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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Star Wars Spoilers</title>
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
</head>
<body>
<div role="main">
<img src="https://svgshare.com/i/AG3.svg" alt="" />
<h1 tabindex="0">Star Wars Spoilers</h1>
<div class="spoiler-group">
<p class="spoiler">
<span tabindex="0">Darth Vader is Luke Skywalker's Father! Noooooooooooo!</span>
</p>
<p class="spoiler">
<span tabindex="0">Jar Jar Binks is Sith!</span>
</p>
<p class="spoiler">
<span tabindex="0">I had friends on that Death Star :(</span>
</p>
<p class="spoiler">
<span tabindex="0">Kylo Ren is ripped <br> and has an eight pack!</span>
</p>
<p class="spoiler">
<span tabindex="0">Anakin Skywalker hates sand. It's course. And gets everywhere.</span>
</p>
<p class="spoiler">
<span tabindex="0">'Do or do not. There is no try.' - Yoda</span>
</p>
<p class="spoiler">
<span tabindex="0">Han shot first.</span>
</p>
<p class="spoiler">
<span tabindex="0">'Beep boop. Boop Beep.' - Artoo</span>
</p>
<p class="spoiler">
<span tabindex="0">Boba Fett survived the Sarlacc pit.</span>
</p>
<p class="spoiler">
<span tabindex="0">Droids don't rip your arms off when they lose.</span>
</p>
<p class="spoiler">
<span tabindex="0">It was indeed no moon. It was a space station. </span>
</p>
<p class="spoiler">
<span tabindex="0">Captain Phasma's chromium armor is made from emporer Palpatine's Yacht.</span>
</p>
<p class="spoiler">
<span tabindex="0">Those really were the droids they were looking for.</span>
</p>
<p class="spoiler">
<span tabindex="0">'Nrgggh arwghhhh nrghh' - Chewbacca</span>
</p>
<p class="spoiler">
<span tabindex="0">Someone is bound to have a bad feeling about this.</span>
</p>
<p class="spoiler">
<span tabindex="0">This isn't going to go the way you think.</span>
</p>
<p class="spoiler">
<span tabindex="0">'Hello There!' - Ben Kenobi</span>
</p>
<p class="spoiler">
<span tabindex="0">Han won the Millenium Falcon<br>fair and square!</span>
</p>
<p class="spoiler">
<span tabindex="0">Darth Maul survived being cut in half by Obi-Wan on Naboo.</span>
</p>
</div>
<div class="controls"></div>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
</body>
</html>
body {
background: rgb(47, 84, 141) url(https://svgshare.com/i/AF4.svg) repeat 0 0;
background-size: 400px auto;
font-family: "Nunito", sans-serif;
}
img {
display: block;
width: 150px;
margin: 100px auto;
cursor: pointer;
}
.spoiler {
background: #1d3c6a;
max-width: 440px;
width: 100%;
margin: 0 auto 20px;
border-radius: 5px;
text-align: center;
font-size: 1.5em;
}
.spoiler span {
color: #F0F0F0;
display: block;
padding: 40px 20px;
}
button,
.show-more {
background: #F0F0F0;
border: none;
border-radius: 5px;
color: #1d3c6a;
font-size: 1em;
max-width: 440px;
width: 100%;
padding: 40px 0;
cursor: pointer;
}
.show-more {
font-size: 1.5em;
background: #328adb;
margin: 0 auto 20px;
text-align: center;
color: #F0F0F0;
}
button:hover,
button:focus {
background: #cbd1d4;
}
.show-more:hover,
.show-more:focus {
background: #327cc0;
}
.jakku button {
color: #844B00;
background: #CCA556;
}
.jakku button:hover,
.jakku button:focus {
background: #cfa143;
}
.jakku .spoiler {
background: #C57002;
}
.jakku .show-more,
.jakku h1 {
background: #ad7935;
}
.jakku .show-more:hover,
.jakku .show-more:focus {
background: #d1984e;
}
h1 {
font-size: 2em;
background: #328adb;
margin: 0 auto 20px;
text-align: center;
color: #F0F0F0;
border: none;
border-radius: 5px;
max-width: 440px;
width: 100%;
padding: 40px 0;
}
const $reveal = $('<button>Reveal Spoiler</button>');
const $showMore = $('<p class="show-more" tabindex="0" role="button">Show More</p>');
$.fn.randomise = function (selector) {
(selector ? this.find(selector) : this.parent().each(function () {
$(this).children(selector).sort(function () {
return Math.random() - 0.5;
}).detach().appendTo(this);
}))
return this;
};
$('.spoiler').randomise();
$('.spoiler').append($reveal);
$('.spoiler span').hide();
$('.spoiler').on('click', 'button', function (event) {
$(this).prev().show().focus();
$(this).hide();
});
const $img = $('img');
$img.on('click', function (event) {
if ($(this).attr('src') == `https://svgshare.com/i/AG3.svg`) {
$(this).hide().attr('src', `https://svgshare.com/i/AEV.svg`).fadeIn();
$('body').addClass('jakku');
$('body').css('background', 'rgb(227, 200, 141) url("https://svgshare.com/i/AFh.svg") repeat scroll 0px 0px / 400px padding-box border-box');
} else {
$(this).hide().attr('src', `https://svgshare.com/i/AG3.svg`).removeAttr('style').fadeIn();
$('body').removeClass().removeAttr('style');
}
});
$('.spoiler').hide();
$('.spoiler:lt(3)').show();
$('.controls').append($showMore);
const $spoilersTotal = $('.spoiler').length;
let $spoilersShown = $('.spoiler:visible').length;
$('.show-more').on('keypress click', function (event) {
if(a11yClick(event) === true){
$spoilersShown += 3;
if ($spoilersShown >= $spoilersTotal) {
$(`.spoiler:lt(${$spoilersTotal})`).slideDown();
$([document.documentElement, document.body]).animate({
scrollTop: $(`.spoiler-group .spoiler:nth-of-type(${$spoilersShown -2}) button`).offset().top
})
$(this).hide();
$(`.spoiler-group .spoiler:nth-of-type(${$spoilersShown -2}) button`).focus();
$spoilersShown = $spoilersTotal;
} else {
$(`.spoiler:lt(${$spoilersShown})`).slideDown();
$(`.spoiler-group .spoiler:nth-of-type(${$spoilersShown -2}) button`).focus();
$([document.documentElement, document.body]).animate({
scrollTop: $(`.spoiler-group .spoiler:nth-of-type(${$spoilersShown -2}) button`).offset().top
})
}
}
})
function a11yClick(event){
if(event.type === 'click'){
return true;
}
else if(event.type === 'keypress'){
var code = event.charCode || event.keyCode;
if((code === 32)|| (code === 13)){
return true;
}
}
else{
return false;
}
}
Also see: Tab Triggers