/

HTML / CSS / JavaScript Tutorial

HTML Element: <li>

[this page | pdf | back links]

The HTML <li> element indicates a list item. It is used in <ol> elements (ordered lists), <ul> elements (unordered lists) and <menu> elements (menu lists).

 

The attributes it can take (other than HTML global attributes and HTML event attributes) include:

 

Attribute

Description

More

value

Value of element

Here

 

It used to support the type attribute (which specified what kind of bullet point should be used with the list element), but this is no longer supported in HTML 5 (similar effects can be achieved using CSS).

 

To create or access such an element in JavaScript see here. The corresponding HTML DOM object supports standard DOM properties and methods, and additional properties with the same name and meaning as the attributes of the underlying HTML element referred to above. The default style applicable to this element is shown here.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using HTML:<br>
<ol>
<li>Apple</li>
<li>Banana</li>
</ol>

<br><br>Created using JavaScript:<br>
<span id="element"></span>

<script>
var x = document.getElementById("element");
var x1 = document.createElement("LI");
var x2 = document.createElement("LI");
var txt1 = document.createTextNode("Apple");
var txt2 = document.createTextNode("Banana");
x1.appendChild(txt1);
x2.appendChild(txt2);
x.appendChild(x1);
x.appendChild(x2);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Elements


Desktop view | Switch to Mobile