CSS Lists are used to style HTML ordered lists
(<ol>) and unordered lists
(<ul>). CSS allows you to customize list markers,
positions, spacing, colors, backgrounds, borders, and hover effects.
Styled lists are commonly used in navigation menus, sidebars, feature
lists, and website content.
Why Use CSS Lists?
By default, HTML lists have basic styling. CSS makes lists more
attractive and easier to read by controlling their appearance and layout.
Properly styled lists improve website design and user experience.
Basic List Syntax
What this code does: Turns a plain list into a blue-text list inside a bordered box by styling the ul element with a class.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the basic list syntax demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. This demo has one rule for the list container. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets a readable font and adds padding: 24px so the demo does not touch the edge of the preview window. It only affects this small preview page, not the tutorial.
.demo-list targets the ul with that class. color: blue is inherited by every li inside it, and the bullet markers use the same color as their text.
A ul is a block element, so a border draws one box around the whole list. border-radius: 6px rounds the corners of that box.
The four padding values are top, right, bottom and left. The left value is 40px on purpose: the bullets are drawn outside the text, to its left, so they need space inside the border. With less left padding they would touch or cross the border. width: 250px keeps the box narrow.
</style> closes the CSS. The browser now has all the rules it needs for the float demo.
</head> closes the head. The visible content comes next, inside <body>.
<body> starts the visible content: one list with three items.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
Each li is one list item and gets a bullet by default. They are indented in the code only for readability. The items inherit the blue color from the list.
</ul> closes the list.
</body> closes the body.
</html> is the final closing tag and ends the document.
Step 1: Change List Marker Type
The list-style-type property changes the appearance of list markers. Different marker styles are available for ordered and unordered lists.
What this code does: Replaces the default round bullets with square ones using list-style-type: square.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the list marker type demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. This demo changes the bullet style of one list. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets a readable font and adds padding: 24px so the demo does not touch the edge of the preview window. It only affects this small preview page, not the tutorial.
list-style-type sets the shape of the markers. For a ul the values are disc (the default round bullet), circle, square and none. For an ol you can use decimal, lower-alpha, upper-roman and more.
The blue color applies to the item text and to the square markers, because markers take the color of their list item.
A blue border with rounded corners puts the list in a box, so you can see how the markers sit inside it.
The 40px left padding leaves room for the markers, which are placed outside the text. The list is 250px wide.
</style> closes the CSS. The browser now has all the rules it needs for the float demo.
</head> closes the head. The visible content comes next, inside <body>.
<body> starts the visible content: a list of three fruits.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
Three items. Each one gets a square marker because of the rule on the parent ul. You only need to set the marker type once, on the list.
</ul> closes the list.
</body> closes the body.
</html> is the final closing tag and ends the document.
Step 2: Remove List Markers
Navigation menus often remove default list markers using list-style-type:none.
What this code does: Hides the bullets completely with list-style-type: none, leaving only the text inside a green box.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the removing list markers demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. This demo removes the markers from one list. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets a readable font and adds padding: 24px so the demo does not touch the edge of the preview window. It only affects this small preview page, not the tutorial.
list-style-type: none removes the bullets. The items are still list items in the HTML, so screen readers still announce them as a list, but no marker is drawn.
A green border with rounded corners puts the list in a box.
Without markers there is no need for the extra 40px on the left, so padding: 15px is the same on all four sides. The list is 250px wide.
</style> closes the CSS. The browser now has all the rules it needs for the float demo.
</head> closes the head. The visible content comes next, inside <body>.
<body> starts the visible content: a menu-like list.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
Three menu items shown as plain text, without bullets. This is the usual starting point for a navigation menu.
</ul> closes the list.
</body> closes the body.
</html> is the final closing tag and ends the document.
Step 3: Change Marker Position
The list-style-position property controls whether list markers appear inside or outside the content area.
What this code does: Moves the bullets inside the text area with list-style-position: inside, so they sit within the blue border.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the marker position demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. This demo places the markers inside the item text. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets a readable font and adds padding: 24px so the demo does not touch the edge of the preview window. It only affects this small preview page, not the tutorial.
list-style-position has two values. outside (the default) draws the bullet in the margin, to the left of the text. inside draws it as part of the text, so a wrapped second line goes below the bullet instead of below the text.
A blue border with rounded corners. The bullets are inside this box.
Because the markers are inside, the list does not need the large left padding used in the earlier steps, so padding: 15px is enough. With outside markers and this padding, the bullets would be drawn on top of the border.
</style> closes the CSS. The browser now has all the rules it needs for the float demo.
</head> closes the head. The visible content comes next, inside <body>.
<body> starts the visible content: a list of three tutorials.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
The bullets appear right before the text. Switch the value to outside in the editor and compare the position.
</ul> closes the list.
</body> closes the body.
</html> is the final closing tag and ends the document.
Step 4: Style List Items
CSS can be used to add backgrounds, spacing, borders, and colors to individual list items.
What this code does: Removes the bullets and turns each list item into a blue block with white text, padding and spacing between items.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the styled list items demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. This demo has one rule for the list and one for its items. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets a readable font and adds padding: 24px so the demo does not touch the edge of the preview window. It only affects this small preview page, not the tutorial.
list-style is a shorthand for type, position and image. list-style: none removes the marker, so each item can look like a button or card.
Browsers give a ul about 40px of left padding by default. padding: 0 removes it, so the blue items start at the left edge. width: 280px sets the width of the list, and the items fill it.
This rule targets each li with the demo-item class. A blue background with white text turns each item into a colored block.
padding: 12px adds space inside each block. margin: 5px 0 means 5px above and below, and 0 on the sides. The vertical margins of neighboring items merge, so the gap between two blocks is 5px, not 10px.
Rounds each block slightly, so the items look like buttons.
</style> closes the CSS. The browser now has all the rules it needs for the float demo.
</head> closes the head. The visible content comes next, inside <body>.
<body> starts the visible content: a list of three menu items.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
Each li has the demo-item class, so every item gets the blue block style. One rule styles all of them.
</ul> closes the list.
</body> closes the body.
</html> is the final closing tag and ends the document.
Step 5: Create a Horizontal Navigation List
Lists are commonly used for navigation menus. Using Flexbox allows list items to appear horizontally.
What this code does: Uses display: flex with a gap to lay the list items out in a single row, like a simple navigation menu.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the horizontal navigation list demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. This demo turns a list into a horizontal menu. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets a readable font and adds padding: 24px so the demo does not touch the edge of the preview window. It only affects this small preview page, not the tutorial.
list-style: none removes the bullets, which a menu does not need.
display: flex makes the ul a flex container, so its li children are placed in a row instead of stacking. gap: 15px puts 15px between the items. padding: 0 removes the default left indent, so the menu starts at the left edge.
Each menu item gets a blue background with white text.
padding: 10px 20px means 10px above and below and 20px left and right, which makes each item look like a button. border-radius: 4px rounds the corners.
</style> closes the CSS. The browser now has all the rules it needs for the float demo.
</head> closes the head. The visible content comes next, inside <body>.
<body> starts the visible content: a list with three menu items.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
Three items in HTML order, left to right. Each uses demo-item for its color and padding.
</ul> closes the list.
</body> closes the body.
</html> is the final closing tag and ends the document.
Complete CSS List Example
What this code does: Builds a card-style list with a blue left border and soft shadow, where each item turns blue with white text on hover.
<!DOCTYPE html> tells the browser to use modern HTML5 rules. Without it the browser can switch to quirks mode, where box sizes and floats may not behave the way this lesson shows.
<html> wraps the whole page. Everything for the card-style list demo sits between this tag and the closing </html>.
<head> holds information about the page rather than visible content: the character encoding and the CSS rules that control the floated elements.
<meta charset="utf-8"> makes the browser read the file as UTF-8, so letters and symbols display correctly.
<style> opens the internal CSS. Every class starts with demo-, so these rules can never change the tutorial page around the preview.
The body rule sets the font and 24px of padding. background: #f5f9ff gives the preview a light blue color, so the white cards stand out.
list-style: none removes the bullets, so each item can look like a card.
The list is 300px wide, and padding: 0 removes the default left indent, so the cards start at the left edge.
Each item has a white background. border-left: 5px solid #007BFF adds a thick blue stripe on the left side only, which is a common card accent.
padding: 15px adds space inside each card, and margin-bottom: 10px leaves a gap below it.
A very soft shadow (2px down, 5px blur, 10% black) lifts each card off the background. transition: .3s makes the hover color change smooth.
:hover applies while the mouse is over an item. The background becomes blue and the text white, so the blue stripe merges with the background.
</style> closes the CSS.
</head> closes the head. The visible content comes next.
<body> starts the visible content: a heading and a list of four items.
A heading that tells what the list contains.
<ul> is an unordered list, and the demo-list class connects it to the CSS rule above. The list items must be direct children of the ul.
Four items, each with demo-item. The hover effect works on every card.
</ul> closes the list.
</body> closes the body.
</html> ends the document.
Advantages of CSS Lists
Advantage
Benefit
Description
Better Organization
Easy Reading
Content is displayed in a structured format.
Custom Design
Professional Appearance
Lists can match the website design.
Navigation Menus
User Friendly
Lists are commonly used for website menus.
Flexible Styling
Creative Layouts
CSS provides complete control over list appearance.
Best Practices
Use meaningful list structures for content organization.
Remove default markers only when necessary.
Use Flexbox for horizontal navigation menus.
Keep list spacing consistent throughout the website.
Use hover effects for interactive navigation lists.
Maintain good contrast between text and backgrounds.