×

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 :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

7 minutes read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 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 Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

CSS Background

CSS Background The properties of CSS background are applied to describe the effects of background on the element. Here are five properties of background that affects various elements of HTML: Background-colorBackground-imageBackground-repeatBackground-attachment Background-position Background-color The color of the background...

7 minutes read.

CSS Order

CSS Order CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item. Note: If any component is...

3 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 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.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 minutes read.

CSS z-index Property

CSS z-index: CSS z-index permits us to represent any visual hierarchy over a 3D plane that is the z-axis. This index can be applied to describe the positioned element’s stacking...

2 minutes read.

CSS Padding

CSS Padding: The padding property in CSS is addressed to describe the space among the element border and the element content.This property is quite different from the margin property of...

2 minutes read.

How to change background color in CSS

How to change background color in CSS? The background-color property in CSS would be used to specify the color of an element's background. As the element's background, it uses solid colors. The...

3 minutes read.

How to resize an image in CSS

How to resize an image in CSS? The resize image attribute is used in responsive web design to resize images to fit within the div container automatically. The resize image attribute...

3 minutes read.

CSS Page-break-before Attribute

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

5 minutes read.

CSS Hover

CSS Hover: CSS :hover is used to select the various elements whenever we point the mouse on these elements. We can also use this selector on all the HTML elements,...

3 minutes read.