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.
<section id="locationMarkdown">
<h1>e.g. Room Title Here</h1>
<p>Description here, etc.</p>
</section>
<section id="alerts">
</section>
<section id="actions">
Action Buttons Will Go Here
</section>
<section class="inventory">
<h3>Inventory:</h3>
<div id="inventory">
You don't have anything yet...
</div>
</section>
.hidden {
display: none;
}
#alerts {
color: red;
}
@media print{*,:after,:before{background:0 0!important;color:#000!important;box-shadow:none!important;text-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}a[href^="#"]:after,a[href^="javascript:"]:after{content:""}blockquote,pre{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}img,tr{page-break-inside:avoid}img{max-width:100%!important}h2,h3,p{orphans:3;widows:3}h2,h3{page-break-after:avoid}}@media screen and (min-width:32rem) and (max-width:48rem){html{font-size:15px}}@media screen and (min-width:48rem){html{font-size:16px}}body{line-height:1.85}.splendor-p,p{font-size:1rem;margin-bottom:1.3rem}.splendor-h1,.splendor-h2,.splendor-h3,.splendor-h4,h1,h2,h3,h4{margin:1.414rem 0 .5rem;font-weight:inherit;line-height:1.42}.splendor-h1,h1{margin-top:0;font-size:3.998rem}.splendor-h2,h2{font-size:2.827rem}.splendor-h3,h3{font-size:1.999rem}.splendor-h4,h4{font-size:1.414rem}.splendor-h5,h5{font-size:1.121rem}.splendor-h6,h6{font-size:.88rem}.splendor-small,small{font-size:.707em}canvas,iframe,img,select,svg,textarea,video{max-width:100%}@import url(http://fonts.googleapis.com/css?family=Merriweather:300italic,300);html{font-size:18px;max-width:100%}body{color:#444;font-family:Merriweather,Georgia,serif;margin:0;max-width:100%}:not(div):not(img):not(body):not(html):not(li):not(blockquote):not(p),p{margin:1rem auto;max-width:36rem;padding:.25rem}div,div img{width:100%}blockquote p{font-size:1.5rem;font-style:italic;margin:1rem auto;max-width:48rem}li{margin-left:2rem}h1{padding:4rem 0!important}p{color:#555;height:auto;line-height:1.45}code,pre{font-family:Menlo,Monaco,"Courier New",monospace}pre{background-color:#fafafa;font-size:.8rem;overflow-x:scroll;padding:1.125em}a,a:visited{color:#3498db}a:active,a:focus,a:hover{color:#2980b9}
//Here is Template code for your own Adventure Game!
//Below are functions that help you code your game
//a bit easier. YOU DO NOT NEED TO EDIT THESE FUNCTIONS!
//Go down to the next comment to see where you
//can begin coding
let inventory = [];
let youWin = function(){
$("#alerts").html("You win congrats!");
}
let addToInventory = function(anItem){
$("#alerts").html(`You got ${anItem}`);
inventory.push(anItem);
$("#inventory").html("");
let i = 0;
for (i = 0; i < inventory.length; i++){
$("#inventory").append(`<div class="inventoryItem">${inventory[i]}</div>`);
}
}
let isInInventory = function(anItem){
return inventory.indexOf(anItem) > -1;
}
let displayMarkdown = function(locationMarkdown){
$("#alerts").html("");
showdown.setFlavor('github');
var converter = new showdown.Converter();
$("#locationMarkdown").html(converter.makeHtml(locationMarkdown));
};
let showButtons = function(buttonArray){
$(".action").off("click");
$("#actions").html("");
let i = 0;
for (i = 0; i < buttonArray.length; i++){
let nextButton = buttonArray[i];
$("#actions").append(
`
<button
class="action"
data-next-location="${nextButton.takesYouToLocation}"
>
${nextButton.buttonText}
</button>
`);
}
$(".action").on("click", function(clickEvent){
let buttonYouClicked = clickEvent.currentTarget;
let nextLocation = $(buttonYouClicked).attr("data-next-location");
loadLocation(nextLocation);
});
}
//HEY HEY!
//Here is where you come in! Below is a switch statement
//that will help you switch your characters locations based on
//the buttons that they press
//Follow the comments below to help you copy and paste
//and then edit the code to help you make a new
//location the user can go to
let loadLocation = function(locationName){
switch (locationName){
//COPY FROM HERE the start location code begins here,
//Copy "case "startLocation":", to where the comments tell you to stop.
case "startLocation": //Change this to the "id" of your location, you will
//Use this id to determine where go from location to location
displayMarkdown( //Here is where you will build the page, this is called Markdown
`
### Story Title / Location Name!
Story flavor text, add something here about your location!
![filler image](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.ArdUbzAJjMbRFfZF3RfkkwHaEB%26pid%3DApi&f=1)
^^ Above is a picture, to add a different picture, just like yesterday,
you want to 'Copy Image Address', and then put it inbetween the ( ) where
the old URL is, DELETE THIS WHEN YOU ARE DONE OR ELSE IT WILL BE ON YOUR WEBSITE
Text to make a decision
`
);
//If you want to add something to your inventory once you are
//in this location, uncomment the function below and edit the
//text, if not leave it commented.
//addToInventory("Put Item Text Here");
//Here we have an if Statement that checks if they have an
//Item in their inventory and gives specific location if they do!
//So, if you want them to have an item to go to a specific location,
//Work inside the if statement, if not, work inside the else statement
if(isInInventory("Item")){ //Here put the Item they must have to enter roomC
//This alert is optional, you can delete it if you want
alert("You Have 'Item', therefore, you can now go to these locations...")
showButtons( //This is where you will edit the buttons
[
{buttonText:"Click here to go to room A", //This is the text that will display on the button
takesYouToLocation:"roomA"}, //Here put the location where you want the button to take you,
//Where is says "roomA", put the id of the location you want to go to!
{buttonText:"Click here to go to room B",
takesYouToLocation:"roomB"},
{buttonText:"Click here to go to room C", //Here is the extra location they can now go to
takesYouToLocation:"roomC"}, //Because they have the special item!
]
);
}
else{ //These will be the buttons that are displayed if they do not have the special item
showButtons( //This is where you will edit the buttons
[
{buttonText:"Click here to go to room A", //This is the text that will display on the button
takesYouToLocation:"roomA"}, //Here put the location where you want the button to take you,
//Where is says "roomA", put the id of the location you want to go to!
{buttonText:"Click here to go to room B",
takesYouToLocation:"roomB"},
]
);
}
break;
//and it ends here END COPY HERE (last thing to copy is 'break';)
//Now that you have created your own location, you can edit the next two locations
//To make them you own! If you want to add a location, Just copy the code above
//and follow the comments!
//You can paste you new location below
case "roomA":
displayMarkdown(
`
### Room A
Room A description
![forrest](https://yogalondon.net/monkey/wp-content/uploads/2015/04/17484746256_8bfc5f4899_k.jpg)
Gain an item!
`
);
addToInventory("An Item");
showButtons(
[
{buttonText:"Click here to move forward",
takesYouToLocation:"roomC"
}
]
);
break;
//and it ends here
//the smith Hall code begins here
case "roomB":
displayMarkdown(
`
### Room B
room B description
![beach](https://cdn.cnn.com/cnnnext/dam/assets/181010131059-australia-best-beaches-cossies-beach-cocos3-full-169.jpg)
`
);
showButtons([]);
youWin(); //LOOK HERE! This is the " youWin(); " function, place this
//function in whatever location you want to be the ending location
break;
//and it ends here
//roomC Begins here
case "roomC":
displayMarkdown(
`
### Room C
Room C description
![Cyberscholars](https://upgradedpoints.com/wp-content/uploads/2018/06/Top-20-Amusement-Parks-in-North-America.jpg)
`
);
//LOOK HERE! Here is where you can have a special option,
//which in this case is winning the game, if you have a certian item
//in you inventory
if (isInInventory("An Item")){ //Here is where you enter the item that you want to check for
youWin(); //Here you can place the action, in this case it is winning the game
} else {
alert("You dont have the right item to win yet!") //In this case, an alert will be sent to the screen
}
showButtons([]);
break;
//and it ends here
}
}
loadLocation("startLocation"); //IF YOU HAVE CHANGED THE NAME OF THE startLocation,
//MAKE SURE TO PUT THAT SAME NAME HERE!
Also see: Tab Triggers