📋 HTML <ul>
Tag — Creating Unordered Lists
The <ul>
tag in HTML is used to create unordered lists, which are collections of items where the order doesn’t matter. Each item in the list is wrapped in an <li>
(list item) tag. Unordered lists typically display bullet points by default.
📌 What Is the <ul>
Tag?
- Defines a list of items with no specific order.
- Contains one or more
<li>
elements as list items. - Commonly used for menus, feature lists, or any grouping where order isn’t important.
- Helps organize content clearly and improves readability.
✅ Basic Syntax
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
🧪 Example: Simple Unordered List
<h2>My Favorite Fruits</h2>
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ul>
🎨 Styling <ul>
Lists
You can customize the appearance of <ul>
with CSS, for example changing bullet styles or spacing:
ul {
list-style-type: square; /* Changes bullets to squares */
padding-left: 20px;
color: #333;
}
🔄 Nested Lists
<ul>
elements can be nested inside <li>
items to create sublists:
<ul>
<li>Programming Languages
<ul>
<li>Python</li>
<li>JavaScript</li>
<li>Ruby</li>
</ul>
</li>
<li>Frameworks
<ul>
<li>React</li>
<li>Vue</li>
</ul>
</li>
</ul>
⚠️ Best Practices
- Always use
<li>
tags inside<ul>
to keep the list semantically correct. - Avoid using
<ul>
purely for layout or styling; use CSS instead. - Use
<ul>
when the sequence of items is irrelevant. - For ordered lists where sequence matters, use
<ol>
instead.
🏁 Summary
The <ul>
tag is a fundamental HTML element for creating unordered lists. It improves content structure and readability, especially when order is not important. Combined with CSS, it can be styled to fit various design needs.