Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
This course introduces web designers to the nuts and bolts of HTML (HyperText Markup Language), the programming language used to create web pages. Author Bill Weinman explains what HTML is, how it's structured, and presents the major tags and features of the language. Discover how to format text and lists, add images and flow text around them, link to other pages and sites, embed audio and video, and create HTML forms. Additional tutorials cover the new elements in HTML5, the latest version of HTML, and prepare you to start working with Cascading Style Sheets (CSS).
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.
Find answers to the most frequently asked questions about HTML Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.