HTML Introduction

HTML (HyperText Markup Language) is the most basic building block of the Web. It defines the meaning and structure of web content. Other technologies besides HTML are generally used to describe a web page's appearance/presentation (CSS) or functionality/behavior (JavaScript).

"Hypertext" refers to links that connect web pages to one another, either within a single website or between websites. Links are a fundamental aspect of the Web. By uploading content to the Internet and linking it to pages created by other people, you become an active participant in the World Wide Web.

HTML uses "markup" to annotate text, images, and other content for display in a Web browser. HTML markup includes special "elements" such as <head>, <title>, <body>, <header>, <footer> and many others.

HTML Basics

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:

  • My cat is very grumpy
  • If we wanted the line to stand by itself, we could specify that it is a paragraph by enclosing it in paragraph tags:

  • <p>My cat is very grumpy</p>
  • HTML Elements

    Let's use the previous example to ilustrate how the elements work in HTML:

  • <p>My cat is very grumpy</p>
  • The main parts of our element are as follows:

    1. The opening tag: This consists of the name of the element (in this case, p), wrapped in opening and closing angle brackets. This states where the element begins or starts to take effect — in this case where the paragraph begins.
    2. The closing tag: This is the same as the opening tag, except that it includes a forward slash 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.
    3. The content: This is the content of the element, which in this case, is just text.
    4. The element: The opening tag, the closing tag, and the content together comprise the element.

    Elements can also have attributes, for example:

  • <p class="editor-note">My cat is very grumpy<p>
  • Attributes contain extra information about the element that you don't want to appear in the actual content. Here, class is the attribute name and editor-note is the attribute value. The class attribute allows you to give the element a non-unique identifier that can be used to target it (and any other elements with the same class value) with style information and other things. An attribute should always have the following:

    1. A space between it and the element name (or the previous attribute, if the element already has one or more attributes).
    2. The attribute name followed by an equal sign.
    3. The attribute value wrapped by opening and closing quotation marks.
    HTML Nest Elements

    You can put elements inside other elements too — 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 be strongly emphasized:

  • <p>My cat is <strong>very</strong> grumpy.</p>
  • You do however need to make sure that your elements are properly nested. In the example above, we opened the <p> element first, then the <strong> element; therefore, we have to close the <strong> element first, then the <p> element. The following is incorrect:

  • <p>My cat is <strong>very grumpy.</p></strong>
  • HTML Empty Elements

    Some elements have no content and are called empty elements. Take the <img> element that we already have in our HTML page:

  • <img src="images/firefox-icon.png" alt="My test image">
  • This contains two attributes, but there is no closing </img> 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.

    HTML Anatomy

    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 index.html example:

  • <!DOCTYPE html>
    <html>
     <head>
      <meta charset="utf-8">
      <title>My test page</title>
     </head>
     <body>
      <img src="images/firefox-icon.png" alt="My test image">
     </body>
    </html>
  • Here, we have the following:

    Reference

    All the documentation in this page is taken from https://developer.mozilla.org/en-US/docs/Web/HTML