# Lists as Containers: Strip the Defaults, Style the Items

Many lists shouldn't look like lists at all, so you strip one list's bullets, indent and margins with three declarations on its class, then style each li as a box, such as a card or a menu row with a link that fills it.

Apprentice · CSS · Updated November 14, 2026

## After this lesson you can

- Remove a list's markers, indent and margins on that one list by its class, without a rule that reaches every list
- Turn each list item into a box with padding, a border, a background and spacing, and make a link fill its item

## Key takeaways

- To make a list stop looking like a list, give that list a class and write list-style: none, padding: 0 and margin: 0 on it.
- Strip one list at a time, by its class. A rule on every ul and ol also takes the numbers off recipe steps and the bullets off lists that need them.
- Once the markers are gone, each li is a box like any other. Give it padding, a border, a background and rounded corners.
- Space the items with a margin, or draw a line only between them with li + li or li:not(:last-child).
- A link with display: block fills its whole item, so the whole row can be clicked. Keep the ul, so screen readers still hear a list.

Here's the most common thing CSS does to a list: it makes the list stop looking like one. The menu at the top of a site, the stack of cards in a feed, the settings screen with a row for each option, the comments under a post: on most sites, each of them is a `<ul>` with its bullets, indent and margins taken away and each `<li>` styled as a box. Once you know the pattern, you'll write it in nearly every project, and you'll spot it whenever you inspect someone else's page.

Paws & Whiskers' designer has drawn the new adoption page: each pet is a white card with rounded corners, stacked down the page, and a side menu lists the kinds of pets (Dogs, Cats, Rabbits, Small pets) as bars a finger can't miss. There isn't a bullet anywhere. Both are lists in the HTML, and they stay lists.

## Taking the list look away, one try at a time

Here's the pet list, three pets for now, each with a name and a line about them:

```html
<ul class="pet-list">
  <li class="pet">
    <h2>Biscuit</h2>
    <p>A 3-year-old beagle who loves long walks.</p>
  </li>
  <li class="pet">
    <h2>Mango</h2>
    <p>A 10-week-old kitten, already the boss of the house.</p>
  </li>
  <li class="pet">
    <h2>Clover</h2>
    <p>A calm 2-year-old rabbit who loves carrots.</p>
  </li>
</ul>
```

The first try takes away the bullets, with the `none` value from *Styling a List That Stays a List*:

```css
.pet-list {
  list-style: none;
}
```

The bullets are gone, but the pets still sit 40 pixels to the right of the page's heading, as if something invisible were pushing them. It is: the indent is the list's padding (`padding-inline-start: 40px`, from *Lists Hold Collections: ul, ol and What the Browser Adds*), and it stays when the markers go. Taking it away is the second try, and it lines the pets up with the heading. One gap is left: the list's margin, a line's height above and below it. Taking that away too gives the three lines you'll write again and again:

```css
.pet-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
```

Read it as "no markers, no indent, no space around the list". `padding: 0` takes the padding off all four sides; a list only has padding on its start side, so that's the indent. If you'd rather name exactly the one the browser set, `padding-inline-start: 0` does the same job.

![The shelter's pet list in three steps: with list-style none, the bullets are gone but the pets still sit 40 pixels to the right of the heading; with padding 0 as well, they line up with the heading; with margin 0 as well, the space above and below the list is gone too](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/b377583fe1a24cc7adec703769c881d3.webp)

## On this list only, never on every list

Once you've written those three lines a few times, it's tempting to put them at the top of the stylesheet, for every list on the site at once:

```css
/* Don't do this */
ul, ol {
  list-style: none;
  padding: 0;
  margin: 0;
}
```

Then the shelter adds its *Bringing Your Pet Home* page, and the treat recipe's steps have lost their numbers, the packing checklist's checkmarks hang off the edge of the page with no indent left to sit in, and every list written to be read as a list looks like loose lines of text. *Browser Defaults and a Small Reset* warned about this kind of "reset everything" rule: it takes away defaults that help. So strip the defaults **on the list you're styling, by its class**, and leave every other list as the browser made it.

## Each item becomes a box

With the markers, the indent and the margins gone, each `<li>` is an ordinary block box (*The Box Model: Content, Padding, Border and Margin*), and everything Module 1 taught about boxes applies. A **card** is a box that holds one thing's details, often one of a row or a column of matching boxes:

```css
.pet {
  padding: 16px;
  border: 2px solid #a8dadc;
  border-radius: 12px;
  background-color: #ffffff;
}

.pet + .pet {
  margin-top: 16px;
}
```

Each pet is now a white card with a light blue border and rounded corners. The second rule puts 16 pixels between the cards: `.pet + .pet` picks every card that comes right after another card, so there's no extra space above the first one or below the last. (`margin-bottom: 16px;` on every `.pet` works too, and leaves 16 pixels under the last card.)

## Lines between the items, not around them

The side menu is a stack of rows with a thin line between each pair, like the lines between rows in a phone's settings screen, and no line above the first row or below the last. Two selectors from Module 2 draw a line only *between* items:

```css
.side-menu li + li {
  border-top: 1px solid #a8dadc;
}
```

```css
.side-menu li:not(:last-child) {
  border-bottom: 1px solid #a8dadc;
}
```

The first gives every item after the first a line on top. The second, read "not last child" (*Pseudo-Classes: :hover, :focus-visible, :nth-child() and More*), gives every item except the last a line underneath. They draw the same lines; choose the one you find easier to read.

## A link that fills its item

Here's the side menu's HTML, with its list stripped like the pet list:

```html
<nav>
  <ul class="side-menu">
    <li><a href="#dogs">Dogs</a></li>
    <li><a href="#cats">Cats</a></li>
    <li><a href="#rabbits">Rabbits</a></li>
    <li><a href="#small-pets">Small pets</a></li>
  </ul>
</nav>
```

Each row looks like a bar, but only the word in it is a link. Click beside the word and nothing happens, and on a phone a short word is a small target for a thumb. The link is an inline box, as wide as its text (*Normal Flow and the display Property*). Make it a block, and it stretches across the whole row; put the padding on the link, not on the `<li>`, so the padding is part of what can be clicked:

```css
.side-menu a {
  display: block;
  padding: 12px 16px;
  color: #1d3557;
  text-decoration: none;
}

.side-menu a:hover {
  background-color: #f1faee;
}
```

Now the whole bar is the link, and it lights up under the mouse. Padding on the `<li>` instead would draw the same bar, with a frame around the link that does nothing when it's clicked.

![The shelter's new adoption page: on the left, the side menu as four full-width bars, Dogs, Cats, Rabbits and Small pets, with thin lines between them and the Cats bar highlighted under the mouse; on the right, the pets as white cards with rounded corners and a light blue border, stacked with a gap between them, and no bullets anywhere](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/207dd64998064c898291a724cdcb82c4.webp)

## Keep the list

Once a list doesn't look like a list, why not swap the `<ul>` for `<div>` elements? Because the bullets were only the look. The list is the meaning: a screen reader still says "list, 4 items" for the side menu and lets its user skip the whole list of pets. The CSS changes how it looks; the HTML keeps saying what it is. This is what **semantic HTML** means: choosing elements for what the content is, not for how it should look.

One browser has a quirk here. Safari's screen reader, VoiceOver, may stop announcing a list as a list once `list-style: none` has taken its markers away. You can put the meaning back with an attribute on the list:

```html
<ul class="pet-list" role="list">
  <li class="pet">
    <h2>Biscuit</h2>
    <p>A 3-year-old beagle who loves long walks.</p>
  </li>
</ul>
```

The **`role`** attribute tells screen readers and other assistive tools what an element is. `role="list"` says "this is a list", which the `<ul>` already said, so it changes nothing for anyone else; it only restores what Safari dropped. It's worth adding to the lists you strip.

**Try it.** In your `adoption-list` folder, make `cards.html` with a page skeleton, a `<style>` element, the side menu and the pet list above. Add the rules one at a time and save after each: the strip on `.pet-list`, then `.pet`, then `.pet + .pet`, then the strip on `.side-menu` and the menu rules. Then change `.pet + .pet` to `.pet:not(:last-child)` with `margin-bottom: 16px;`: does anything change on screen?

## Do it: turn the visit times into bars

Paws & Whiskers' *Visit us* page lists Saturday's visiting times, and the designer wants them as a stack of wide bars, like a phone's settings screen. The page also lists the adoption steps, which must keep their numbers.

- The **visit times** lose their list look: no bullets, no indent, no space around the list.
- A thin line, `1px solid #a8dadc`, **between** the times, with none above the first time.
- Each time's **link fills its whole bar**, so a thumb can't miss it.
- The adoption steps keep their numbers.

Practiced live on the lesson page: write the CSS right there and check it.

## Check yourself

2 questions to try on the lesson page.

## So what

A menu, a stack of cards and a settings screen are lists with the list look taken away: three lines on that one list's class, then each item styled as a box. The next lesson puts the items side by side.

## Key terms

- [List style](https://www.ask-codey.com/glossary/list-style)
- [Card](https://www.ask-codey.com/glossary/card)
- [Semantic HTML](https://www.ask-codey.com/glossary/semantic-html)
- [ARIA role](https://www.ask-codey.com/glossary/aria-role)

## Cheat sheets

- [Lists as Containers: Strip the Defaults, Style the Items](https://www.ask-codey.com/cheat-sheets/css-lists-as-containers-cheat-sheet)

## Related

- [Lists Hold Collections: ul, ol and What the Browser Adds](https://www.ask-codey.com/lessons/css-lists-hold-collections)
- [Styling a List That Stays a List](https://www.ask-codey.com/lessons/css-styling-lists)
- [Browser Defaults and a Small Reset](https://www.ask-codey.com/lessons/css-browser-defaults-and-resets)
- [Lists Side by Side, by Hand](https://www.ask-codey.com/lessons/css-lists-side-by-side)

Source: https://www.ask-codey.com/lessons/css-lists-as-containers
