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.
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Barlow&display=swap" rel="stylesheet">
<div class="container">
<nav id="navbar">
<header>Getting started with HTML</header>
<ul>
<li><a class="nav-link" href="#What_is_HTML?">What is HTML?</a></li>
<li><a class="nav-link" href="#Anatomy_of_an_HTML_element">Anatomy of an HTML element</a></li>
<li><a class="nav-link" href="#Nesting_elements">Nesting elements</a></li>
<li><a class="nav-link" href="#Block_versus_inline_elements">Block versus inline elements</a></li>
<li><a class="nav-link" href="#Empty_elements">Empty elements</a></li>
<li><a class="nav-link" href="#Attributes">Attributes</a></li>
<li><a class="nav-link" href="#Anatomy_of_an_html_document">Anatomy of an HTML document</a></li>
<li><a class="nav-link" href="#HTML_comments">HTML comments</a></li>
<li><a class="nav-link" href="#Reference">Reference</a></li>
</ul>
</nav>
<main id="main-doc">
<section class="main-section" id="What_is_HTML?">
<header>What is HTML?</header>
<article>
<p>HTML (Hypertext Markup Language) is not a programming language. It is a markup language that tells web browsers how to structure the web pages you visit. It can be as complicated or as simple as the web developer wants it to be. HTML consists of a series of elements, which you use to enclose, wrap, or mark up different parts of content to make it appear or act in a certain way. The enclosing tags can make content into a hyperlink to connect to another page, italicize words, and so on. For example, consider the following line of text:</p>
<code>My cat is very grumpy</code>
<p>If we wanted the text to stand by itself, we could specify that it is a paragraph by enclosing it in a paragraph (<p>) element:</p>
<code><p>My cat is very grumpy</p></code>
</article>
</section>
<section class="main-section" id="Anatomy_of_an_HTML_element">
<header>Anatomy of an HTML element</header>
<article>
<p>Let's further explore our paragraph element from the previous section:</p>
<img src="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started/grumpy-cat-small.png" alt="grumpy-cat-small">
<p>The anatomy of our element is:</p>
<ul>
<li><strong>The opening tag</strong>: This consists of the name of the element (in this example, p for paragraph), wrapped in opening and closing angle brackets. This opening tag marks where the element begins or starts to take effect. In this example, it precedes the start of the paragraph text.
</li>
<li>
<strong>The content</strong>: This is the content of the element. In this example, it is the paragraph text.
</li>
<li>
<strong>The closing tag</strong>: This is the same as the opening tag, except that it includes a forward slash before the element name. This marks where the element ends. Failing to include a closing tag is a common beginner error that can produce peculiar results.
</li>
</ul>
<p>
The element is the opening tag, followed by content, followed by the closing tag.
</p>
</article>
</section>
<section class="main-section" id="Nesting_elements">
<header>Nesting elements</header>
<article>
<p>
Elements can be placed within other elements. This is called nesting. If we wanted to state that our cat is very grumpy, we could wrap the word very in a <strong> element, which means that the word is to have strong(er) text formatting:
</p>
<code>
<p>My cat is <strong>very</strong></p>
</code>
<p>There is a right and wrong way to do nesting. In the example above, we opened the <i>p</i> element first, then opened the strong element. For proper nesting, we should close the <i>strong</i> element first, before closing the p.</p>
<p>The following is an example of the <i>wrong</i> way to do nesting:</p>
<code><p>My cat is <strong>very grumpy.</p></strong></code>
<p>The <strong>tags have to open and close in a way that they are inside or outside one another</strong>. With the kind of overlap in the example above, the browser has to guess at your intent. This kind of guessing can result in unexpected results.</p>
</article>
</section>
<section class="main-section" id="Block_versus_inline_elements">
<header>Block versus inline elements</header>
<article>
<p>There are two important categories of elements to know in HTML: block-level elements and inline elements.</p>
<ul>
<li>Block-level elements form a visible block on a page. A block-level element appears on a new line following the content that precedes it. Any content that follows a block-level element also appears on a new line. Block-level elements are usually structural elements on the page. For example, a block-level element might represent headings, paragraphs, lists, navigation menus, or footers. A block-level element wouldn't be nested inside an inline element, but it might be nested inside another block-level element.</li>
<li>Inline elements are contained within block-level elements, and surround only small parts of the document’s content (not entire paragraphs or groupings of content). An inline element will not cause a new line to appear in the document. It is typically used with text, for example an <a> element creates a hyperlink, and elements such as <em> or <strong> create emphasis.</li>
</ul>
<p>Consider the following example:</p>
<code><em>first</em><em>second</em><em>third</em>
<p>fourth</p><p>fifth</p><p>sixth</p></code>
<p><em> is an inline element. As you see below, the first three elements sit on the same line, with no space in between. On the other hand, <p> is a block-level element. Each p element appears on a new line, with space above and below. (The spacing is due to default CSS styling that the browser applies to paragraphs.)</p>
<p><em>first</em><em>second</em><em>third</em></p>
<p>fourth</p>
<p>fifth</p>
<p>sixth</p>
</article>
</section>
<section class="main-section" id="Empty_elements">
<header>Empty elements</header>
<article>
<p>Not all elements follow the pattern of an opening tag, content, and a closing tag. Some elements consist of a single tag, which is typically used to insert/embed something in the document. For example, the <img> element embeds an image file onto a page:</p>
<img src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png">
<p>This would output the following:</p>
<img id="image" src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png" alt="firefox-icon">
</article>
</section>
<section class="main-section" id="Attributes">
<header>Attributes</header>
<article>
<p>Elements can also have attributes. Attributes look like this:</p>
<img src="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started/grumpy-cat-attribute-small.png" alt="grumpy-cat-attribute-small">
<p>Attributes contain extra information about the element that won't appear in the content. In this example, the <i>class</i> attribute is an identifying name used to target the element with style information.</p>
<p>An attribute should have:</p>
<ul>
<li>A space between it and the element name. (For an element with more than one attribute, the attributes should be separated by spaces too.)</li>
<li>The attribute name, followed by an equal sign.</li>
<li>An attribute value, wrapped with opening and closing quote marks.</li>
</ul>
</article>
</section>
<section class="main-section" id="Anatomy_of_an_html_document">
<header>Anatomy of an HTML document</header>
<article>
<p>Individual HTML elements aren't very useful on their own. Next, let's examine how individual elements combine to form an entire HTML page:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My test page</title>
</head>
<body>
<p>This is my page/p>
</body>
</html></code>
</pre>
<p>Here we have:</p>
<ol>
<li><!DOCTYPE html>: The doctype. When HTML was young (1991-1992), doctypes were meant to act as links to a set of rules that the HTML page had to follow to be considered good HTML. Doctypes used to look something like this:
<pre class="inline-text"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></pre>
More recently, the doctype is a historical artifact that needs to be included for everything else to work right. <!DOCTYPE html> is the shortest string of characters that counts as a valid doctype. That is all you need to know!
</li>
<li><html></html>: The <html> element. This element wraps all the content on the page. It is sometimes known as the root element.</li>
<li><head></head>: The <head> element. This element acts as a container for everything you want to include on the HTML page, that isn't the content the page will show to viewers. This includes keywords and a page description that would appear in search results, CSS to style content, character set declarations, and more. You'll learn more about this in the next article of the series.</li>
<li><meta charset="utf-8">: This element specifies the character set for your document to UTF-8, which includes most characters from the vast majority of human written languages. With this setting, the page can now handle any textual content it might contain. There is no reason not to set this, and it can help avoid some problems later.</li>
<li><title></title>: The <title> element. This sets the title of the page, which is the title that appears in the browser tab the page is loaded in. The page title is also used to describe the page when it is bookmarked.</li>
<li><body></body>: The <body> element. This contains all the content that displays on the page, including text, images, videos, games, playable audio tracks, or whatever else.</li>
</ol>
</article>
</section>
<section class="main-section" id="HTML_comments">
<header>HTML comments</header>
<article>
<p>HTML has a mechanism to write comments in the code. Browsers ignore comments, effectively making comments invisible to the user. The purpose of comments is to allow you to include notes in the code to explain your logic or coding. This is very useful if you return to a code base after being away for long enough that you don't completely remember it. Likewise, comments are invaluable as different people are making changes and updates.</p>
<p>To write an HTML comment, wrap it in the special markers <!-- and -->. For example:</p>
<code><p>I'm not inside a comment</p>
<!-- p>I am!</p> -->
</code>
<p>As you can see below, only the first paragraph displays in the live output.</p>
<code><p>I'm not inside a comment</p></code>
</article>
</section>
<section class="main-section" id="Reference">
<header>Reference</header>
<article>
<ul>
<li>
All the documentation in this page is taken from
<a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started" target="_blank">MDN</a>
</li>
</ul>
</article>
</section>
</main>
</div>
* {
box-sizing: border-box;
}
body {
font-size: 16px;
font-family: "Barlow", "Rubik", sans-serif;
color: #2f4f4f;
background-color: #faebd7;
min-width: 300px;
}
section {
margin: 0;
padding: 0.25em;
}
header {
font-size: 1.5rem;
font-weight: bold;
}
.container {
display: grid;
grid-template-columns: 300px 1fr;
grid-template-rows: auto;
font-size: 1.25rem;
}
#navbar {
grid-column: 1 / -1;
position: relative;
width: 300px;
}
#navbar header {
font-size: 1.75rem;
}
#navbar ul {
list-style: none;
margin: 0;
padding: 0;
}
#navbar li {
border-top: 1px solid;
position: relative;
width: 100%;
}
#navbar li:last-child {
border-bottom: 1px solid;
}
#navbar a {
display: block;
text-decoration: none;
padding: 0.5em;
}
img {
width: 90%;
}
#image {
width: 200px;
}
#main-doc {
display: block;
grid-column: 1 / -1;
position: relative;
}
#reference li {
list-style: none;
}
@media only screen and (min-width: 850px) {
header {
font-size: 2rem;
}
section {
margin: 1em;
padding: 1em;
}
#navbar {
grid-column: 1 / 2;
position: fixed;
border-right: solid;
border-color: #2f4f4f;
}
#navbar header {
font-size: 2.5rem;
}
#main-doc {
grid-column: 2 / -1;
position: relative;
}
}
@media (min-width: 350px) {
header {
font-size: 2rem;
}
#navbar {
width: 325px;
}
img {
width: auto;
max-width: 450px;
}
}
Also see: Tab Triggers