Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource


Add Packages

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.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <body class="wrapper l-stack-xxl">

	<div class="forms-container">
		<form method="post" id="form-number">
			<p>Search for a Pokémon by its number.</p>
			<div class="l-stack-xxs">
				<label for="input-number">Pokémon number (1 – 898)</label>
				<input id="input-number" type="number" inputmode="numeric" pattern="[0-9]*" name="input-number" min="1" max="898" required>
			<button id="submit-number" type="submit" name="submit-number">Show Pokémon</button>

		<form method="post" id="form-random">
			<p>Show a random Pokémon.</p>
			<button id="submit-random" type="submit" name="submit-random">Show a random Pokémon</button>

	<!--<form id="form-name">
		<label for="input-name">Pokémon name</label>
		<div class="l-input-button">
			<input id="input-name" type="text" name="input-name" required>
			<button id="submit-name" type="submit" name="submit-name">Show Pokémon</button>

	<ul id="list" class="list-none list-pokemon"></ul>


                @import "" layer(base);
@import "" layer(styles);

:root {
	--page-max-inline-size: 100rem;

body {
	text-align: center;

form {
	display: flex;
	flex-direction: column;
	gap: 1rem;

form > :last-child {
	margin-block-start: auto;

figure {
	border: var(--bw-1) solid var(--c-bg-3);
	border-radius: var(--border-radius);

figure img {
	max-inline-size: 10rem;
	border-start-start-radius: var(--border-radius);
	border-start-end-radius: var(--border-radius);

figure figcaption {
	padding: var(--padding-xs);
	background-color: var(--c-bg-2);
	border-end-start-radius: var(--border-radius);
	border-end-end-radius: var(--border-radius);

figure figcaption > * {
	justify-content: center;

.forms-container {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: var(--s-800);

.list-pokemon {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
	justify-items: center;
	gap: var(--s-400);

.list-pokemon:empty {
	display: none;

.pokemon-type {
	padding-block: var(--padding-xxxs);
	padding-inline: var(--padding-sm);
	background-color: var(--c-bg-a);
	border-radius: var(--border-radius);



                // RESTful API "PokéAPI" (
// Endpoint: "{id or name}/"
const baseApiUrl = "";
const maxPokeNumber = 898;

// Elements in the DOM
const formNumber = document.querySelector("#form-number");
const formRandom = document.querySelector("#form-random");
const list = document.querySelector("#list");

formNumber.addEventListener("submit", (e) => {

	const inputNumber = e.currentTarget.elements["input-number"];

	// Sanitize and store the number that the user has entered
	const pokeNumber = parseInt(inputNumber.value);

	// Clear the input value
	inputNumber.value = "";

	// Remove current Pokémon
	list.querySelectorAll(":scope > *").forEach((pokemon) => pokemon.remove());

	// Fetch the Pokémon data using the API

formRandom.addEventListener("submit", (e) => {

	// Remove current Pokémon
	list.querySelectorAll(":scope > *").forEach((pokemon) => pokemon.remove());

	// Fetch the Pokémon data using the API
	getPokemonData(getRandomIntInclusive(1, maxPokeNumber));

function getPokemonData(idNumber) {
	const requestURL = baseApiUrl + idNumber;

		.then((response) => response.json())
		.then((pokemonData) => {
			const pokemonElement = createPokemon(pokemonData);
			return addPokemonToList(pokemonElement, list);
		.catch((error) => console.log(error));

function createPokemon({ id, name, sprites, types }) {
	// Figure as a container
	const pokemon = document.createElement("figure");

	// Image
	const image = document.createElement("img");
	image.src = `${sprites["other"]["official-artwork"]["front_default"]}`;
	image.alt = `Pokémon number ${id}, called ${name}`;
	image.width = "475";
	image.height = "475";

	// Figcaption for the info
	const info = document.createElement("figcaption");

	const infoNumber = document.createElement("p");
	infoNumber.innerText = id;

	const infoName = document.createElement("p");
	infoName.innerText = name[0].toUpperCase() + name.slice(1);
	infoName.classList.add("text-500", "weight-bold");

	const infoTypes = document.createElement("ul");
	infoTypes.setAttribute("role", "list");
	infoTypes.classList.add("l-cluster-xs", "text-300");
	types.forEach((type) => {
		const typeElement = document.createElement("li");
		typeElement.innerText = type["type"]["name"];


	return pokemon;

function addPokemonToList(pokemon, list) {
	const li = document.createElement("li");

function getRandomIntInclusive(min, max) {
	min = Math.ceil(min);
	max = Math.floor(max);
	const randomNumber = Math.floor(Math.random() * (max - min + 1) + min);
	return randomNumber;