HTML is written in the form of HTML elements consisting of tags enclosed in angle brackets (like
<html>). HTML tags most commonly come in pairs like
</h1>, although some tags represent empty elements and so are unpaired, for example
<img>. The first tag in a pair is the start tag, and the second tag is the end tag (they are also called opening tags and closing tags).
Elements are often made of multiple sets of tags, identified as opening and closing tags. Opening tags mark the beginning of an element, such as
<div>. Closing tags mark the end of an element and begin with a forward slash, such as
<div>, <p> and <ul>
Elements are designators that define objects within a page, including structure and content. Some of the more popular elements include h1 through h6, p, a, div, span, strong, and em.
<h1> … </h1>
Attributes are properties used to provide additional instruction to given elements. More commonly, attributes are used to assign an id, class, or title to an element, to give media elements a source (src), or to provide a hyperlink reference (href).
<a href="http://www.apple.com">Apple</a> <div class=”foo”> … </div>
Thanks to HTML5, we now have the ability to embed custom data attributes on all HTML elements. These new custom data attributes consist of two parts:
The data attribute name must be at least one character long and must be prefixed with
data-. It should not contain any uppercase letters.
The attribute value canUsing this syntax, we can add application data to our markup as shown below:
<ul id="vegetable-seeds"> <li data-spacing="10cm" data-sowing-time="March to June">Carrots</li> <li data-spacing="30cm" data-sowing-time="February to March">Celery</li> <li data-spacing="3cm" data-sowing-time="March to September">Radishes</li> </ul>
All HTML documents have a required structure that includes the following declaration and tags:
doctype declaration is used to instruct web browsers which version of HTML is being used and is placed at the very beginning of the HTML document.
The head of the document is used to outline any meta data, the document title, and links to any external files.
Any context included within the head tags is not visible within the actual web page itself.
All of the content visible within the web page will fall within the body tags.
<!DOCTYPE html> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="css/main.css"> </head> <body> <h1>Hello World</h1> <p>This is a website.</p> <script src="js/main.js"></script> </body> </html>
Defines the main or important content in the document. There is only one
<main> element in the document.
<main> ... </main>
Defines the header of a page or section. It often contains a logo, the title of the Web site, and a navigational table of content.
<header> ... </header>
Defines the footer for a page or section. It often contains a copyright notice, some links to legal information, or addresses to give feedback.
<footer> ... </footer>
Defines a section in a document, only just a little more semantic then a
<section> ... </section>
Defines self-contained content that could exist independently of the rest of the content.
<article> ... </article>
Defines a section that contains only navigation links
<nav> ... </nav>
Defines some content loosely related to the page content. If it is removed, the remaining content still makes sense.
<aside> ... </aside>
This is a quick reference of elements that are new or have been redefined in HTML5. For each element there is a short description, a link to the specification, and a code example. “Our prognosis” links to the HTML5 Doctor article on the element. There are more articles in the Article Archive.
An easy-to-understand HTML5 sectioning element flowchart to help you get to grips with some of the new elements in HTML5.
A cross-platform and language-independent convention for representing and interacting with objects in
NOTE: The DOM tree is NOT
With the advent of JS MVVM frameworks and other DOM manipulators, much can happen after the fact that
view source will not show.
To render a document such as an HTML page, most web browsers use an internal model similar to the DOM.
The nodes of every document are organized in a tree structure, called the DOM tree, with topmost node named "Document object".
When an HTML page is rendered in browsers, the browser downloads the HTML into local memory and automatically parses it to display the page on screen.
Web browsers rely on layout engines to parse HTML into a DOM.