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

HTML5 syntax

From: HTML5: Structure, Syntax, and Semantics

Video: HTML5 syntax

If you're making the jump to HTML5 from XHTML, you've probably heard some of the concerns over the syntax changes. If you haven't, most of it centers on the rather loose coding standards of HTML compared to that of XHTML. Now rather than go over them one by one, let's just re-examine our XHTML document and discuss some of the syntax rules that governed writing XTML. So we're looking currently at the xhtml.htm file that's found in 02_02 directory, and I just want to point out some of the coding rules that we pretty much had to follow when we were writing XHTML.

HTML5 syntax

If you're making the jump to HTML5 from XHTML, you've probably heard some of the concerns over the syntax changes. If you haven't, most of it centers on the rather loose coding standards of HTML compared to that of XHTML. Now rather than go over them one by one, let's just re-examine our XHTML document and discuss some of the syntax rules that governed writing XTML. So we're looking currently at the xhtml.htm file that's found in 02_02 directory, and I just want to point out some of the coding rules that we pretty much had to follow when we were writing XHTML.

For one thing, notice that all of the tag names are lowercase. Notice that for any tags that had attributes, those attributes are in quotation marks, and we have some tags that don't ever contain content, so those tags are being self-closed. You can see the meta tags here are self-closing. If I scroll down a little bit, I have a couple of line break tags down here, and those guys are self-closing as well. Now, those rules were driven, for the most part, by XML syntax requirements. Because most pages were served as text/html rather than application/xhtml, these syntax rules went largely ignored by browsers if authors didn't follow them.

Now, I am going to switch over to html5.htm. Again, this is from the 02_02 directory. It's the exact same file that we created in the last movie; it just has the content actually dumped into it. I want to examine some of the syntax rules now for HTML5. It's very loose, especially when you compare it with XHTML. Now, I am going to do some changes to the document here. If you're following along with me, you don't necessarily have to do these changes because when I am done with all of them, I am going to revert back to this file. So if you just want to kind of hang out for second and watch what I am about to do, that's fine. If you want to do it with me, that's cool too.

So let's go to the head tag here. Maybe I might take a look at this thing and make it all caps. So, I'll make it all caps, and I'll go to the title tag here and make the title tag all caps in the opening tag, but not in the closing tag. Quotation marks around utf-8. Let's go ahead and get rid of that, so no quotation marks around that. And just to really throw things, I am going to go to the body tag and I'll capitalize just the O in body. So, it kind of looks kind of cool, right? Believe it or not, this is all conforming HTML.

You can even take this further. In the HTML spec, for example, some of the opening and closing tags are optional. In terms of being optional for both the opening and the closing tag, you have HTML head and body. That means that I don't need the HTML opening tag, I don't need the head tag, I don't need the closing head tag, I don't need the opening body tag, and I don't need either of these closing tags. Some tags are just entirely optional to close. For example, list items, definition lists, paragraphs, table rows, table headings, table data cells, those types of things, we don't necessarily have to close them.

So I can come up to a paragraph here, for example, and just go ahead and get rid of the closing paragraph tag, and I am just going to go ahead and save that, okay? So, this is probably making some of you break out in cold sweats. Just to prove to you that this is conforming HTML, I am going to go ahead and validate this. Now, I know at the beginning of the title, I said, "Hey! I am not going to do anything in Dreamweaver that you can't do in other authoring programs," but I'm going to save myself a little bit of time here. Dreamweaver does have W3C validation baked right into it in the Dreamweaver CS5 version, which is really nice, handy tool.

Now if you don't have that, that's fine. You can go out online and you can got to validator.w3.org, and this is W3C's markup validation service. This is the same one that Dreamweaver uses. And you can either validate by a valid URL, you can upload a file, or you can just copy and paste your HTML directly into that. So if you do want to do this along with me, feel free to use this service instead of the Dreamweaver service; it's the exact same thing. So back in Dreamweaver, I am just going to go ahead and validate this document. And you can see, it says, hey, no errors or warnings found; everything is fine.

I am not even going to pretend that this is good authoring practice. I am just telling you this is allowed within the HTML syntax. For those of us that are used to writing using all those XHTML rules--and I have had them hammered into me year after year-- it can be a bit jarring. To help you understand this a little better remember, HTML5 and HTML itself is just a markup language; it's not an authoring language. It's designed to simply identify content, and that's it. The web is kind of a messy place, and the role of most user agents is to display the content the way the author intended, even if they're messy, non-human authors.

Now, because of this, HTML syntax gives us kind of a wide amount of latitude to how that content is formed. Now that we know kind of how far we can take it, let's take a look at what's practical within the scope of good authoring practice. So, the first thing I am going to do is I am going to come in here and sort of undo all those changes that I--those horrible, terrible changes that I made to the document. I am going to go ahead and undo those, okay. There we are. Good! So I am kind of back to where I started from. One of the things that I am going to do is I am going to keep all my tags in lowercase. Now, you could do one or the other, but I'd really recommend being consistent with it.

So I'm just going to go ahead and keep mine in all lowercase. I am also, going to keep the quotation marks around the attribute values. In some cases, you can pass multiple values as an attribute, and if you were to do that, you would definitely need the quotation marks. So, if you pass in another form of encoding along with this, you would need the separation. You would need the quotation mark. So just as a general rule, I err on the side of caution and go ahead and add them. Some attributes also contain Boolean values. So, some of the new HTML5 attributes have Boolean values.

Let me show you what I am mean. I am going to scroll down, and you see I've got a div with an id of sidebar, and it has the new hidden attribute. So notice hidden=hidden, so it's kind of redundant. So really, you can just present that this way. You can take off the attribute entirely. Just the presence of the attribute confirms that the value is true for that. So in cases of that syntax, I'm probably not going to put an attribute on there. I am just going to pass the attribute and let the browser go ahead and validate that. I am also going to go up to my link tag that's linking to my external style sheet, and one of the things that we don't need to pass along anymore is the type attribute, so where it says text/css.

These MIME types are now optional as our user agents are instructed to use the MIME type provided by the server for those external resources. So it's optional. I don't need it, so I am going to go ahead and get rid of that, and that just makes my code a little bit shorter, a little bit tighter. Same thing for your scripts. So if you are linking to external JavaScripts, or if you are using JavaScript on the page, JavaScript is actually assumed when the script tag is entered, so I don't need the type attribute for that either. Now, I would need it if I was doing something other than JavaScript. So, JavaScript is assumed. You can just leave it off for that. But for any other type of scripting language, you want to go ahead and pass the type value for that.

Other tags in HTML are considered void--that is, they can never ever contain any content. Like the meta tag, for example. Now, in XHTML, you remember, we had those self-closing tags that I just talked about a moment ago. So, I was trying to bridge the gap between the XML requiring a closing tag and HTML saying, yeah, but there is never anything in it. So these self-closing tags really aren't necessary anymore. And again, the irony involved in these is that everybody that was doing these-- and I certainly was chief among them-- when we were serving our pages as text/html, this was simply badly formed HTML, and it was HTML's loose syntax rules-- the one that I was complaining about--that allowed it in the first place, so...irony.

So I am going to remove that from the link tag. I don't have it on the meta tag, and then I am going to remove it from my line breaks down here as well. And this has probably been the hardest thing for me to break out in terms of a habit. I'm just got so in the habit of self- closing those tags that I don't even think about it when I type them now. So this is something I am still having to sort of break myself from, that we really don't need the self-closing tags. And again, if I want to be consistent with the syntax of HTML, I'll just go ahead and get rid of those. What it really boils down to is that we have more options than HTML5, in terms of how we write our code, not less.

Unfortunately, it also let's people write some really ugly code and get away with it. So my advice is to go ahead and come up with a consistent coding standard that not only conforms to HTML, but that's readable and maintainable not only by yourself, but other authors as well. I'll use my own standard throughout this course, and I have just pretty much described it to you--and if it works well for you, feel free to go ahead and adopt it. Now, for the most part, it's almost exactly like what I was doing when I was writing XHTML. I used all lowercase for the tags. I enclosed my attributes in quotation marks.

I don't self-close those tags any more, however. I also don't serve attributes that are no longer required, like the MIME types, and I don't include attribute values for those global attributes that have a single or a Boolean value. Now, it works for me. It helps me create consistent code and more importantly, it works in all conforming user agents, and it's also backwards compatible, which is a good thing. Now I recommend using the exact same criteria when determining your own syntax standards, and that's actually something that, if you're new to this, I would encourage you to do over the course of the title.

Show transcript

This video is part of

Image for HTML5: Structure, Syntax, and Semantics
HTML5: Structure, Syntax, and Semantics

46 video lessons · 36571 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 20s
    1. Welcome
      48s
    2. Using the exercise files
      1m 32s
  2. 18m 41s
    1. A brief overview of HTML5
      3m 57s
    2. What's in the HTML5 specification?
      8m 17s
    3. Why do we need new structural elements?
      6m 27s
  3. 50m 33s
    1. Defining HTML5 documents
      5m 5s
    2. HTML5 syntax
      9m 14s
    3. The header element
      5m 22s
    4. The nav element
      4m 55s
    5. The section element
      4m 51s
    6. The article element
      4m 48s
    7. The aside element
      4m 13s
    8. The footer element
      4m 17s
    9. Content model overview
      7m 48s
  4. 35m 28s
    1. Understanding the outline algorithm
      3m 17s
    2. Creating document sections
      8m 25s
    3. Using headings properly
      9m 1s
    4. Using hgroup to override sectioning
      4m 17s
    5. Properly nesting structure
      7m 17s
    6. Sectioning roots
      3m 11s
  5. 58m 30s
    1. Organizing content
      4m 41s
    2. Planning document structure
      5m 47s
    3. Choosing the right structural element
      4m 43s
    4. Checking document outlines
      5m 27s
    5. Coding initial page structure
      5m 28s
    6. Using class and ID attributes
      5m 31s
    7. Structuring headers
      13m 13s
    8. Building navigation
      7m 1s
    9. Structuring footers
      6m 39s
  6. 1h 27m
    1. Working with figure and figcaption
      7m 12s
    2. Grouping content with asides
      3m 46s
    3. Using divs in HTML5
      5m 0s
    4. Working with lists in HTML5
      7m 10s
    5. The return of bold and italic
      5m 52s
    6. Citing works semantically
      6m 32s
    7. Using the address element
      5m 24s
    8. Using the small element
      4m 24s
    9. Using the mark element
      5m 16s
    10. Working with date and time
      11m 55s
    11. Creating block-level links
      8m 53s
    12. Understanding link relationships
      9m 28s
    13. Defining link relationships
      6m 23s
  7. 17m 22s
    1. Current browser support
      7m 38s
    2. Ensuring block-level display
      4m 3s
    3. Adding support for elements in older browsers
      5m 41s
  8. 3m 46s
    1. Additional Resources
      3m 46s

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.

Join now "Already a member? Log in

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 HTML5: Structure, Syntax, and Semantics.

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.