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.
<body>
<div class="header">
<h1>INFO</h1>
<input class="input" type="text" id="input" placeholder="Pokédex Number...">
<button id="go" class="pokedex-button" onclick="submit()">Go</button>
<button id="random" class="pokedex-button" onclick="random()">Random Pokémon</button>
<button id="clear" class="button-clear">x</button>
</div>
<div class="pokedex-screen">
<img class="pokedex-img" id="img" src="" alt="">
</div>
<div class="info">
<div id="data1" class="pokedex-data">
<p class="pokedex-data-text"><span id="text_id"></span> <span id="text_name"></span></p>
</div>
<p class="pokedex-data-text ability">Ability: <span id="text_ability"></span></p> <br>
<p class="pokedex-data-text ability">Type(s):</p>
<div id="data2" class="pokedex-data">
<p class="pokedex-data-text"><span id="text_type"> </span><span class="space"></span><span id="text_type2"></span></p>
</div>
</div>
</body>
// Colours
$bgColor1: #D8F8F8;
$bgColor2: #C0F0F8;
$size: 50px;
$smColor1: #f8f8f8;
$smColor2: #f0f0f8;
$top: #0060F0;
$titleBg: #F8F8C0;
$infoBg: #F8F8C0;
$textColour: #606060;
$textWhite: #F8F8F8;
$borderColour: #F8F898;
$typeBorderColour: #586060;
// Fonts
$mainFont: 'Press Start 2P';
@import url('https://fonts.googleapis.com/css?family=Press+Start+2P&display=swap');
// Global
* {
margin: 0;
font-size: 16px;
font-family: $mainFont;
-webkit-font-smoothing: none;
}
body {
background-image:
linear-gradient(45deg, $bgColor1 25%, transparent 25%, transparent 75%, $bgColor1 75%),
linear-gradient(45deg, $bgColor1 25%, $bgColor2 25%, $bgColor2 75%, $bgColor1 75%);
background-size: $size $size;
background-position:0 0, $size/2 $size/2;
color: $textColour;
}
.space {
padding:10px;
}
// Typography
h1 {
color: $textWhite;
font-size: 1.6rem;
display: inline-block;
}
p {
font-size: 1.2rem;
}
span {
text-transform: capitalize;
font-size: 1.2rem;
}
#text_type, #text_type2 {
text-transform: uppercase;
}
// Header
.header {
background: $top;
padding:20px;
}
.input {
padding: 10px;
border-radius: 10px;
}
button {
padding: 10px;
border-radius: 10px;
background-color: light-grey;
}
// Data
.info {
display: inline-block;
background-color: $infoBg;
border-radius: 20px;
margin-top: 50px;
padding: 10px 60px 20px 10px;
}
.ability {
padding-left: 15px;
}
#data1, #data2 {
padding: 15px;
}
#data2 {
padding-top: 30px;
}
// Type Icon
#text_type, #text_type2 {
padding: 10px;
color: white;
border: 2px solid $typeBorderColour;
border-radius: 10px;
}
// Image
.pokedex-screen {
display: inline-block;
overflow: hidden;
float:left;
margin: 40px;
width: 300px;
background-image: linear-gradient(0deg, $smColor1 25%, $smColor2 25%, $smColor2 50%, $smColor1 50%, $smColor1 75%, $smColor2 75%, $smColor2 100%);
background-size: 80px 80px;
border-radius: 30px;
border: 10px solid $borderColour;
}
img {
width: 100%;
}
var normal = "#ADA480";
var fighting = "#C22F26";
var flying = "#B49AF6";
var poison = "#A43FA4";
var ground = "#DEBE63";
var rock = "#B49E38";
var bug = "#A8B531";
var ghost = "#6E5391";
var steel = "#B8B5CF";
var fire = "#F07D33";
var water = "#6D88F8";
var grass = "#81CB5B";
var electric = "#E9D436";
var psychic = "#FF598D";
var ice = "#9AD9DA";
var dragon = "#723EFC";
var dark = "#705749";
var fairy = "#E1A4E1";
var go;
var clear;
var img;
var textId;
var textName;
var textAbility;
var textType;
var textType2;
var param;
$(function() {
img = $('#img');
go = $("#go");
clear = $('#clear');
textId = $('#text_id');
textName = $('#text_name');
textAbility = $('#text_ability');
textType = $('#text_type');
textType2 = $('#text_type2');
param = $('#input');
});
function clearData() {
img.attr('src', '');
textId.html('');
textName.html('');
textAbility.html('');
textType.html('');
textType2.html('');
param.val('');
}
function submit(){
var inputValue = $.trim(param.val());
if (inputValue === '') return;
var pokeURL = "https://pokeapi.co/api/v2/pokemon/" + inputValue;
$.ajax({
type: "GET",
url: pokeURL,
success: function(data){
ajaxSuccess(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
ajaxError();
}
});
}
function random() {
var number = Math.floor(Math.random() * 898) + 1;
var pokeURL = "https://pokeapi.co/api/v2/pokemon/" + number;
$.ajax({
type: "GET",
url: pokeURL,
success: function(data){
ajaxSuccess(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
ajaxError();
}
});
}
function ajaxSuccess(data){
var imageURI = data.sprites.front_default;
var id = data.id;
var name = data.name;
var ability = data.abilities;
var type = data.types;
img.attr('src', imageURI);
textId.html(id);
textName.html(name);
textAbility.html(ability[0].ability.name);
var type1 = type[0].type.name;
textType.html(type1);
getTypeColour1(type1);
textType2.html('');
if (type.length == 2) {
let type2 = type[1].type.name;
textType2.html(type2);
getTypeColour2(type2);
}
clear.click(function() {
clearData();
});
}
function ajaxError(data){
clearData();
}
function changeBg1(name) {
textType.css("background-color", name);
}
function changeBg2(name) {
textType2.css("background-color", name);
}
function getTypeColour1(type) {
var pokeType = type;
switch (pokeType) {
case "normal":
changeBg1(normal);
break;
case "fighting":
changeBg1(fighting);
break;
case "flying":
changeBg1(flying);
break;
case "poison":
changeBg1(poison);
break;
case "ground":
changeBg1(ground);
break;
case "rock":
changeBg1(rock);
break;
case "bug":
changeBg1(bug);
break;
case "ghost":
changeBg1(ghost);
break;
case "steel":
changeBg1(steel);
break;
case "fire":
changeBg1(fire);
break;
case "water":
changeBg1(water);
break;
case "grass":
changeBg1(grass);
break;
case "electric":
changeBg1(electric);
break;
case "psychic":
changeBg1(psychic);
break;
case "ice":
changeBg1(ice);
break;
case "dragon":
changeBg1(dragon);
break;
case "fairy":
changeBg1(fairy);
break;
case "dark":
changeBg1(dark);
break;
}
}
function getTypeColour2(type) {
var pokeType = type;
switch (pokeType) {
case "normal":
changeBg2(normal);
break;
case "fighting":
changeBg2(fighting);
break;
case "flying":
changeBg2(flying);
break;
case "poison":
changeBg2(poison);
break;
case "ground":
changeBg2(ground);
break;
case "rock":
changeBg2(rock);
break;
case "bug":
changeBg2(bug);
break;
case "ghost":
changeBg2(ghost);
break;
case "steel":
changeBg2(steel);
break;
case "fire":
changeBg2(fire);
break;
case "water":
changeBg2(water);
break;
case "grass":
changeBg2(grass);
break;
case "electric":
changeBg2(electric);
break;
case "psychic":
changeBg2(psychic);
break;
case "ice":
changeBg2(ice);
break;
case "dragon":
changeBg2(dragon);
break;
case "fairy":
changeBg2(fairy);
break;
case "dark":
changeBg2(dark);
break;
}
}
Also see: Tab Triggers