HTML Documentation
Introduction

HTML, or HyperText Markup Language, is a markup language used to describe the structure of a web page. It uses a special syntax or notation to organize and give information about the page to the browser. Elements usually have opening and closing tags that surround and give meaning to content. For example, there are different tag options to place around text to show whether it is a heading, a paragraph, or a list.

For example:


    <h1>Top level heading: Maybe a page title</h1>
        <p>A paragraph of text. Some information we would like to communicate to the viewer. This can be as long or short as we would like.</p>
                        
            <ol>
                <li>Number one on the list</li>
                <li>Number two</li>
                <li>A third item</li>
                <li>Four</li>
                <li>Five</li>
            </ol>
                    

Becomes:

Top level heading: Maybe a page title

A paragraph of text. Some information we would like to communicate to the viewer. This can be as long or short as we would like.

  1. Number one on the list
  2. Number two
  3. A third item
  4. Four
  5. Five

The HyperText part of HTML comes from the early days of the web and its original use case. Pages usually contained static documents that contained references to other documents. These references contained hypertext links used by the browser to navigate to the reference document so the user could read the reference document without having to manually search for it. As web pages and web applications grow more complex, the W3 Consortium updates the HTML specification to ensure that a webpage can be shown reliably on any browser. The latest version of HTML is HTML5.


Comment out HTML

Remember that in order to start a comment, you need to use <!-- and to end a comment, you need to use -->


HTML5 Elements

HTML5 introduces more descriptive HTML tags. These include main, header, footer, nav, video, article, section and others.

These tags give a descriptive structure to your HTML, make your HTML easier to read, and help with Search Engine Optimization (SEO) and accessibility. The main HTML5 tag helps search engines and other developers find the main content of your page.

Example usage, a main element with two child elements nested inside it:


    <main>
        <h1>Hello World!</h1>
        <p>Hello World!</p>
    </main>
                    

NOTE: Many of the new HTML5 tags and their benefits are covered in the Applied Accessibility section.


Add Images

You can add images to your website by using the img element, and point to a specific image's URL using the src attribute.

An example of this would be:


    <img src="https://www.freecatphotoapp.com/your-image.jpg">
                    

NOTE! That img elements are self-closing.

All img elements must have an alt attribute. The text inside an alt attribute is used for screen readers to improve accessibility and is displayed if the image fails to load.

Note: If the image is purely decorative, using an empty alt attribute is a best practice.

Ideally the alt attribute should not contain special characters unless needed.


Ordered List

HTML has another special element for creating ordered lists, or numbered lists.

Ordered lists start with an opening <ol> element, followed by any number of <li> elements. Finally, ordered lists are closed with the </ol> tag.

For example:


    <ol>
        <li>Garfield</li>
        <li>Sylvester</li>
    </ol>
                    

would create a numbered list of "Garfield" and "Sylvester".


Form Element

You can build web forms that actually submit data to a server using nothing more than pure HTML. You can do this by specifying an action on your form element.

For example:


    <form form action="/url-where-you-want-to-submit-form-data"></form>
                    

Nest the existing input element inside a form element and assign "https://freecatphotoapp.com/submit-cat-photo" to the action attribute of the form element.


Radio Buttons

You can use radio buttons for questions where you want the user to only give you one answer out of multiple options.

Radio buttons are a type of input.

Here's an example of a radio button:


    <label>
        <input type="radio" name="indoor-outdoor">Indoor
    </label>
                    

It is considered best practice to set a for attribute on the label element, with a value that matches the value of the id attribute of the input element. This allows assistive technologies to create a linked relationship between the label and the child input element. For example:


    <label for="indoor">
        <input id="indoor" type="radio" name="indoor-outdoor">Indoor
    </label>
                    


Checkboxes

Forms commonly use checkboxes for questions that may have more than one answer.

Checkboxes are a type of input.

Each of your checkboxes can be nested within its own label element. By wrapping an input element inside of a label element it will automatically associate the checkbox input with the label element surrounding it.

All related checkbox inputs should have the same name attribute.

It is considered best practice to explicitly define the relationship between a checkbox input and its corresponding label by setting the for attribute on the label element to match the id attribute of the associated input element.

Here's an example of a checkbox:


    <label for="loving"><input id="loving" type="checkbox" name="personality"> Loving</form>
                    


Declare Doctype

The challenges so far have covered specific HTML elements and their uses. However, there are a few elements that give overall structure to your page, and should be included in every HTML document.

At the top of your document, you need to tell the browser which version of HTML your page is using. HTML is an evolving language, and is updated regularly. Most major browsers support the latest specification, which is HTML5. However, older web pages may use previous versions of the language.

You tell the browser this information by adding the <!DOCTYPE ...> tag on the first line, where the ... part is the version of HTML. For HTML5, you use <!DOCTYPE html>.

Next, the rest of your HTML code needs to be wrapped in html tags. The opening <html> goes directly below the <!DOCTYPE html> line, and the closing </html> goes at the end of the page.

Here's an example of the page structure:


    <!DOCTYPE html>
    <html>
        <!-- Your HTML code goes here -->
    </html>
                    


Head and Body

You can add another level of organization in your HTML document within the html tags with the head and body elements. Any markup with information about your page would go into the head tag. Then any markup with the content of the page (what displays for a user) would go into the body tag.

Metadata elements, such as link, meta, title, and style, typically go inside the head element.

Here's an example of a page's layout:


    <!DOCTYPE html>
    <html>
        <head>
            <!-- Metadata elements -->
        </head>
        <body>
            <!-- Page content -->
        </body>
    </html>