Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Lists are everywhere in web development! 📋
From recipe ingredients and science experiment steps, to feature bullet points and full website navigation bars, HTML lists (<ul> and <ol>) form the structural backbone of grouped information.
By default, web browsers apply built-in styling:
<ul> (Unordered lists): Simple black dots (disc) with about 40px of left padding.<ol> (Ordered lists): Basic Arabic numerals (1, 2, 3...) with the same left indentation.With CSS, you have complete artistic control: swap boring dots for squares, roman numerals, or custom emojis, adjust bullet indentation, or completely strip default bullets to craft horizontal navigation menus!
In this lesson, you will master:
list-style-type for both unordered and ordered listslist-style-position (outside vs inside)Imagine your school's Morning Assembly:
+-------------------------------------------------------------------------+ | LIST-STYLE-POSITION VISUALIZED | +-------------------------------------------------------------------------+ | OUTSIDE (Default): | | The class monitor stands OUTSIDE in the aisle holding the class board, | | while all students stand neatly aligned in a single straight row: | | | | [•] Rohit Sharma, Roll 10, Green House Captain | | and cricket team opening batsman. | | ^ | | Bullet hangs outside the text margin! | | | | INSIDE: | | The monitor steps INSIDE the student line, right next to the student: | | | | [•] Rohit Sharma, Roll 10, Green House Captain | | and cricket team opening batsman. | | ^ | | Second line wraps directly under the bullet itself! | +-------------------------------------------------------------------------+
list-style-typeThe list-style-type property controls the visual marker displayed next to each list item (<li>).
<ul>)Common marker values for bullet points:
| Value | Appearance | Best Used For |
|---|---|---|
disc | Filled black circle (Default) | General point-wise notes |
circle | Hollow unfilled circle | Sub-items or secondary lists |
square | Solid neat square | Technical documents or modern cards |
none | No marker at all | Navigation menus and custom icon lists |
<ol>)Ordered lists have a rich collection of counting numbering systems:
| Value | Example Output | Real-World Use Case |
|---|---|---|
decimal | 1, 2, 3, 4 (Default) | Standard numbered instructions |
decimal-leading-zero | 01, 02, 03 | High-end tech rankings & steps |
lower-alpha | a, b, c, d | Multiple-choice quiz options |
upper-alpha | A, B, C, D | Major exam question sections |
lower-roman | i, ii, iii, iv | Preface chapters or sub-clauses |
upper-roman | I, II, III, IV | School standards (Class X, XII) |
devanagari | १, २, ३, ४ | Hindi / Sanskrit traditional numbering |
list-style-position: Outside vs InsideWhen a list item contains multiple lines of text, how should subsequent lines wrap?
outside (Default)The marker hangs to the left, outside the text content flow. All lines of text remain cleanly aligned on the left edge.
insideThe marker sits inside the text block, behaving like the first word in a paragraph. If the sentence wraps onto line two, it wraps underneath the marker.
list-style ShorthandYou can specify type and position in a single shorthand line:
::before)While CSS supports list-style-image: url('star.png'), images are difficult to align and resize cleanly across different screen resolutions.
The modern industry best practice is using list-style: none; combined with the CSS ::before pseudo-element to display crisp emojis or SVG icons:
Did you know almost every horizontal navigation bar on the internet (Google, YouTube, GitHub) is fundamentally built with an HTML <ul> list?
Why? Because semantic HTML requires navigational links to be grouped as a list.
However, browsers add default margin and 40px of left padding. To build a navbar, you must apply the List Reset:
+-------------------------------------------------------------+ | NAVBAR LIST RESET BREAKDOWN | +-------------------------------------------------------------+ | Default HTML <ul>: | | • Home | | • About | | • Courses | | | | After list-style: none + margin: 0 + padding: 0 + flex: | | [ Home ] [ About ] [ Courses ] [ Contact ] | +-------------------------------------------------------------+
| Bad Practice ❌ | Why It Fails ⚠️ | Better Approach ✅ |
|---|---|---|
Writing margin: 0 on <ul> but forgetting padding: 0 | The list still has a mysterious 40px left gap because browsers use padding-left for default indent! | Always reset both: margin: 0; padding: 0;. |
Setting list-style: none on <li> instead of <ul> | Can cause inconsistent inheritance in nested lists. | Set list-style: none directly on the parent <ul> or <ol>. |
Using list-style-image with huge images | Images cannot be sized in CSS and will display at their full gigantic dimensions. | Use ::before pseudo-element with emojis or font icons for pixel-perfect sizing. |
Forgetting gap or margins between horizontal list items | The text links bump into each other with zero breathing space. | Use Flexbox gap: 20px; on the parent list. |
list-style-type sets bullet or number formats (disc, circle, square, decimal, lower-roman, devanagari, none).list-style-position controls text wrapping (outside hangs bullet outside; inside brings bullet into paragraph flow).list-style: none; and inject emojis using li::before { content: "🎯"; }.list-style: none; margin: 0; padding: 0; when transforming <ul> lists into horizontal headers or footers.margin: 0 on a <ul>, but the list still has empty white space on the left side. What is causing this?list-style-position: outside and inside when list text wraps across multiple lines?list-style-type value renders Indian Devanagari numerals (१, २, ३...)?li::before instead of list-style-image for custom icon bullets?school-canteen-menu.html.In the next lesson, we will continue your web styling journey with Styling Tables: Borders, Striping, and Responsive Tables (Links, Lists and Tables Styling).
👉 Continue to Next Lesson: Styling Tables: Borders, Striping, and Responsive Tables →
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Styling Links with Pseudo-classes | Styling Tables: Borders, Striping, and Responsive Tables |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.