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.
<!doctype html>
<!--
This is an HTML comment. These do not render on the document for the user to view, but can be viewed in the source of the code.
-->
<!--
The 'doctype' declaration at the start of this document is a special element that we must use at the beggining of any HTML document to ensure that all of our document renders appropriately. If anything comes before the element, the document may not be recognized as HTML5 (which may break some of our document).
-->
<!--
The <html> element below wraps our entire document, both information about the document and the content itself. It is also showing the standard structure of an HTML tag, where:
< ... > - Triangle brackets open/close the tag
<html ... > - The name of the element comes first
<html lang...> - Attributes (in this case 'lang') are declared after a separating space
<html lang="..."> - Quotation marks wrap the attribute's value
<html lang="en"> - The complete opening tag of the element
<html lang="en"></html> - Both the opening and closing tags of the element
In this case we are opening our HTML document and declaring the default language as English (en).
-->
<html lang="en">
<!--
The <head> element is where we declare information about our document that is NOT visible to users. This includes things like the character set and title for our document.
Later we will include information about how the document should resize for mobile devices as well as our stylesheets. No user-visible content should appear in here.
-->
<head>
<!--
The <meta> element defines information about our document. Because it does not have any content (it only declares attributes) there is no need to use a closing tag with it. In this case, we are declaring a character set (what kind of characters we are using) for the document. If you would like more information about character sets, I recommend reading this article - http://www.joelonsoftware.com/articles/Unicode.html
-->
<meta charset="utf-8">
<!--
The <meta> element below is important to help change the size of our browser window to reflect the size of the device. It works as follows:
name="viewport" - this clarifies that we are declaring something about the viewport (aka browser window)
'width=device-width' - this specifies that the width of the viewport should be equal to the width of our device (important for mobile devices)
'initial-scale=1' - this ensures that our website renders not zoomed-in or zoomed-out, as we have designed it to be responsive.
If you would like more information on why we set this, I recommend reading this article - https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag
-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
The <title> element defines the title of our document. This is what ends up appearing in our tab at the top of our browser window and what is read by search engines for listing the document.
-->
<title>My Most Hideous Page Ever</title>
<!--
Remember that unless it is a self-closing element, we need to make sure to close tags.
-->
</head>
<!--
The <body> element is where we include all our content that is meant to be visible to the user in the web browser.
-->
<body>
<!--
The <header> element - NOT TO BE CONFUSED WITH THE <head> ELEMENT - helps group the main headings and navigation for the content of the website.
-->
<header>
<!--
The <h1> element is our highest level heading. When reading a document, browsers and search engines look at the structure and hierarchy of headings as well as content to understand how the document should be interpreted or ranked in search engines.
-->
<h1>My Most Hideous Page Ever</h1>
<!--
The <nav> element is for major groupings of navigation items. This can be for links within the same document, or to other documents. Think of it as a means of grouping the major links related or connected to this document.
-->
<nav>
<!--
The <a> (anchor) element allows us to link to other points in the document, or to different documents entirely. In this case, both of our links point to different ID's within our document. ID's are referenced by using the hashtag and then the name of the ID (i.e. # + kittens = #kittens).
-->
<a href="#introduction">An introduction</a>
<a href="#kittens">To the kittens</a>
</nav>
</header>
<!--
The <section> element defines just that, a section of our document. It is more semantically meaningful then the more generic <div> (division) element, as the section element expects a heading and content.
Within the opening section tag below, we have also defined an ID of 'introduction'. This allows us to link from the navigation to this point in the document. Note that because we declare the 'id' attribute, we do not need to use a hashtag (#) before the value 'introduction'.
-->
<section id="introduction">
<!--
The <h2> element, a second-level heading is being used to help browsers understand the hierarchy of our document.
-->
<h2>An introduction</h2>
<!--
The <p> element is for paragraphs. Inside of this paragraph, we have an additional element:
The <strong> element, which indicates a portion of the text as more important than the rest of the paragraph (in this case).
-->
<p>
<strong>Very exciting things are happening</strong>. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
</p>
</section>
<!--
The <section> element defines just that, a section of our document. It is more semantically meaningful then the more generic <div> (division) element, as the section element expects a heading and content.
Within the opening section tag below, we have also defined an ID of 'kittens'. This allows us to link from the navigation to this point in the document. Note that because we declare the 'id' attribute, we do not need to use a hashtag (#) before the value 'kittens'.
-->
<section id="kittens">
<h2>Kittens are da cutest!</h2>
<!--
The <figure> element allows us to build a relationship between multimedia elements (i.e. images, videos...) and a caption.
-->
<figure>
<!--
The <img> element is for placing images in the document. Because the image is placed within the attributes of the image element itself, we do not need to close this tag. The attributes of this tag are important:
'src' - Sets the location of the image, which is relative to where our HTML document is saved.
'alt' - Is alternative text that describes the image as if we did not see it. The best way to think of this is it should describe the image within its own context. For example, if the content of the image is important to understanding the document, then the alt text should describe the image. If the image is a link, the text should describe where the link is taking them.
More information on making good alt text is available at http://a11yproject.com/posts/alt-text/
'width' and 'height' - Define the width and height of the original image in pixels. Do not use other units or measurements different from the original size of the image.
-->
<img src="https://andrewh.ca/teaches/information_design/tutorials/01/explanation/img/kitten.jpg" alt="A blue eyed kitten standing over a bowl with a milk beard" width="1200" height="627">
<!--
The <figcaption> element must be used inside of a <figure> element. It defines the caption for the figure.
-->
<figcaption>
It's a bundle of cute, cuddly, danger!
<!--
Here we are creating a link to placekitten.com, note that to link outside of the existing site we have to start the link with either 'http://' or 'https://'
Links without 'http://' or 'https://' at the beginning will point to files within our website. For example:
<a href="contact.html">Contact</a> will link to the 'contact.html' file.
-->
<a href="http://placekitten.com">Photo from placekitten</a>
</figcaption>
</figure>
<!--
The <ol> element defines an ordered list. Note that only <li> (list items) can appear inside of an <ol> element.
-->
<ol>
<!--
The <li> element is a list item. Depending on if the list item is within an ordered list <ol> element or unordered list <ul> element either numbers or bullets will be placed before each list item.
<em> - The emphasis element, which indicates inflection (emphasis in your speaking).
-->
<li>The <em>first</em> reason why kittens are dangerous.</li>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
</section>
</body>
</html>
Also see: Tab Triggers