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

Creating lists

From: Up and Running with HTML

Video: Creating lists

Lists are incredibly useful ways for organizing content. HTML gives us three different types of lists to use based on how our content needs to be organized. Let's take a look at all three of those by opening up the lists.htm found on the 03_05 directory. Just underneath the h3 element that we have here are Ordered and unordered lists. We have some items that appear to be destined for a list. The first two types that we are going to tackle are ordered and unordered.

Creating lists

Lists are incredibly useful ways for organizing content. HTML gives us three different types of lists to use based on how our content needs to be organized. Let's take a look at all three of those by opening up the lists.htm found on the 03_05 directory. Just underneath the h3 element that we have here are Ordered and unordered lists. We have some items that appear to be destined for a list. The first two types that we are going to tackle are ordered and unordered.

Now, you may have referred to them before as numbered or bulleted lists. They are really the same thing. So here we have item one, two, three, four. This is exactly what we need. The list syntax for ordered and unordered lists are exactly the same, and that's why we are sort of tackling them together. The first thing I am going to do is I am just going to create a little bit of blank space here. This isn't necessary for formatting a list; it's just necessary to make it little bit more readable for all of us. So above all these item properties I am going to go ahead and create a ul tag.

ul stands for unordered list, and that is the parent-level tag that's going to wrap the entire list. And I am going to do the same thing at the bottom of all those list items, unordered list. That's step one. Step two would be to identify the items within the list themselves. A browser can't just sort of guess how many items you have in a list. Right now it thinks you only have one, which is all this text that's we are looking at here. So we need to identify the fact that each of these guys are individual items within the list, and we do that by using the list item, or li tag.

So I am going to go ahead and wrap item one in a list item tag. Now, go ahead and do that for the rest of the items, and just go ahead and remember to do the opening and the closing tags for these list items. Now, one of the interesting things about the li tag, everybody when they first start doing lists they do them like this, which is here is my list item and here is some text inside of it. And sometimes that will pass along the mistaken impression that the only thing that you can have an inside of a list is text.

You can place almost anything you want to inside of a list item. As a matter of fact, if you look inside the HTML specification, what it's going to say-- at least in the HTML5 Specification--it's going to say that any items that's considered part of flow content can go inside a list item. Now what's flow content? Just about anything: paragraphs, headings, images, other lists. So really, inside of a list item you can put anything you want, and that means that our list can become, if we want them to be, incredibly complex structures that represent organized data in a really, really complex way.

So if I save this and preview this in one of my browsers, I can see, there is our list. And because we used an unordered list, you can see that we have bullets showing up in the place of numbers. It's quite common to need to nest lists from time to time, and it's easy enough to do in a word processing program. You just sort of highlight the ones that you want nested and you click the right indent button, and there you go. It doesn't quite work that way when you are coding it by hand. You have to pay attention to the syntax, and essentially what happens is, you are going to be nesting one list inside of another one. But you are not actually nesting the list inside of another list; you are nesting it within a list item.

So for example these items 3.1, 3.2, and 3.3 obviously are referencing item 3. These guys are going to be wrapped inside of another list, which is inside this list item. Now, that may seem a little confusing, so let me kind of show you how this works. What I am going to do, just for readability's sake, is I am going to take this list item and I am going to hit Return on this. I am going to cut this, just to make this a little bit easier for us to see what's going on here, and then I am going to create a new line underneath those submenu items and paste that closing list item text.

So now you can see what's going on here. These three list items are now part of this list item. That doesn't mean anything right now, because I need to wrap them and let the browser or the user agent know that, hey, there is an unordered list inside this. To do that I am just going to use another unordered list tag. And I have got to remember to open and close that tag properly. So let me indent this a little bit so you can get a better feel for what's happening here. So you will notice that here is the opening list item.

Here is the closing list item. Inside that we have not only the text that identifies that, but we have an unordered list inside of that, and that is how you nest the list. A lot of people get confused about that syntax and they will try to close the list item and have another unordered list happen right after it. It does not work, because what happens to the browser is the browser sees an unordered list, it goes down and sees all of the list items, and then it sees another unordered list, and it assumes that the first one has ended. So what you end up with is not a nested list, but two lists stacked right on top of each other.

So just make sure that any nested lists are inside the list item that they apply to. So if I save this and go into the browser and preview that again, you can see that now those items are indeed going to nest. What's the difference between an unordered list and an ordered list? In terms of your code, not a lot. If I go up to the parent-level unordered list tag and I change that from a ul to an ol-- and remember to change the proper closing tag as well-- if I save this and then refresh it, you can see that now instead of those bullets we have a nice ordered list with items one, two, three, and four.

There is not that much difference in terms of code. I mean, you are just using one letter instead of another one. But what is actually changing on behind the scenes? Well, now we have information that's not only organized in a list, but it's organized in a list in a very specific fashion. Now, one of the best ways that I can describe to you when to use an ordered list versus when to use an unordered list is think about this: If you had a list and you jumbled up all the items in the list, would it still make sense? If the answer is yes then you have an unordered list on your hands. If the answer is no--for example, maybe you are giving somebody step-by-step instructions on how to get your house-- that's going to be an ordered list.

There is always a judgment call made as to whether you want something in an ordered list or an unordered list, but really, that is the logical reason behind using those. Now if you are saying to yourself, well, yeah, but I don't want numbers to show up. I want something else. Well, that's fine. CSS can do that for you. It can cause those numbers to go away, and you can even replace them with your own specific icons if you wanted something other than that out there. So don't let that be the deciding factor, in terms of how you want the list to display. Rather, think about how the list should be structured logically.

Now, there is one more thing that we can do to our ordered list. All these lists have certain attributes. Most of the attributes of lists have been deprecated, meaning they're no longer a viable part of the HTML specification, but there's one for the ordered list that's been brought back in HTML5 and that is the start attribute. So if I go up to my opening ordered list and I type in the word start and then equals and then I can just type in whatever number I want--let's say 6 for example in quotation marks-- now what that's going to do for me is it's going to cause this particular list to now start at 6.

So there is no mechanism in HTML that says pick up and continue numbering from the list above me or the list on the previous page, but you do have the ability to go in and manually set a start for that particular list by using that attribute. So there's one more list that I want to tackle really quickly, and that is what's known as a definition list. And you're probably going to see ordered lists and unordered lists more than you will definition lists, but these are incredibly useful lists to use, so let's take a look at the syntax of those. Going back into our code, just below the h3 we have Term one and then we have Term one definition, and we have Term two, Term two definition, and of course it carries on for Term number three.

Definition lists are just that. They are term then followed by definition. Think about a glossary or frequently asked questions or something like that where you have an item and then some information about that item, an individual and then maybe the person's bio. So there is all sorts of different reasons for using definition lists and they have this sort of really neat structure to them. Just after the h3 I am going to start a definition list by typing dl. So it's pretty self- explanatory in terms of what this is: ul unordered list, ol ordered list, dl definition list. But there is some differences in the definition list in terms of syntax.

Instead of identifying every time inside of it as being a list item, in a definition list we have to identify as being either a term or a definition. So, what I am going to do is I am going to go up to the term one and I am going to wrap that in the dt tags, which stands for definition term. Underneath that, I am going to wrap that in a dd tag, which stands for definition, definition. I am just going to follow suit for each of these. And if you're wondering, do I always have to follow this particular order? oddly enough, you don't.

You have some leeway. I've seen plenty of people do lists where they have multiple terms without a definition and then they'll add some more definitions. And yes, you can nest additional list and things inside of it, and inside these terms and definitions you can have whatever content you want inside of them the same way you can do with list items. So there is our initial structure here. We have a definition list and then we have terms followed by definitions. This is sort of the basic, if you will, structure for a definition list. If I save this, again go out to my browser and refresh that, you can see that most browsers are going to render definition lists in this manner.

They are going to have the term left-aligned and then the definition they are going to sort of indent down that little bit. Of course, using CSS you can style that any way that you want. You can italicize things, bold things, put them on the same like. You can really format that any way that you want. That's just the browser default formatting for it. Be sure to take some time to practice this syntax for these lists so that you understand exactly how they are structured and how nesting the list inside of each other, how that works. You are going to use lists far more often than you might think at first glace. They are great for organizing menus, form elements, product information, any content that needs to be grouped together in a related manner.

Their flexibility and utility make them among the most commonly used HTML elements, so once you are used to their syntax, you are going to find yourself using them all the time.

Show transcript

This video is part of

Image for Up and Running with HTML
Up and Running with HTML

49 video lessons · 26192 viewers

James Williamson

Expand all | Collapse all
  1. 2m 12s
    1. Welcome
    2. Using the exercise files
      1m 17s
  2. 29m 30s
    1. Learning HTML
      2m 47s
    2. Choosing a code editor
      5m 2s
    3. Exploring basic HTML syntax
      8m 18s
    4. Do I need to learn HTML5?
      5m 6s
    5. Exploring HTML references
      8m 17s
  3. 35m 40s
    1. Exploring an HTML document
      5m 19s
    2. Working with doctype declarations
      4m 3s
    3. Examining the document head
      8m 20s
    4. Looking at the document body
      3m 21s
    5. Adding document structure
      8m 52s
    6. Lab: Coding a basic page
      3m 9s
    7. Solution: Coding a basic page
      2m 36s
  4. 1h 23m
    1. How does HTML format text?
      5m 51s
    2. Adding headings
      7m 24s
    3. Formatting paragraphs
      4m 54s
    4. Controlling line breaks
      3m 50s
    5. Creating lists
      10m 37s
    6. Emphasizing text
      6m 42s
    7. Displaying special characters
      5m 8s
    8. Controlling whitespace
      4m 35s
    9. Inserting images
      9m 20s
    10. Lab: Controlling page content
      13m 57s
    11. Solution: Controlling page content
      10m 55s
  5. 31m 54s
    1. Linking to pages within your site
      6m 45s
    2. Linking to external pages
      3m 2s
    3. Linking to downloadable resources
      2m 25s
    4. Linking to page regions
      8m 0s
    5. Lab: Creating Links
      5m 57s
    6. Solution: Creating Links
      5m 45s
  6. 40m 27s
    1. Examining basic table structure
      5m 10s
    2. Adding content to tables
      6m 20s
    3. Setting table attributes
      7m 42s
    4. Adding table captions
      4m 3s
    5. Defining table headers
      2m 13s
    6. Making table data accessible
      5m 46s
    7. Lab: Building tables
      4m 13s
    8. Solution: Building tables
      5m 0s
  7. 43m 23s
    1. Understanding the relationship between HTML and CSS
      4m 58s
    2. Creating inline styles
      4m 53s
    3. Exploring the style element
      5m 13s
    4. Basic font styling
      9m 24s
    5. Changing color
      4m 55s
    6. Taking styles further
      5m 24s
    7. Lab: Controlling basic styles
      5m 10s
    8. Solution: Controlling basic styles
      3m 26s
  8. 5m 44s
    1. Next steps
      2m 56s
    2. Additional resources
      2m 48s

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


You have completed Up and Running with HTML.

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

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?


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.