CSS Lists are used to display a group of related items in a specific order. Lists can be either ordered (with numbers) or unordered (with bullets). CSS provides a lot of options to style lists, making them visually appealing and easy to use. In this tutorial, we will explore both unordered and ordered lists and how to style them using CSS.
/* Basic Unordered List */ ul { list-style-type: square; /* Adds square bullets */ padding-left: 20px; /* Indents the list */ } /* Ordered List */ ol { list-style-type: decimal; /* Adds numbered list */ padding-left: 20px; /* Indents the list */ } /* Customizing List Item */ li { font-size: 18px; margin-bottom: 10px; color: #333; }
list-style-type:
Defines the type of list marker. Common types: disc
(default), circle
, square
, decimal
, etc.list-style-image:
Adds a custom image as a bullet point. This is a great way to add a personal touch to your lists.padding-left:
Specifies the left padding for the list, creating an indent to separate the list from other content.font-size:
Controls the text size of the list items.color:
Sets the color of the list item text.margin-bottom:
Adds space between each list item, improving readability.Use @media queries
to adjust the list styling based on different screen sizes. For example, on smaller devices like smartphones, you might want to reduce the font size or change the bullet style to improve visibility.
You can also combine CSS properties to create dynamic, interactive lists. For example, adding animations when a list item is clicked or hovered. Hereβs how you could add a subtle animation effect:
/* Example of animated list item */ li:hover { transform: scale(1.1); /* Scales the list item */ transition: transform 0.3s ease-in-out; /* Smooth transition */ }
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!