UL Tag in HTMLUL TagThe <ul> tag, which stands for "unordered list," is a crucial HTML component used to generate lists of items where the order of the items has no significance. Unordered lists (<ul>) are used when the order of the items is not important, and you wish to present the elements with bullet points or other markers to denote separation, in contrast to ordered lists (<ol>), which depict lists with a defined order. Purpose:
Basic Syntax and StructureSyntax: Unordered lists combine the <ul> tag with< li> elements. One item in the list is represented by each <li> element. Here is a simple example of how to use the HTML <ul> tag to create an unordered list: This example creates an unordered list with bullet points by enclosing three list items (<li>) in <ul> tags as follows: Attributes of the UL TagSeveral attributes are supported by the HTML <ul> tag and can be used to modify the appearance and behaviour of unordered lists. Here are some typical attributes and their outcomes: 1. Type Attribute:The type attribute describes the bullet point or marker used for list items. The common values "disc" (the default filled circle), "circle" (the empty circle), and "square" (the filled square) are all examples. Example: This example uses the type attribute with different values. Output: 2. Class AttributeThe class attribute enables you to provide the <ul> element with a CSS class that may be used to style or target the list with CSS. Example: Output: Creating Nested Unordered Lists in HTMLYou may create hierarchical structures with nested unordered lists, where a sub-list is contained within an item of an outer list. A <ul> (unordered list) or <ol> (ordered list) element is inserted inside a <li> (list item) element to accomplish this. To build nested unordered lists, follow these steps:
Example of Nested Unordered Lists:To demonstrate nested unordered lists, let's create a simple example. Consider making a list of animals with sub-lists for each animal category: Example: Output: Styling Unordered ListsYou may style unordered lists using CSS (Cascading Style Sheets) to make them look the way you want them to on your website. You can change many features, such as text attributes, list markers (bullets), and the distance between items. Here's how to use CSS to style unordered lists: 1. Changing List Markers (bullets):The list-style-type parameter allows you to modify how list markers appear. Disc (the default filled circle), circle (the empty circle), square (the filled square), and custom images are examples of common values. 2. Customizing List Markers Position:To change the position of list markers, use the list-style-position property. When set inside, markers are placed inside the list item's content-box; when set to outside (the default), they are outside. 3. Modifying Text PropertiesTargeting the <li> elements within the <ul> will allow you to change the text properties within list items, such as color, font, and size. 4. SpacingUsing the margin or padding properties, change the spacing between list items. To add space between list items, for instance: 5. Custom Images as List MarkersBy including the URL of your custom image in the list-style-image attribute, you may use it as a list marker. The complete example of CSS code for styling an unordered list is shown below: Output: Practical Use Cases for Unordered Lists in Web Design:Unordered lists (abbreviated as "ul" in web design) are flexible elements that may be used to improve how content is organized and presented on websites. Unordered lists are frequently used in the following situations from the real world:
Supporting Browsers
Next TopicAutomatic Image Slider in HTML and CSS |