×

CSS Lists

CSS Lists: Several properties are available in CSS that are used to manage the lists. Lists are distributed as ordered and unordered kind of lists. The ordered lists provide the facility to mark the items of the list along with numbers and alphabet. An unordered list offers the facility to mark the items of lists using bullets.

With the help of CSS, we can style various lists. These lists give us the facility to:

  • Arrange the distance among the marker and the text inside the list.
  • Describe the image for any marker instead the use of any bullet point or any number.
  • Manage the appearance or pattern of any marker.
  • Position a marker inside or outside of a box that includes the items of a list.
  • Set the color of the background for lists and list items.

There are several properties of CSS which may be applied for styling the lists of CSS:

  • list-style-type: It is used to control the appearance or shape of a marker.
  • list-style-image: It is used to set the image to the marker instead of using any number or any bullet point.
  • list-style-position: This property describes the marker’s position, as its name implies.
  • list-style: This property is used as a shorthand property for all the properties mentioned above.
  • marker-offset: It describes the distance among the marker and the text. This property does not provide any support to Netscape 7 or IE6.

Take a look at the following illustration of list properties one by one:

CSS list-style-type

It permits us to modify the marker’s list type to some other type like Latin letters, roman numerals, circle, square, etc. The items of an ordered list are numbered in Arabic numerals (i.e., 1, 2, 3, etc.), although an unordered list’s items are remarked with the round bullet point.

When none value is set, it will erase all the bullets or markers.

Note: These lists also contain the default padding and margin. To erase, we have to add margin: 0 and padding: 0 to <ul> and <ol>.

Let’s have a look on the following example:

Example:                             

list-style-type

<!DOCTYPE html>
<html>
<head>
<title> CSS Lists </title>
<style>
.num
{
 list-style-type: decimal;
}
.alpha
{
 list-style-type: lower-alpha;
}
.roman
{
 list-style-type: lower-roman;
}
.circle
{
 list-style-type: circle;
}
.square
{
 list-style-type: square;
}
.disc
{
 list-style-type: disc;
}
</style>
</head>
<body>
<h1> Welcome to this Page </h1>
<h2> Ordered Lists </h2>
<ol class= "num">
<li> one </li>
<li> two </li>
<li> three </li>
</ol>
<ol class= "alpha">
<li> one </li>
<li> two </li>
<li> three </li>
</ol>
<ol class= "roman">
<li> one </li>
<li> two </li>
<li> three </li>
</ol>
<h2> Unordered Lists </h2>
<ul class= "disc">
<li> one </li>
<li> two </li>
<li> three </li>
</ul>
<ul class= "circle">
<li> one </li>
<li> two </li>
<li> three </li>
</ul>
<ul class= "square">
<li> one </li>
<li> two </li>
<li> three </li>
</ul>
</body>
</html>

Output:

CSS Lists

CSS list-style-position

It is used to specify the appearance of a marker, whether it is outside or inside of a box. It also includes bullet points. This property contains two values.

inside: It specifies that bullet points are inside a list item. If any content goes to the next line, then content will wrap under a marker.

outside: It specifies that bullet points are outside a list item. These values used as the default value.

Let’s have a look on the following illustration:

Example:

<!DOCTYPE html>
<html>
<head>
<title> CSS Lists </title>
<style>
.num
{
 list-style-type: decimal;
 list-style-position: inside;
}
.roman
{
 list-style-type: lower-roman;
 list-style-position: outside;
}
.circle
{
 list-style-type: circle;
 list-style-position: inside;
}
.square
{
 list-style-type: square;
}
.disc
{
 list-style-type: disc;
 list-style-position: inside;
}
</style>
</head>
<body>
<h1> Welcome to this Page </h1>
<h2> Ordered Lists </h2>
<ol class= "num">
<li> INSIDE </li>
<li> two </li>
<li> three </li>
</ol>
<ol class= "roman">
<li> OUTSIDE </li>
<li> two </li>
<li> three </li>
</ol>
<h2> Unordered Lists </h2>
<ul class= "disc">
<li> INSIDE </li>
<li> two </li>
<li> three </li>
</ul>
<ul class= "circle">
<li> INSIDE </li>
<li> two </li>
<li> three </li>
</ul>
<ul class= "square">
<li> DEFAULT </li>
<li> two </li>
<li> three </li>
</ul>
</body>
</html>

Output:

CSS Lists

CSS list-style-image

The list-style-image property describes an image to the marker. It provides the facility to set the bullets of an image. It has a syntax that is similar to another property of CSS i.e., background-image. If it can’t find a corresponding image, it will automatically use the default bullets.

Example:

<!DOCTYPE html>
<html>
<head>
<title> CSS Lists </title>
<style>
.order
{
 list-style-image: url(img.png);
}
.unorder
{
 list-style-image: url(img.png);
}
</style>
</head>
<body>
<h1> Welcome to this Page </h1>
<h2> Ordered Lists </h2>
<ol class= "order">
<li> one </li>
<li> two </li>
<li> three </li>
</ol>
<h2> Unordered Lists </h2>
<ul class= "unorder">
<li> one </li>
<li> two </li>
<li> three </li>
</ul>
</body>
</html>

Output:        

CSS Lists

CSS list-style

It is used as a shorthand attribute that can be applied to set every list property within single expression. The values order of this attribute is image, position, and type. Although if an attribute value is not their then its default value is inserted.

Example:

<!DOCTYPE html>
<html>
<head>
<title> CSS Lists </title>
<style>
.order
{
 list-style: lower-alpha inside url(img.png);
}
.unorder
{
 list-style: disc outside;
}
</style>
</head>
<body>
<h1> Welcome to this Page </h1>
<h2> Ordered Lists </h2>
<ol class= "order">
<li> one </li>
<li> two </li>
<li> three </li>
</ol>
<h2> Unordered Lists </h2>
<ul class= "unorder">
<li> one </li>
<li> two </li>
<li> three </li>
</ul>
</body>
</html>

Output:

CSS Lists

CSS lists along with colors

To show these lists more interesting and attractive, we can apply various colors to these lists. If we add something to the <ol> or <ul> tag, then it will affect a whole list, but if we add something to the <li> tag individually, then it will affect only the items corresponding list.

Example:

<!DOCTYPE html>
<html>
<head>
<title> CSS Lists </title>
<style>
.order
{
 list-style: upper-alpha;
 background: lightblue;
 padding: 20px;
}
.order li
{
 background: pink;
 padding: 10px;
 font-size: 20px;
 margin: 10px;
}
.unorder
{
 list-style: square inside;
 background: cyan;
 padding: 20px;
}
.unorder li
{
 background: lime;
 padding: 10px;
 color: white;
 font-size: 20px;
 margin: 10px;
}
</style>
</head>
<body>
<h1> Welcome to this Page </h1>
<h2> Ordered Lists </h2>
<ol class= "order">
<li> ONE </li>
<li> TWO </li>
<li> THREE </li>
</ol>
<h2> Unordered Lists </h2>
<ul class= "unorder">
<li> ONE </li>
<li> TWO </li>
<li> THREE </li>
</ul>
</body>
</html>

Output:

CSS Lists

Related Topics

CSS @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.

CSS Pagination

CSS Pagination The pagination in CSS is an advantageous approach for indexing of a website’s distinct pages over the homepage. When our site contains multiple pages, we must insert a few...

13 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

CSS Syntax

The CSS syntax contains the selector and the declaration block, which will be clearer with the following example: Selector: A CSS selector specifies the HTML tag we wish to style. A selector can be...

2 minutes read.

CSS Radio Button

Radio Button A radio button has been defined as an element of HTML. It can support us to take any input from the user. But it is challenging to design a...

4 minutes read.

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 minutes read.

CSS Color Keywords

Here, we will discuss the following keywords: transparent currentcolor Inherit Transparent keyword A color can generally be made transparent by using the transparent keyword. Often it is used to for all intents...

4 minutes read.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.

CSS Specificity

CSS Specificity: If one or more conflicting rules of CSS express a similar element, a browser will pursue a few rules to examine the specific one. Specificity can be specified...

3 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

CSS Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

What is a CSS File?

What is a CSS File and How to use it in Html? CSS: - CSS stands for Cascading Style Sheet. CSS is a file of style sheets that describe the presentation of...

4 minutes read.

Divi in CSS

Divi is popular WordPress themes due to its versatility and user-friendly interface. It includes a built-in page builder for sophisticated design options and an assortment of customization features to help...

9 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

CSS Background-blend-mode

Background-blend-mode The background-blend-mode property sets a blend mode of the component’s every background layer (color/image). It illustrates how the element background image blends well with the element background color. We can...

9 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.