Lesson 4
18 min
ul, ol, li and the a tag to navigate between pages.
An unordered list (ul, "unordered list") displays its items with a bullet, when the order doesn't matter. Each item is written with<li>("list item").
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
An ordered list (ol, "ordered list") automatically numbers its items, which is useful for steps to follow in order.
<ol>
<li>Open the editor</li>
<li>Create the index.html file</li>
<li>Open the page in the browser</li>
</ol>
<!-- You can change the starting point -->
<ol start="5">
<li>Fifth step</li>
<li>Sixth step</li>
</ol>
<!-- Or reverse the order -->
<ol reversed>
<li>Last</li>
<li>Second-to-last</li>
</ol>
You can place a list inside an<li>to create subcategories, like a multi-level outline.
<ul>
<li>
Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</li>
<li>
Backend
<ul>
<li>Node.js</li>
<li>Python</li>
</ul>
</li>
</ul>
Less well known, the description list (dl) associates a term (dt) with its definition (dd) — handy for a glossary or an FAQ.
<dl>
<dt>HTML</dt>
<dd>Language for structuring web content.</dd>
<dt>CSS</dt>
<dd>Language for visual styling.</dd>
</dl>To create a link to another page or another site, you use the<a>tag ("anchor") with thehrefattribute ("hypertext reference").
<!-- External link -->
<a href="https://developer.mozilla.org">MDN documentation</a>
<!-- Relative internal link -->
<a href="/contact">Contact page</a>
<!-- Open in a new tab -->
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
Open in a new tab
</a>
<!-- Link to an email address -->
<a href="mailto:contact@example.com">Write to us</a>
<!-- Link to a phone number -->
<a href="tel:+15551234567">555 123 4567</a>
<!-- Link to an anchor on the same page -->
<a href="#contact-section">Go to the contact section</a>
<section id="contact-section">...</section>target="_blank" opens the link in a new tab.rel="noopener noreferrer" is recommended with target="_blank" for security and performance reasons./ points to a page on your own site (absolute path from the root).# jumps to an element with that id on the same page.Common mistake
Never use <a href="#">on its own to trigger a JavaScript action: it scrolls the page back to the top. Use a <button>for actions, and keep <a>for navigation.
Exercise
Go further
mailto:link to your email address at the bottom of the page.