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

Using divs in HTML5

From: HTML5: Structure, Syntax, and Semantics

Video: Using divs in HTML5

You may have noticed that there aren't a lot of divs on our page. In fact, you've probably picked up on the fact that we haven't used any. This is in stark contrast to HTML 4 and XHTML documents, where a div really was the primary way to group and organize content. The variety and richness of the sectioning and grouping content elements in HTML5 means that we don't really have to rely on the div tag to do the heavy lifting anymore. Of course this doesn't mean that we are just going to forget about the div and never use it anymore.

Using divs in HTML5

You may have noticed that there aren't a lot of divs on our page. In fact, you've probably picked up on the fact that we haven't used any. This is in stark contrast to HTML 4 and XHTML documents, where a div really was the primary way to group and organize content. The variety and richness of the sectioning and grouping content elements in HTML5 means that we don't really have to rely on the div tag to do the heavy lifting anymore. Of course this doesn't mean that we are just going to forget about the div and never use it anymore.

There are still some very legitimate reasons for using it. So we are going to take a quick look what the specification has to say about the div and then come back into our page and see where it's appropriate. So here I am back at the HTML5 author-view spec and I have navigated down to the div element. And there are a couple things that I want to point out here. Notice it's flow content, not sectioning content, and it can contain anything that's in flow content inside of it. So it's really, really generic, and you can use it with just about anything. Okay, I am going to scroll down a little bit for its definition. This is where it kinds of gets sad.

The div element has no special meaning at all. It represents its children. That's basically about it. It can be used with class, language, title attributes to markup semantics common to a group of consecutive elements. Okay! Now, it's the note that I really want to pay attention to. Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. And it does mention here, I can't say I was going to say that, but it mentions use of the div elements instead of more appropriate element. So using instead of say a section or an article element leads to poor accessibility for readers and poor maintainability for authors.

So you are encouraged to use other elements in place of the div tag. However, div elements are incredibly appropriate for grouping content for just stylistic purposes. They are incredibly appropriate for grouping content that you are going to need to affect through JavaScript a little bit later on that's not necessarily structural in nature. So it is definitely something that we can still use. We are just not going to use it as much. All right! So I am going go back over to our trails page, and we are going to take a look at what the div is going to allow us to do in our file. Okay! So I am back in our trails page, and this one can be found at 05_03 folder.

And you know it's easier for me to point this out in the browser rather than the structure so let me go ahead and get preview this. So I am going to go ahead and preview this in one of our browsers. I haven't used Chrome yet, so let's not pick on Chrome. Let's use it. If I scroll down to the footer, I can see the footer is--there is no other way to put it, the footer is kind of ugly at the moment, so everything is just sort of stacked on top of each other. What I would like to do, what I really like to do with the footer is I'd like to have the footer in a two-column view. I would like to have the phone number and the email address and the return to top link, all that stuff, over on the right-hand side, and I would really like to have the address on the left-hand side.

Now an easy way to do that is to use a div tag for each of those, segment them, structure them using a div tag and put them on either side. Now I could use a section element here. But again, the problem with a section element was it would now show up in the outline, and we don't want a footer in the outline. So let me go ahead and close our browser window, and we'll go back into our trails page, scroll all the way down to our footer, and we are going to start using our div tag. Okay, so essentially we are just going to group some content here with the div tag. So right inside the footer, I am going to open a div tag.

And I am going to go ahead and identify the div tags through the use of a class attribute. So I am going to give this one a class of right column, rightCol, so lowercase r, uppercase Col, rightCol if you will. And then remember this is just going to be going all the way down to say the email address. So there I am going to go down and close my div tag. So just above the all content copyright 2001 Explore California, I'll open up another div tag, and as you can probably guess this one, this one is going to get a class of leftCol.

And then at the very bottom of the footer, I'll go ahead and I'll close that div tag. So essentially, we've segmented, or sectioned if you will, or footer into two sections, a right column and a left column, and we've done that by above using the div tag. And it's going to give us a couple of advantages here. So I am going to save this, and I am going to preview this in a browser that I can check the outline in locally. So I am just going to preview this in Opera, and if I scroll down towards the bottom, I can see that we now have our two-column layout So we already have the CSS written that's basically a floating this column to the right and floating that column to the left, that sort of thing.

And if we go up and check our document outline, we can see that the footer is still not added to the outline. That's perfect! That's exactly what we want. So the divs are playing a very important role for us here. They are sectioning and structuring our content without actually creating a brand-new section in the outline, and they are allowing us to style this the way we want to without adding a ton of unnecessary markup. Now you may not use the div tag as much as you have in the past, but it does remain a really important tool for web authors. It's a great way of grouping content together without creating new sections in your document, and this can be extremely helpful for styling, like we are doing here, or just in adding an extra measure of organization to your content.

Show transcript

This video is part of

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

46 video lessons · 36454 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.