Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The list elements are really very flexible. Let's take a look at some details on how these work. We're going to make a working copy of lists.html. I am going to rename this as lists-working. I am going to open this in my text editor here, and I am going to go ahead and open it also in the browser. So here we have a simple document, with the three different types of HTML lists in it. The first thing I want to show you is that it is possible to nest these lists.
So if I take this whole ordered list and I just make a copy of it, and I'll make another copy of it, right there in the middle of the existing list-- of course I'm just indenting them so that it's clear; that doesn't affect how they are rendered-- and if I go ahead and reload this, you see we now have three different lists and they are nested within each other. And you notice that they each start over at 1. So if I wanted to, I could come over here and I could put start="5" on this second ol, and when I reload over here, you'll see it's 5, 6, and 7.
The inner one is still starting at 1, 2, and 3. If I wanted to, there I could say type="i" and start="7" and save that and reload, and you see now we have 7, 8, 9 in roman numerals for that inner one. So there is really a lot of flexibility in how this works with the nested lists. And if I nest the unordered lists, see, we get this other behavior here, and I reload this, you'll see that we have the discs and the circles and the squares for the different levels of nested unordered lists.
So I am going to go ahead and remove that nesting, and I'm going to include now our CSS reset so you can see another interesting aspect of these. So I am just going to expand this so you can see the whole line there. I have included our CSS style sheet that does resets, and when I reload this, you see that these are still formatted very much like they were before. And that's because if we look at our CSS reset file here, you notice I really don't do much to the lists.
The only thing in here is for the ordered list, unordered list, and the li elements. I've got margin, padding, border, font-size--those things reset. I am not doing anything actually specifically about the lists; instead, I am going to come in here and I am going to add a little reset here. Let's say style. And normally when I use my resets in a website, I'll have something like this in here. I am going to say dl, dt, dd, ol, ul, li, and so that's all of the list-related elements.
I am going to come in here, and I am going to set the margin and the padding, and the border, all to 0. When I save this and I reload in the browser, now, that's interesting. Of course we expected them all to have no margin, no border, and no padding. What might have been unexpected is that all of the bullets and those kinds of things have disappeared. Otherwise, it's a great place to start, because it normalizes the display across the platform, so that's what a reset is for. But with the bullets and the numbering disappeared, that's not right.
What's actually happened is they're still there; they're just outside of the margin. I am going to show you why here. I am going to go ahead and I am going to put a div around all of these list elements, and I am just going to call it outer. And I am going to come up here into our style sheet. I am going to say outer, and so that's the id selector, say margin-left: 50px, and I am going to give it a border. Put this on a separate line; do this right. And now when I reload over here, we'll have them inside this div, and it has this indent, and you'll notice that outside of the margin we've got our numbers and our bullets.
Now, that may seem weird, but that is the default on all the browsers that I know of. Of course there is no guarantee that that's the default on all of them, so we can't specify it. So we can come out here and we're going to say for ol and ul elements, list-style-position: inside. Now, there's two possible values here-- outside and inside--and outside is the default. And when I change it to inside, now all of those numbers and bullets are inside of the margin.
And when I scroll back down here--I am just going to take out this div. We don't need it anymore. And I can take out the styling for the div. Save this and reload. Now this might be more of what we expect; we have the numbers and we have the bullets displayed, even with our margins set to 0. Now, you don't have to do this. You can set that list-style position to outside, and if I just change this to outside and reload, you'll see there is our default. But if you want to have those within the margins of whatever containers you're putting this in, you might want to set it to inside.
So, just for display purposes and to make this line up with things, we're going to go ahead and put a margin-left. I am going to say 1ex, which is the default that I have for these other elements here. And so it lines up nicely with our header. And now let's take a look at some of the possibilities here. So I am going to go ahead and I am going to put some class names in here. I am going to say class for the ordered list-- I am just going to call it ordered-- and a class for the unordered list as unordered. And come back up here into our style sheet and I am going to say for the ordered list, say list-style-type, I am going to say lower-alpha.
Let's make this a little bit wider here so it all fits. And we can actually move this over a little bit. And this is just for our purposes of being able to experiment here. So I save that and reload it, and now we have lowercase alpha and I can say upper-alpha. Then I'll have uppercase alpha. I can say lower-roman and we have the lowercase roman numerals. I can say upper-roman, and we have the uppercase roman numerals. Now let's look at some of these other options. I can say katakana. We get Japanese.
There is really a lot of them available. There's also katakana- iroha. Save this and reload. Different type of katakana. There's hiragana and also hiragana-iroha. There's Armenian. Reload that. You can do decimal with a leading 0, like that (decimal-leading-zero). There's georgian. There's really a lot of them. Or if we like, we can even use an image. We can say list-style-image. I am going to do this for the unordered list.
These same things work for both the ordered and the unordered list, but images are more common for the unordered list because they'll replace the bullets. So that's url(images/scissors-small.png. And that's an image that we have in our exercise files, and you see it's a small thumbnail size of my little scissors picture. So we again have 1, 2, 3 for the ordered list and our unordered list now has these images.
That's a great feature if you want to create your own types of bullets. So you can see that there are many, many options available. Of course you can and likely will apply other CSS properties to your list elements. Formatting your list with CSS is a very powerful way of presenting lists in your documents.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101658 Viewers
61 Video lessons · 88415 Viewers
71 Video lessons · 72249 Viewers
56 Video lessons · 103984 Viewers
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.
Your file was successfully uploaded.