<ul> and <ol> — DemoThis page shows unordered lists (<ul>), ordered lists (<ol>),
and how to style a <ul> to look like an <ol> using CSS. Each example shows the
output and the code.
<ul><ul> = “unordered list”. Items are shown with bullets (discs by default). Use it
when the order of items does not matter.
My favourite fruits:
<p><strong>My favourite fruits:</strong></p>
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Orange</li>
</ul>
<ul> wraps the list; each item is in a <li>
(list item). The browser shows bullets by default. You can change the bullet style with CSS
(list-style-type: disc | circle | square).
<ol><ol> = “ordered list”. Items are numbered (1, 2, 3…). Use it when the order
matters (steps, rankings, etc.).
Steps to make tea:
<p><strong>Steps to make tea:</strong></p>
<ol>
<li>Boil water</li>
<li>Add tea leaves or bag</li>
<li>Add milk and sugar (optional)</li>
<li>Serve</li>
</ol>
<ol> tells the browser to number the <li>
items automatically. You can change the style with CSS
(list-style-type: decimal | upper-roman | lower-alpha, etc.).
You can put a list inside a list item: put <ul> or
<ol> inside an <li>. The inner list is indented and can have its own bullet
or number style.
Breakfast menu (categories with sub-items):
<p><strong>Breakfast menu:</strong></p>
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>
</li>
<li>Hot drinks
<ol>
<li>Tea</li>
<li>Coffee</li>
</ol>
</li>
<li>Toast</li>
</ul>
<ul>. The first <li>
contains text (“Fruits”) and then another <ul> for sub-items. The second
<li> contains “Hot drinks” and an <ol> for numbered sub-items. The third
<li> has no nested list. Rule: the nested <ul> or <ol>
must be placed inside an <li>, not directly inside the parent list.
<ul> but looking like <ol> (CSS)Sometimes we keep <ul> in HTML (e.g. for semantics or reuse) but want numbers on
screen. We can do that with one CSS property: list-style-type: decimal;.
Top 3 languages (HTML is <ul>, styled with CSS as numbers):
<!-- HTML: we use ul, not ol -->
<p><strong>Top 3 languages:</strong></p>
<ul class="styled-as-ol">
<li>JavaScript</li>
<li>Python</li>
<li>Java</li>
</ul>
<style>
/* Change bullet to numbers — now it looks like an ordered list */
ul.styled-as-ol {
list-style-type: decimal;
padding-left: 1.5em;
}
</style>
<ul> and <li>. The class
styled-as-ol applies list-style-type: decimal;, which replaces the default bullet with
numbers (1, 2, 3…). So the structure is an unordered list, but the presentation looks like an
ordered list. This shows how CSS controls how content looks without changing the HTML tags.
<ul> = unordered list → bullets (disc, circle, square).<ol> = ordered list → numbers or letters (decimal, roman, alpha).<li> for each item.<ul> or <ol> inside an
<li> to get sub-items.<ul> look like an <ol> with
list-style-type: decimal; (and other values like upper-roman,
lower-alpha).