Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Examining the structure of an HTML document

From: HTML Essential Training

Video: Examining the structure of an HTML document

A complete HTML document has several important parts. Let's take a look at what some of them are. I'll start by making a working copy of structure.html here. I am pressing Command+C and Command+V on this Mac. You would use Ctrl+C and Ctrl+V on a PC and I'm renaming the copy to be structure-working, and I am going to open it in my text editor. I am using TextWrangler here on this Mac. You can use whatever text editor you like on a Mac or on a PC, or on any platform, as long as it's a plain text editor and not a word processor or an HTML editor.

Examining the structure of an HTML document

A complete HTML document has several important parts. Let's take a look at what some of them are. I'll start by making a working copy of structure.html here. I am pressing Command+C and Command+V on this Mac. You would use Ctrl+C and Ctrl+V on a PC and I'm renaming the copy to be structure-working, and I am going to open it in my text editor. I am using TextWrangler here on this Mac. You can use whatever text editor you like on a Mac or on a PC, or on any platform, as long as it's a plain text editor and not a word processor or an HTML editor.

So this is a minimal document with a number of typical elements that you'll see in a lot of HTML documents. This is not the minimum allowable document. It's just a small document with some basic elements that you will probably want to include in most of your HTML documents. The purpose here is to have a discussion about the structure of an HTML document and many of these subjects will be covered in more detail throughout the rest of this course. So here on the first line, we have the DOCTYPE declaration. The purpose of this is to tell the browser what version of HTML to be expecting in the rest of the document.

If you've seen DOCTYPE declarations before, you'll notice that this one is very, very simple. This is the way the DOCTYPE declaration is supposed to look in an HTML5 compliant document. HTML4 and other versions of HTML have a much more complicated DOCTYPE that includes a DTD and things like that. Because HTML has now been divorced from SGML, we don't need a DTD; a DTD is actually no longer even a valid thing to do, and so, the purpose of this DOCTYPE declaration has become just to tell the browser, don't use Quirks mode, use Standards mode.

This is a standards compliant document. So the DOCTYPE element looks like this. It has a left angle bracket, an exclamation point, the word DOCTYPE in all caps, and the word HTML separated by a space in all lowercase and a right angle bracket. It should be the very first thing in your document before any comments, even before any white space. If it's not the very first thing, it will work in some browsers. It won't work in other browsers. In particular, many versions of Internet Explorer will fall back into Quirks mode if that DOCTYPE is not the very first thing in the file.

So you just put it at the very top before any of your comments or anything else. You get used to putting it there and it'll do its job across the board. The next thing in this document is a comment, and you'll see that here on line two, a comment is introduced by a left angle bracket, and an exclamation point followed by two dashes and a space. And this is all very important, so it's all of these pieces here. Leaving out any of these pieces will make it work as a comment in some browsers and in some browsers, they won't know it's a comment and they'll try to do something else with it.

So it's a good idea just to always do your comments like this with all five of those characters, the left angle bracket, the exclamation point, the two dashes and the space. And then at the end of the comment, you have these four characters, a space followed by two dashes and a right angle bracket. And again, some browsers might not insist on the space. Some browsers might allow white space in between some of these things, but the point is, is that if you want it to be interpreted as a comment across the board, just always do it that way and it will always work.

You can have all kinds of space and multiple lines and things like that inside your comment, so this all works just fine like that. The one thing you will want to avoid is anywhere in your comment having two dashes. I am going to put this in here and you'll see that even this editor stops interpreting the rest of the document as an HTML document when it sees those extra two dashes inside of the comment. The reason for that is mired in legacy with SGML, but the point is, is that it confounds the parsers in a lot of browsers, and so you'll just want to not use two dashes right next to each other within any of your comments.

So I am going to go ahead and get rid of all this extra white space that we introduced, and save it, and now we have just our little one line comment. Now the rest of this document starting with this HTML tag on line four, and going all the way down to the close HTML tag on line 22, the rest of this document is a tree of elements, called a DOM tree, Document Object Model tree. At the root of the tree is the HTML element and you'll notice here we have an opening tag, and tags in HTML they have this left angle bracket and then the name of the tag, and then any attributes, and then a right angle bracket.

And so this tag here is an HTML tag, and you will notice down here on line 22, is what's called an end tag or a closing tag. And it looks just like the HTML tag except it has this little slash before the word html. And so the name of this tag is HTML and the beginning tag is formed like that, which is the left angle bracket and the word html, and then whatever else goes inside there, the attributes, and then a closing angle bracket, a right angle bracket. An end tag looks like this, with a left angle bracket followed by a slash, that's a forward slash, and the name of the tag and then a closing angle bracket and an end tag will never have any attributes.

So it will always be just like that, the name of the tag followed by the right angle bracket. So that makes this head element a container. So everything from the opening tag to the end tag, including everything in between is all part of that HTML element. So the contents of the element includes this head element, which starts there and ends there, and this body element, which starts there and ends there, and the contents of head includes all of these elements, meta, title, link, and the contents of the body element includes these two elements, h1 and p, and the head element and the body element are both children of the HTML element.

And so they are branches on the tree. You could consider the HTML element to be the root of the tree or the trunk of the tree and head and body to be sibling children or branches at the same level. And so the parent of the head element is HTML and its children are meta, title, and link, and body can be considered its sibling. So the head element is where you put things that are head matter inside of the document. These are things that apply to the entire document and so they include this meta tag which gives an information about the document.

There is the title tag which describes the title that's going to go in the Title Bar of the browser, and this link tag, which links other related documents, in this case, a CSS document, a style sheet, and even though I've specified this style sheet here, it's not actually in the folder and so it won't load, and we'll see as we bring this up in a browser later on that that's not going to affect the document. That missing CSS file is just going to be ignored. And then inside the body we have an h1 element which defines a header and that will be displayed bold, and the p element which describes a paragraph.

So let's take a look at this in our browser, and here's Firefox, and I am just going to say File > Open. I am going to navigate to my exercise files in Chapter 01, and here's structure-working.html. This is the document we are looking at, and I am going to open that up. You see here is our title HTML Document Structure. If I look at it in the editor, there it is in the title element, HTML Document Structure, so that shows up here in the Title Bar of the browser, and here's our h1 element and our p element, and those are right here h1 and p.

So these are the major parts of an HTML document and many of these topics are discussed in detail throughout the rest of this course.

Show transcript

This video is part of

Image for HTML Essential Training
HTML Essential Training

82 video lessons · 101476 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 24s
    1. Welcome
      56s
    2. Using the exercise files
      1m 37s
    3. What you need to know about this course
      2m 51s
  2. 22m 0s
    1. What is HTML?
      4m 12s
    2. Examining the structure of an HTML document
      7m 50s
    3. Understanding tags and containers
      6m 4s
    4. Exploring content models in HTML5
      2m 23s
    5. Looking at obsolete elements
      1m 31s
  3. 27m 19s
    1. Understanding whitespace and comments
      3m 53s
    2. Displaying text with paragraphs
      3m 37s
    3. Applying style
      8m 5s
    4. Using block and inline tags
      6m 34s
    5. Displaying characters with references
      5m 10s
  4. 16m 36s
    1. Exploring the front matter of HTML
      2m 9s
    2. Applying CSS to your document
      3m 59s
    3. Adding scripting elements
      4m 54s
    4. Using the meta tag
      3m 34s
    5. Optimizing your page for search engines
      2m 0s
  5. 24m 59s
    1. Controlling line breaks and spaces
      2m 46s
    2. Exploring phrase elements
      1m 44s
    3. Using font markup elements
      1m 5s
    4. Highlighting text with mark
      1m 29s
    5. Adding headings
      1m 38s
    6. Using quotations and quote marks
      3m 2s
    7. Exploring preformatted text
      1m 45s
    8. Formatting lists
      2m 28s
    9. Forcing text direction
      3m 49s
    10. Suggesting word-break opportunities
      2m 29s
    11. Annotating East Asian languages
      2m 44s
  6. 29m 15s
    1. Introducing CSS
      55s
    2. Understanding CSS placement
      6m 55s
    3. Exploring CSS syntax
      10m 34s
    4. Understanding CSS units of measure
      3m 3s
    5. Some CSS examples
      7m 48s
  7. 22m 5s
    1. Using images
      4m 13s
    2. Flowing text around an image
      4m 55s
    3. Breaking lines around an image
      3m 3s
    4. Aligning images
      5m 25s
    5. Mapping links in an image
      4m 29s
  8. 22m 28s
    1. Understanding URLs
      2m 41s
    2. Working with hyperlinks
      3m 28s
    3. Using relative URLs
      4m 20s
    4. Specifying a base URL
      2m 19s
    5. Linking within a page
      4m 12s
    6. Using image links
      5m 28s
  9. 17m 2s
    1. Exploring list types
      3m 52s
    2. List elements in depth
      7m 44s
    3. Using text menus with unordered lists
      5m 26s
  10. 15m 30s
    1. Introduction to HTML semantics
      4m 9s
    2. Exploring an example
      4m 56s
    3. Marking up figures and illustrations
      2m 33s
    4. Creating collapsible details
      3m 52s
  11. 11m 18s
    1. Embedding audio
      5m 19s
    2. Embedding video
      5m 59s
  12. 11m 53s
    1. Creating ad-hoc Document Object Model (DOM) data with the data-* attribute
      4m 53s
    2. Displaying relative values with meter
      2m 57s
    3. Creating dynamic progress indicators
      4m 3s
  13. 4m 49s
    1. Overview of HTML5 microdata
      1m 8s
    2. Exploring an example with microdata
      3m 41s
  14. 7m 3s
    1. Understanding outlines
      52s
    2. A demonstration of outlining
      6m 11s
  15. 13m 1s
    1. Table basics
      7m 29s
    2. Exploring the semantic parts of a table
      2m 32s
    3. Grouping columns
      3m 0s
  16. 9m 55s
    1. Frames overview
      54s
    2. Using traditional frames
      4m 26s
    3. Exploring inline frames using iframe
      2m 7s
    4. Simulating frames with CSS
      2m 28s
  17. 53m 7s
    1. Introducing forms
      10m 24s
    2. Using text elements
      10m 12s
    3. Using checkboxes and radio buttons
      2m 37s
    4. Creating selection lists and dropdown lists
      5m 14s
    5. Submit and button elements
      8m 48s
    6. Using an image as a submit button
      2m 15s
    7. Keeping context with the hidden element
      3m 0s
    8. Setting tab order
      2m 7s
    9. Preloading an autocomplete list using the datalist feature
      5m 26s
    10. Displaying results with output
      3m 4s
  18. 19m 47s
    1. Touring a complete site
      2m 14s
    2. Touring the HTML
      8m 44s
    3. Touring the CSS
      8m 49s
  19. 29s
    1. Goodbye
      29s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.