Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

Save Automatically?

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.

HTML

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, intial-scale=1.0" />
    <meta name="description" content="freeCodeCamp HTML Technical Documentation Page project" />
    <link rel="stylesheet" type="text/css" href="./styles.css" />
    <title>HTML Technical Documentation</title>
  </head>
  <body>
    <nav id="navbar">
      <header class="main">HTML Documentation</header>
      <ul>
        <li><a class="nav-link" href="#Introduction">Introduction</a>
        </li>
        <li><a class="nav-link" href="#Prerequisites">Prerequisites</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="#Boolean_attributes">Boolean 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="#Whitespace_in_HTML">Whitespace in HTML</a>
        </li>
        <li><a class="nav-link" href="#Entity_references:_Including_special_characters_in_HTML">Entity references: Including special characters in HTML</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="Introduction">
        <header class="main">Introduction</header>
        <article></article>
          <p>HTML (<strong>H</strong>yper<strong>T</strong>ext <strong>M</strong>arkup <strong>L</strong>anguage) is the code that is used to structure a web page and its content. For example, content could be structured within a set of paragraphs, a list of bulleted points, or using images and data tables.</p>
        <p>HTML is a markup language that defines the structure of your content. HTML consists of a series of elements, which you use to enclose, or wrap, different parts of the content to make it appear a certain way, or act a certain way. The enclosing tags can make a word or image hyperlink to somewhere else, can italicize words, can make the font bigger or smaller, and so on. For example, take the following line of content:</p>
        <div class="code">
        <code>My cat is very grumpy</code>
        </div>
        <p>If we wanted the line to stand by itself, we could specify that it is a paragraph by enclosing it in paragraph tags:</p>
        <div class="code">
        <code>&ltp>My cat is very grumpy&lt/p></code>
        </div>
      </section>
      <section class="main-section" id="Prerequisites">
        <header>Prerequisites</header>
        <p>Before starting this guide, you don't need any previous HTML knowledge, but you should have at least basic familiarity with using computers and using the web passively (i.e., just looking at it and consuming content). You should have a basic work environment set up (e.g., having installed basic software), and understand how to create and manage files.</p>
      </section>
      <section class="main-section" id="Anatomy_of_an_HTML_element">
        <header class="main">Anatomy of an HTML element</header>
        <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="Image of HTML element anatomy from the grumpy cat example" />
        <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>
      </section>
      <section class="main-section" id="Nesting_elements">
        <header>Nesting elements</header>
        <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 &ltstrong> element, which means that the word is to have strong(er) text formatting:</p>
        <div class="code">
        <code>&ltp>My cat is &ltstrong>very&lt/strong> grumpy.&lt/p></code>
        </div>
        <p>There is a right and wrong way to do nesting. In the example above, we opened the p element first, then opened the strong element. For proper nesting, we should close the strong element first, before closing the p.</p>
        <p>The following is an example of the wrong way to do nesting:</p>
        <div class="code">
        <code>&ltp>My cat is &ltstrong>very grumpy.&lt/p>&lt/strong></code>
        </div>
        <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>
      </section>
      <section class="main-section" id="Block_versus_inline_elements">
        <header>Block versus inline elements</header>
        <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 &lta> element creates a hyperlink, and elements such as &ltem> or &ltstrong> create emphasis.
          </li>
        </ul>
        <p>Consider the following example:</p>
        <div class="code">
        <code>&ltem>first&lt/em>&ltem>second&lt/em>&ltem>third&lt/em>&ltp>fourth&lt/p>&ltp>fifth&lt/p>&ltp>sixth&lt/p></code>
        </div>
        <p>&ltem> 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, &ltp> 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>
        <fieldset>
        <samp><em>first</em><em>second</em><em>third</em>
<p>fourth</p><p>fifth</p><p>sixth</p>
        </samp>
        </fieldset>
        <div class="note">
          <strong>Note:</strong>
          <ul>
            <li>HTML5 redefined the element categories. While these definitions are more accurate and less ambiguous than their predecessors, the new definitions are a lot more complicated to understand than block and inline. This article will stay with these two terms.
            </li>
            <li>The terms block and inline, as used in this article, should not be confused with the types of CSS boxes that have the same names. While the names correlate by default, changing the CSS display type doesn't change the category of the element, and doesn't affect which elements it can contain and which elements it can be contained in. One reason HTML5 dropped these terms was to prevent this rather common confusion.
            </li>
          </ul>
        </div>
      </section>
      <section class="main-section" id="Empty_elements">
        <header>Empty elements</header>
        <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 &ltimg> element embeds an image file onto a page:
        </p>
        <div class="code">
          <code>&ltimg src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png">
          </code>
        </div>
        <p>This would output the following:</p>
        <fieldset>
          <samp><img src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png" /></samp>
        </fieldset>
        <div class="note">
          <strong>Note:</strong>
          <ul>
            <li>Empty elements are sometimes called void elements.
            </li>
            <li>In HTML, there is no requirement to add a / at the end of an empty element's tag, for example: &ltimg src="images/cat.jpg" alt="cat" />. However, it is also a valid syntax and you may do this when you want your HTML to be valid XML.
            </li>
          </ul>
        </div>
      </section>
      <section class="main-section" id="Attributes">
        <header class="main">Attributes</header>
        <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="Image of HTML class attribute example">
        <p>Attributes contain extra information about the element that won't appear in the content. In this example, the class 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>
        <p>Another example of an element is &lta>. This stands for anchor. An anchor can make the text it encloses into a hyperlink. Anchors can take a number of attributes, but several are as follows:</p>
        <ul>
          <li><strong>href:</strong> This attribute's value specifies the web address for the link. For example: href="https://www.mozilla.org/".
          </li>
          <li><strong>title:</strong> The title attribute specifies extra information about the link, such as a description of the page that is being linked to. For example, title="The Mozilla homepage". This appears as a tooltip when a cursor hovers over the element.
          </li>
          <li><strong>target:</strong> The target attribute specifies the browsing context used to display the link. For example, target="_blank" will display the link in a new tab. If you want to display the linked content in the current tab, just omit this attribute.
          </li>
        </ul>
      </section>
      <section class="main-section" id="Boolean_attributes">
        <header>Boolean attributes</header>
        <p>Sometimes you will see attributes written without values. This is entirely acceptable. These are called Boolean attributes. Boolean attributes can only have one value, which is generally the same as the attribute name. For example, consider the disabled attribute, which you can assign to form input elements. (You use this to disable the form input elements so the user can't make entries. The disabled elements typically have a grayed-out appearance.) For example:</p>
        <div class="code">
          <code>&ltinput type="text" disabled="disabled"></code>
        </div>
        <p>As shorthand, it is acceptable to write this as follows:</p>
        <div class="code">
          <code><p>&lt!-- using the disabled attribute prevents the end user from entering text into the input box --></p>
<p>&ltinput type="text" disabled></p><p>&lt!-- text input is allowed, as it doesn't contain the disabled attribute --></p>
<p>&ltinput type="text"></p></code>
        </div>
        <p>For reference, the example above also includes a non-disabled form input element. The HTML from the example above produces this result:</p>
        <fieldset>
          <samp><!-- using the disabled attribute prevents the end user from entering text into the input box -->
<input type="text" disabled>

<!-- text input is allowed, as it doesn't contain the disabled attribute -->
<input type="text">
          </samp>
        </fieldset>
      </section>
      <section class="main-section" id="Anatomy_of_an_HTML_document">
        <header class="main">Anatomy of an HTML document</header>
        <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>
        <div class="code">
          <code><p>&lt!DOCTYPE html></p>
<p>&lthtml></p>
  <p>&nbsp&nbsp&lthead></p>
    <p>&nbsp&nbsp&nbsp&nbsp&ltmeta charset="utf-8"></p>
    <p>&nbsp&nbsp&nbsp&nbsp&lttitle>My test page&lt/title></p>
  <p>&nbsp&nbsp&lt/head><p>
  <p>&nbsp&nbsp&ltbody></p>
    <p>&nbsp&nbsp&nbsp&nbsp&ltp>This is my page&lt/p></p>
  <p>&nbsp&nbsp&lt/body></p>
<p>&lt/html></p></code>
        </div>
        <p>Here we have:</p>
        <ol>
          <li>&lt!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:
            <div class="code">
              <code>&lt!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></code>
            </div>
            <p>More recently, the doctype is a historical artifact that needs to be included for everything else to work right. &lt!DOCTYPE html> is the shortest string of characters that counts as a valid doctype. That is all you need to know!</p>
          </li>
          <li>&lthtml>&lt/html>: The &lthtml> element. This element wraps all the content on the page. It is sometimes known as the root element.
          </li>
          <li>&lthead>&lt/head>: The &lthead> 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 will learn more about this in the next article of the series.
          </li>
          <li>&ltmeta charset="utf-8">: The &ltmeta> element. This element represents metadata that cannot be represented by other HTML meta-related elements, like &ltbase>, &ltlink>, &ltscript>, &ltstyle> or &lttitle>. The charset attributes sets 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>&lttitle>&lt/title>: The &lttitle> 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>&ltbody>&lt/body>: The &ltbody> element. This contains all the content that displays on the page, including text, images, videos, games, playable audio tracks, or whatever else.
          </li>
        </ol>
      </section>
      <section class="main-section" id="Whitespace_in_HTML">
        <header>Whitespace in HTML</header>
        <p>In the examples above, you may have noticed that a lot of whitespace is included in the code. This is optional. These two code snippets are equivalent:</p>
        <div class="code">
          <code><p>&ltp>Dogs are silly.&lt/p></p>

<p>&ltp>Dogs        are</p><p>&nbsp&nbsp&nbsp&nbsp
         silly.&lt/p></p></code>
        </div>
        <p>No matter how much whitespace you use inside HTML element content (which can include one or more space character, but also line breaks), the HTML parser reduces each sequence of whitespace to a single space when rendering the code. So why use so much whitespace? The answer is readability.</p>
        <p>It can be easier to understand what is going on in your code if you have it nicely formatted. In our HTML we've got each nested element indented by two spaces more than the one it is sitting inside. It is up to you to choose the style of formatting (how many spaces for each level of indentation, for example), but you should consider formatting it.</p>
      </section>
      <section class="main-section" id="Entity_references:_Including_special_characters_in_HTML">
        <header class="main">Entity references: Including special characters in HTML</header>
        <p>In HTML, the characters &lt, >,",' and & are special characters. They are parts of the HTML syntax itself. So how do you include one of these special characters in your text? For example, if you want to use an ampersand or less-than sign, and not have it interpreted as code.</p>
        <p>You do this with character references. These are special codes that represent characters, to be used in these exact circumstances. Each character reference starts with an ampersand (&), and ends with a semicolon (;).</p>
        <table>
          <thead>
            <tr>
              <th>Literal character</th>
              <th>Character reference equivalent</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>&lt;</td>
              <td><code>&amp;lt;</code></td>
            </tr>
            <tr>
              <td>&gt;</td>
              <td><code>&amp;gt;</code></td>
            </tr>
            <tr>
              <td>"</td>
              <td><code>&amp;quot;</code></td>
            </tr>
            <tr>
              <td>'</td>
              <td><code>&amp;apos;</code></td>
            </tr>
            <tr>
              <td>&amp;</td>
              <td><code>&amp;amp;</code></td>
            </tr>
          </tbody>
        </table>
        <p>The character reference equivalent could be easily remembered because the text it uses can be seen as less than for '&lt;' , quotation for ' &quot; ' and similarly for others.</p>
        <div class="note">
          <strong>Note:</strong>
          <ul> 
           <li>You don't need to use entity references for any other symbols, as modern browsers will handle the actual symbols just fine as long as your HTML's character encoding is set to UTF-8.
            </li>
          </ul>
        </div>
      </section>
      <section class="main-section" id="HTML_comments">
        <header class="main">HTML comments</header>
        <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 &lt!-- and -->. For example:</p>
        <div class="code">
          <code><p>&ltp>I'm not inside a comment&lt/p></p>

<p>&lt!-- &ltp>I am!&lt/p> --></p></code>
        </div>
        <p>As you can see below, only the first paragraph is displayed in the live output.</p>
        <fieldset>
          <samp><p>I'm not inside a comment</p>

<!-- <p>I am!</p> --></samp>
        </fieldset>
      </section>
      <section class="main-section" id="Reference">
        <header class="main">Reference</header>
        <p>All the documentation in this article is taken from <a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started#attributesMDN" target="_blank">MDN</a>.
        </p>
      </section>
    </main>
  </body>
</html>
              
            
!

CSS

              
                @media (prefers-reduced-motion: no-preference) {
  * {
    scroll-behavior: smooth;
  }
}

.note {
  background: #e7f5fe;
  padding: 1rem 1rem .5rem 1rem;
  margin-top: 1.5rem;
  border-radius: .5rem;
}

.code {
  background: #f5f5f5;
  padding: 1rem;
  margin-top: .5rem;
  margin-bottom: 1.25rem;
  border-radius: .5rem;
  word-wrap: break-word;
}

header {
  font-size: 1.75rem;
  margin-top: 2rem;
}

.main {
  font-weight: bold;
}

p {
  margin-bottom: 0;
}

img {
  margin-top: .5rem;
  max-width: 100%;
}

table, ul, ol {
  margin-top: .5rem
}

fieldset {
  margin-top: .5rem;
  margin-bottom: 1.25rem;
}

th, td {
  border: solid 1px;
  text-align: center;
  padding: 0.5rem;
}

table {
  border: solid 1px;
  margin: 0.5rem auto;
}

.code p:first-child, samp p {
  margin:0;
}

#main-doc {
  position: absolute;
  padding: 1rem;
  padding-bottom: 5rem;
  margin: -1rem 1rem 10rem 15.5rem;
}

#navbar {
  position: fixed;
  min-width: 14rem;
  top: 0px;
  left: 0px;
  width: 15rem;
  height: 100%;
  border-right: solid;
  border-color: #5e7388;
  background: #3a3b3c;
}

#navbar header {
  text-align: center;
  margin-top: .5rem;
  color: white;
}

#navbar ul {
  height: 85%;
  padding: 0;
  overflow-y: auto;
}

#navbar li {
  border-top: 1px solid;
  list-style: none;
  position: relative;
  border-color: #5e7388;
  width: 100%;
}

#navbar a {
  display: block;
  padding: .5rem 1.9rem;
  color: white;
  text-decoration: none;
  cursor: pointer;
}

@media only screen and (max-width: 700px) {
  #navbar ul {
    border: 1px solid;
    height: 10rem;
  }

  #navbar {
    position: absolute;
    top: 0;
    padding: 0;
    margin: 0;
    width: 100%;
    max-height: 13rem;
    z-index: 1;
    border-bottom: 1px solid;
  }

  #main-doc {
    position: relative;
    margin-left: 1rem;
    margin-top: 15rem;
    padding:0;
  }
}

li p {
  margin-bottom: 1rem;
}
              
            
!

JS

              
                
              
            
!
999px

Console