Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

              
                <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 (&lt;p&gt;) element:</p>
        <code>&lt;p&gt;My cat is very grumpy&lt;/p&gt;</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 &lt;strong> element, which means that the word is to have strong(er) text formatting:
        </p>
        <code>
          &lt;p&gt;My cat is &lt;strong&gt;very&lt;/strong&gt;&lt;/p&gt;
        </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>&lt;p&gt;My cat is &lt;strong>very grumpy.&lt;/p&gt;&lt;/strong&gt;</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 &lt;a> element creates a hyperlink, and elements such as &lt;em> or &lt;strong> create emphasis.</li>
        </ul>
        <p>Consider the following example:</p>
        <code>&lt;em&gt;first&lt;/em&gt;&lt;em&gt;second&lt;/em&gt;&lt;em&gt;third&lt;/em&gt;
          &lt;p&gt;fourth&lt;/p&gt;&lt;p&gt;fifth&lt;/p&gt;&lt;p&gt;sixth&lt;/p&gt;</code>
        <p>&lt;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, &lt;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 &lt;img> element embeds an image file onto a page:</p>
        &lt;img src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png"&gt;
        <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>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;My test page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;This is my page/p&gt;
  &lt;/body&gt;
&lt;/html&gt;</code>
</pre>
        <p>Here we have:</p>
        <ol>
          <li>&lt;!DOCTYPE html&gt;: 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">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;</pre>

            More recently, the doctype is a historical artifact that needs to be included for everything else to work right. &lt;!DOCTYPE html&gt; is the shortest string of characters that counts as a valid doctype. That is all you need to know!
          </li>
          <li>&lt;html&gt;&lt;/html&gt;: The &lt;html&gt; element. This element wraps all the content on the page. It is sometimes known as the root element.</li>
          <li>&lt;head&gt;&lt;/head&gt;: The &lt;head&gt; 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>&lt;meta charset="utf-8"&gt;: 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>&lt;title&gt;&lt;/title&gt;: The &lt;title&gt; 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>&lt;body&gt;&lt;/body&gt;: The &lt;body&gt; 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 &lt;!-- and -->. For example:</p>
        <code>&lt;p&gt;I'm not inside a comment&lt;/p&gt;

          &lt;!-- p&gt;I am!&lt;/p&gt; --&gt;
        </code>
        <p>As you can see below, only the first paragraph displays in the live output.</p>

        <code>&lt;p&gt;I'm not inside a comment&lt;/p&gt;</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>
              
            
!

CSS

              
                * {
  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;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console