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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>
  <head>
    <meta charset="UTF-8">
    <title>Basic HTML</title>
  <link rel="stylesheet" href="stylesheet.css" type="text/css">
  </head>
  <body>
    <nav id="navbar">
      <header>
        Basic HTML
      </header>
      <ul>
        <li>
          <a class="nav-link" href="#Introduction_to_Basic_HTML">Introduction to Basic HTML</a>
        </li>
        <li>
          <a class="nav-link" href="#So_what_is_HTML?">So what is HTML?</a>
        </li>
        <ul>
          <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="#Empty_elements">Empty elements </a>
          </li>
          <li>
            <a class="nav-link" href="#Anatomy_of_an_HTML_document">Anatomy of an HTML document</a>
          </li>
        </ul>
        <li>
          <a class="nav-link" href="#Images">Images</a>
        </li>
        <li>
          <a class="nav-link" href="#Marking_up_text">Marking up text</a>
        </li>
        <ul>
          <li>
            <a class="nav-link" href="#Headings">Headings</a>
          </li>
          <li>
            <a class="nav-link" href="#Paragraphs">Paragraphs</a>
          </li>
          <li>
            <a class="nav-link" href="#Lists">Lists</a>
          </li>
        </ul>
        <li>
        <a class="nav-link" href="#Links">Links</a>
      </li>
        <li>
          <a class="nav-link" href="#Conclusion">Conclusion</a>
        </li>
      </ul>
      <p>
        All Resources by <a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics">MDN</a>.
      </p>
    </nav>
    <main id="main-doc">
      <section class="main-section" id="Introduction_to_Basic_HTML">
        <header>Introduction to Basic HTML</header>
        <article>
        <p>
        HTML (<b>H</b>yper<b>t</b>ext <b>M</b>arkup <b>L</b>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. As the title suggests, this article will give you a basic understanding of HTML and its functions.
        </p>
        </article>
      </section>
      <hr />

      <section class="main-section" id="So_what_is_HTML?">
        <header>So what is HTML?</header>
        <article>
        <p>
        HTML is not a programming language; it is a <em>markup language</em> 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>
        <code>My cat is very grumpy</code>
        <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>
        <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><mark>Anatomy of an HTML element</mark></header>
        <article>
        <p>
        Let's explore this paragraph element a bit further.
        </p>
        <image src="https://mdn.mozillademos.org/files/9347/grumpy-cat-small.png" alt="Anatomy of an HTML element" />
        <p>
        The main parts of our element are as follows:
        </p>
        <ol>
          <li>
            <b>The opening tag:</b> This consists of the name of the element (in this case, p), wrapped in opening and closing <b>angle brackets</b>. This states where the element begins or starts to take effect — in this case where the paragraph begins.
          </li>
          <li>
            <b>The closing tag:</b> This is the same as the opening tag, except that it includes a <em>forward slash</em> before the element name. This states where the element ends — in this case where the paragraph ends. Failing to add a closing tag is one of the standard beginner errors and can lead to strange results.
          </li>
          <li>
              <b>The content:</b> This is the content of the element, which in this case, is just text.
          </li>
          <li>
              <b>The element:</b> The opening tag, the closing tag and the content together comprise the element.
          </li>
        </ol>
        <p>
        Elements can also have attributes that look like the following:
        </p>
        <img src="https://mdn.mozillademos.org/files/9345/grumpy-cat-attribute-small.png" alt="Element Attributes" />
        <p>
        Attributes contain extra information about the element that you don't want to appear in the actual content. Here, <span class="code-element">class</span> is the attribute <em>name</em> and <span class="code-element">editor-note</span> is the attribute <em>value</em>. The class attribute allows you to give the element an identifier that can be used later to target the element with style information and other things.
        </p>
        <p>
        An attribute should always have the following:
        </p>
        <ol>
          <li>
            A space between it and the element name (or the previous attribute, if the element already has one or more attributes).
          </li>
          <li>
            The attribute name followed by an equal sign.
          </li>
          <li>
            The attribute value wrapped by opening and closing quotation marks.
          </li>
        </ol>
        </article>
      </section>

      <section class="main-section" id="Nesting_elements">
        <header><mark>Nesting elements</mark></header>
        <article>
          <p>
            You can put elements inside other elements too — this is called <b>nesting</b>. If we wanted to state that our cat is <b>very</b> grumpy, we could wrap the word "very" in a <span="code-element">&lt;strong&gt;</span> element, which means that the word is to be strongly emphasized:
          </p>
          <code>&lt;p&gt;My cat is &lt;strong&gt;very&lt;/strong&gt; grumpy.&lt;/p&gt;</code>
          <p>
          You do however need to make sure that your elements are properly nested. In the example above, we opened the <span class="code-element">&lt;p&gt;</span> element first, then the <span class="code-element">&lt;strong&gt;</span> element; therefore, we have to close the <span class="code-element">&lt;strong&gt;</span> element first, then the <span class="code-element">&lt;p&gt;</span> element. The following is incorrect:
          </p>
          <code>&lt;p&gt;My cat is &lt;strong&gt;very grumpy.&lt;/p&gt;&lt;/strong&gt;</code>
          <p>
          The elements have to open and close correctly so that they are clearly inside or outside one another. If they overlap as shown above, then your web browser will try to make the best guess at what you were trying to say, which can lead to unexpected results. So don't do it!
          </p>
        </article>
      </section>

      <section class="main-section" id="Empty_elements">
        <header><mark>Empty elements</mark></header>
        <article>
          <p>
            Some elements have no content and are called <b>empty elements</b>. Take the <span class="code-element">&lt;img&gt;</span> element that we already have in our HTML page:
          </p>
          <code>&lt;img src="images/firefox-icon.png" alt="My test image"&gt;</code>
          <p>
            This contains two attributes, but there is no closing <span class="code-element">&lt;/img&gt;</span> tag and no inner content. This is because an image element doesn't wrap content to affect it. Its purpose is to embed an image in the HTML page in the place it appears.
          </p>
        </article>
      </section>

      <section class="main-section" id="Anatomy_of_an_HTML_document">
        <header><mark>Anatomy of an HTML document</mark></header>
        <article>
          <p>
            That wraps up the basics of individual HTML elements, but they aren't handy on their own. Now we'll look at how individual elements are combined to form an entire HTML page. Let's revisit the code we put into our <span class="code-element">index.html</span> example (which we first met in the <a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/Dealing_with_files" target="_blank">Dealing with files</a> article):
          </p>
          <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;img src="images/firefox-icon.png" alt="My test image"&gt;
    &lt;/body&gt;
  &lt;/html&gt;
          </code>
          <p>
          Here, we have the following:
          </p>
          <ul>
            <li>
            <span class="code-element">&lt;!DOCTYPE html&gt;</span> — the doctype. It is required preamble. In the mists of time, when HTML was young (around 1991/92), doctypes were meant to act as links to a set of rules that the HTML page had to follow to be considered good HTML, which could mean automatic error checking and other useful things. However these days, they don't do much, and are basically just needed to make sure your document behaves correctly. That's all you need to know for now.
            </li>
            <li>
            <span class="code-element">&lt;html&gt;&lt;/html&gt;</span> — the <span class="code-element">&lt;html&gt;</span> element. This element wraps all the content on the entire page and is sometimes known as the root element.
            </li>
            <li>
            <span class="code-element">&lt;head&gt;&lt;/head&gt;</span> — the <span class="code-element">&lt;head&gt;</span> element. This element acts as a container for all the stuff you want to include on the HTML page that isn't the content you are showing to your page's viewers. This includes things like keywords and a page description that you want to appear in search results, CSS to style our content, character set declarations and more.
            </li>
            <li>
            <span class="code-element">&lt;meta charset="utf-8"&gt;</span> — This element sets the character set your document should use to UTF-8 which includes most characters from the vast majority of written languages. Essentially, it can now handle any textual content you might put on it. There is no reason not to  set this and it can help avoid some problems later on.
            </li>
            <li>
            <span class="code-element">&lt;title&gt;&lt;/title&gt;</span> — the <span class="code-element">&lt;title&gt;</span> element. This sets the title of your page, which is the title that appears in the browser tab the page is loaded in. It is also used to describe the page when you bookmark/favourite it.
            </li>
            <li>
            <span class="code-element">&lt;body&gt;&lt;/body&gt;</span> — the <span class="code-element">&lt;body&gt;</span> element. This contains all the content that you want to show to web users when they visit your page, whether that's text, images, videos, games, playable audio tracks or whatever else.
            </li>
          </ul>
        </article>
      </section>
      <hr />
      <section class="main-section" id="Images">
        <header>Images</header>
        <article>
          <p>
            Let's turn our attention to the <span class="code-element">&lt;img&gt;</span> element again:
          </p>
          <code>&lt;img src="images/firefox-icon.png" alt="My test image"&gt;</code>
          <p>
          As we said before, it embeds an image into our page in the position it appears. It does this via the src (source) attribute, which contains the path to our image file.
          </p>
          <p>
            We have also included an <span class="code-element">alt</span> (alternative) attribute. In this attribute, you specify descriptive text for users who cannot see the image, possibly because of the following reasons:
          </p>
          <ol>
            <li>
              They are visually impaired. Users with significant visual impairments often use tools called screen readers to read out the alt text to them.
            </li>
            <li>
              Something has gone wrong causing the image not to display. For example, try deliberately changing the path inside your src attribute to make it incorrect. If you save and reload the page, you should see something like this in place of the image:
              <div class="align-image">
                <img id="test-image" src="https://mdn.mozillademos.org/files/9349/alt-text-example.png" alt="My test image" />
              </div>
            </li>
          </ol>
          <p>
            The keywords for alt text are "descriptive text". The alt text you write should provide the reader with enough information to have a good idea of what the image conveys. In this example, our current text of "My test image" is no good at all. A much better alternative for our Firefox logo would be "The Firefox logo: a flaming fox surrounding the Earth."
          </p>
          <p>
            Try coming up with some better alt text for your image now.
          </p>
        </article>
      </section>
      <hr />
      <section class="main-section" id="Marking_up_text">
        <header>Marking up text</header>
        <article>
          <p>
           This section will cover some of the essential HTML elements you'll use for marking up the text.
         </p>
        </article>
      </section>

      <section class="main-section" id="Headings">
        <header><mark>Headings</mark></header>
        <article>
          <p>
            Heading elements allow you to specify that certain parts of your content are headings — or subheadings. In the same way that a book has the main title, chapter titles and subtitles, an HTML document can too. HTML contains 6 heading levels, <span class="code-element">&lt;h1&gt;</span>–<span class="code-element">&lt;h6&gt;</span>, although you'll commonly only use 3 to 4 at most:
          </p>
          <code>
&lt;h1&gt;My main title&lt;/h1&gt;
&lt;h2&gt;My top level heading&lt;/h2&gt;
&lt;h3&gt;My subheading&lt;/h3&gt;
&lt;h4&gt;My sub-subheading&lt;/h4&gt;
          </code>
          <p>
          Now try adding a suitable title to your HTML page just above your <span class="code-element">&lt;img&gt;</span> element.
        </p>
        </article>
      </section>

      <section class="main-section" id="Paragraphs">
        <header><mark>Paragraphs</mark></header>
        <article>
          <p>
            As explained above, <span class="code-element">&lt;p&gt;</span> elements are for containing paragraphs of text; you'll use these frequently when marking up regular text content:
          </p>
          <code>&lt;p&gt;This is a single paragraph&lt;/p&gt;</code>
          <p>
            Add your sample text (you should have it from <a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/What_will_your_website_look_like" target="_blank">What should your website look like?</a>) into one or a few paragraphs, placed directly below your <span class="code element">&lt;img&gt;</span> element.
          </p>
        </article>
      </section>

      <section class="main-section" id="Lists">
        <header><mark>Lists</mark></header>
        <article>
          <p>
          A lot of the web's content is lists and HTML has special elements for these. Marking up lists always consist of at least 2 elements. The most common list types are ordered and unordered lists:
          </p>
          <ol>
            <li>
              Unordered lists are for lists where the order of the items doesn't matter, such as a shopping list. These are wrapped in a <span class="code-element">&lt;ul&gt;</span> element.
            </li>
            <li>
              Ordered lists are for lists where the order of the items does matter, such as a recipe. These are wrapped in an <span class="code-element">&lt;ol&gt;</span> element.
            </li>
          </ol>
          <p>
          Each item inside the lists is put inside an <span class="code-element">&lt;li&gt;</span> (list item) element.
          </p>
          <p>
            For example, if we wanted to turn the part of the following paragraph fragment into a list
          </p>
          <code>&lt;p&gt;At Mozilla, we’re a global community of technologists, thinkers, and builders working together ... &lt;/p&gt;</code>
          <p>
            We could modify the markup to this
          </p>
          <code>
&lt;p&gt;At Mozilla, we’re a global community of&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;technologists&lt;/li&gt;
  &lt;li&gt;thinkers&lt;/li&gt;
  &lt;li&gt;builders&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;working together ... &lt;/p&gt;
          </code>
          <p>
            Try adding an ordered or unordered list to your example page.
          </p>

        </article>
      </section>
      <hr />
      <section class="main-section" id="Links">
        <header><mark>Links</mark></header>
        <article>
          <p>
            Links are very important — they are what makes the web a web! To add a link, we need to use a simple element — <span class="code-element">&lt;a&gt;</span> — "a" being the short form for "anchor". To make text within your paragraph into a link, follow these steps:
          </p>
          <ol>
            <li>
              Choose some text. We chose the text "Mozilla Manifesto".
            </li>
            <li>
              Wrap the text in an <span class="code-element">&lt;a&gt;</span> element, as shown below:
              <code>&lt;a&gt;Mozilla Manifesto&lt;/a&gt;</code>
            </li>
            <li>
              Give the &lt;a&gt; element an href attribute, as shown below:
              <code>&lt;a href=""&gt;Mozilla Manifesto&lt;/a&gt;</code>
            </li>
            <li>
              Fill in the value of this attribute with the web address that you want the link to link to:
              <code>&lt;a href="https://www.mozilla.org/en-US/about/manifesto/"&gt;Mozilla Manifesto&lt;/a&gt;</code>
            </li>
          </ol>
          <p>
          You might get unexpected results if you omit the <span class="code-element">https://</span> or <span class="code-element">http://</span> part, called the <em>protocol</em>, at the beginning of the web address. After making a link, click it to make sure it is sending you where you wanted it to.
          </p>
        </article>
      </section>
      <hr />
      <section class="main-section" id="Conclusion">
        <header>Conclusion</header>
        <article>
          <p>
            If you have followed all the instructions in this article, you should end up with a page that looks like the one below (you can also <a href="http://mdn.github.io/beginner-html-site/">view it here</a>):
          </p>
          <img src="https://mdn.mozillademos.org/files/9351/finished-test-page-small.png" alt="Test Website Preview"/>
          <p>
            If you get stuck, you can always compare your work with our <a href="https://github.com/mdn/beginner-html-site/blob/gh-pages/index.html" target="_blank">finished example code</a> on GitHub.
          </p>
          <p>
            Here, we have only really scratched the surface of HTML. To find out more, go to our <a href="https://developer.mozilla.org/en-US/docs/Learn/HTML" target="_blank">Learning HTML</a> topic.
          </p>
        </article>
      </section>

      <footer>
        All Resources by <a href="https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics">MDN</a>.
      </footer>
      </main>
  </body>
</html>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Open+Sans|Raleway:500&display=swap');

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Open Sans', sans-serif;
  min-width: 280px;
  line-height: 1.5;
  background-color: white;
}

h1, h2, h3 {
  font-family: 'Raleway', sans-serif;
}

p {
  font-family: 'Open Sans', sans-serif;
  font-size: 14px;
}

a {
  color: inherit;
}

a:hover {
  color: #990000;
}

a:visited {
  color: #737373;
}

hr {
  border: 1.5px solid #990000;
}

/* navigation */
@media only screen and (min-width: 671px) {
/* for desktop */
  body {
    display: flex;
    flex-flow: row wrap;
    justify-content: flex-start;
    text-align: left;
    align-items: flex-start;
  }

  body > * {
    flex: 1 100%;
  }

  nav {
    height: 100%;
    border-right: solid;
    border-color: #990000;
    padding: 10px;
    order: 1;
    flex: 1 10%;
  }

  #navbar > ul {
    list-style: none;
    margin: 0;
  }

  #navbar > ul > ul {
    list-style: none;
  }

  main {
    width: 70%;
    text-align: left;
    padding: 10px 10% 10px 10%;
    max-height: 100vh;
    order: 2;
    flex: 1 auto;
    overflow: scroll;
  }
}

@media only screen and (max-width: 670px) {
    /* For mobile phones: */
  body {
    display: flex;
    flex-flow: column nowrap;
    justify-content: flex-start;
    text-align: left;
    align-items: flex-start;
  }

  nav {
    display: block;
    height: 400px;
    width: 100%;
    border-bottom: solid;
    border-color: #990000;
    padding: 10px 10% 10px 10%;
  }

  #navbar > ul {
    list-style: none;
    margin: 0;
  }

  #navbar > ul > ul {
    list-style: none;
  }

  main {
    text-align: left;
    padding: 10px 10% 10px 10%;
    width: 100%;
  }
}

/* main content */

footer {
  padding: 20px 0;
}

.main-section {
  display: block;
  text-align: left;
  font-family: 'Raleway', sans-serif;
}

mark {
  padding: 5px 5px 5px 50px;
  background-color: #990000;
  font-size: 18px;
  color: #FFF;
  font-family: 'Raleway', sans-serif;
}

article {
  margin-top: 10px;
}

header {
  font-size: 700;
  font-size: 20px;
  font-family: 'Raleway', sans-serif;
}

.main-section header {
  font-size: 700;
  font-size: 24px;
}

.align-image {
  text-align: center;
}

#test-image {
  display: inline-block;
  margin: 10px 0;
}

img {
  object-fit: contain;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 20px 0;
}

code {
  display: block;
  white-space: pre-wrap;
  background-color: #C0C0C0;
  margin: 5px;
  padding: 10px 15px;
  word-break: normal;
  word-wrap: normal;
}

.code-element {
  font-family: courier, monospace;
  background-color: #C0C0C0;
  padding: 1px;
}

              
            
!

JS

              
                
              
            
!
999px

Console