Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

CSS Lists

CSS Lists

Unordered Lists:

  • Coffee
  • Tea
  • Coca Cola

 

  • Coffee
  • Tea
  • Coca Cola

Ordered Lists:

  1. Coffee
  2. Tea
  3. Coca Cola
  1. Coffee
  2. Tea
  3. Coca Cola

HTML Lists and CSS List Properties

In HTML, there are two primary list types:

  1. Unordered lists (<ul>) – list items are marked with bullets.
  2. Ordered lists (<ol>) – list items are marked with numbers or letters.

CSS list properties enable you to:

  1. Customize list item markers for ordered lists.
  2. Customize list item markers for unordered lists.
  3. Utilize images as list item markers.
  4. Apply background colors to lists and list items.

Different List Item Markers

The list-style-type property determines the style of the marker used for list items.

Below is an example showcasing a variety of available list item markers:

Example

ul.a {
  list-style-type: circle;
}

ul.b {
  list-style-type: square;
}

ol.c {
  list-style-type: upper-roman;
}

ol.d {
  list-style-type: lower-alpha;
}

Please note: Certain values correspond to unordered lists, while others are for ordered lists.

An Image as The List Item Marker

The list-style-image property allows you to designate an image as the marker for list items.

Example

ul {
  list-style-image: url(‘sqpurple.gif’);
}

Position The List Item Markers

The list-style-position property determines the placement of list item markers (bullet points).

When set to “list-style-position: outside;”, the bullet points will appear outside the list item, and the start of each line of a list item will be vertically aligned. This is the default behavior.

  • Coffee – A brewed drink prepared from roasted coffee beans…
  • Tea
  • Coca-cola

When specified as “list-style-position: inside;”, the bullet points will be positioned inside the list item. This means they are considered part of the list item’s text, causing the text to be pushed at the beginning accordingly.

  • Coffee – A brewed drink prepared from roasted coffee beans…
  • Tea
  • Coca-cola

Example

ul.a {
  list-style-position: outside;
}

ul.b {
  list-style-position: inside;
}

Remove Default Settings

The list-style-type: none property is utilized to eliminate markers or bullets from lists. It’s important to note that lists also have default margin and padding. To remove these defaults, apply margin:0 and padding:0 to <ul> or <ol>.

Example

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

List – Shorthand property

The list-style property serves as a shorthand for setting all list properties in a single declaration.

Example

ul {
  list-style: square inside url(“sqpurple.gif”);
}

When employing the shorthand property, the order of property values is as follows:

  1. list-style-type: Specifies the type of list item marker.
  2. list-style-position: Determines if the list-item markers should be positioned inside or outside the content flow.
  3. list-style-image: Designates an image as the list item marker.

If any of the above property values are omitted, the default value for the missing property will be applied, if available.

Styling List With Colors

You can enhance the appearance of lists by applying colors, adding visual interest to them.

Styles applied to the <ol> or <ul> tag will affect the entire list, while properties added to the <li> tag will impact individual list items.

Example

ol {
  background: #ff9999;
  padding: 20px;
}

ul {
  background: #3399ff;
  padding: 20px;
}

ol li {
  background: #ffe5e5;
  color: darkred;
  padding: 5px;
  margin-left: 35px;
}

ul li {
  background: #cce5ff;
  color: darkblue;
  margin: 5px;
}

Result:

Image

 

All CSS List Properties

Property

Description

list-style

Combines all list properties into a single declaration.

list-style-image

Uses an image as the list-item marker.

list-style-position

Defines the position of list-item markers (bullet points).

list-style-type

Defines the type of list-item marker.