HTML Lists & Images – An Easy Guide To HTLM For Beginners

by THT
easy html lists and html images for beginners

HTML lists & images are the most frequently used elements when writing HTML code.

Lists add structure to your content, allowing you to organize and present information in the most engaging way. Images make for a visually appealing user experience. Both HTML lists and images help format your web page.

This post will go over the basics you need to know for both HTML lists & images. We start by understanding two kinds of HTML lists – not too exciting – and move on to how you can insert images to your web page (the fun part).

Unordered Lists

So-called “unordered” because it renders a bulleted list instead of a numbered one. The list item marker (bullet) can be styled with CSS.

Unordered lists are created with the unordered list tag  <ul></ul> and its child element the list item tag <li></li>.

ul tag with li tags
unordered list tags with list items

Each item on the list goes in a <li> tag which is a block element taking up the entire line. You can have as many <li>s as you want, but only need one <ul> per list.

Without <li>, <ul> acts similarly to a <div>.

ul tag without li tags
An unordered list without list items
unordered list tags no list items

Unordered lists are the most common type of lists when writing HTML – I can’t remember ever using its opposite, the ordered list, in practice.

Ordered Lists

Ordered lists are created with the <ol></ol> tags. They can be numeric or alphanumeric with a default ascending order which you can change (see below).

ol tag with li default
ordered list tags with default list items

Similar to unordered lists, ordered lists require the use of the list item child tags <li></li> for each item you want to be on the list.

Ordered List Attributes

  • Don’t want the list to start at 1? Then set its start attribute.
<ol start="#">with # being the number you want your list to start at
  • Want to create a countdown list? Then add the reversed attribute.
<ol reversed>
setting attributes of ol
attributes of ordered lists
  • Want an ordered list that is not numerical but in letters or roman numerals? Then set the type attribute.
<ol type="A or a || I or I"> 

note: (||) is known as a logical "or" operator ~ we figured writing three "or"s wasn't doing anyone any favors
setting different ol types html lists
types of ordered lists

Note:

  1. The letters or roman numerals can be uppercase or lowercase.
  2. The default type is “1” for numeric lists.
  3. You can reverse and change the starting point of the different types of ordered lists using the two attributes mentioned above.

HTML Images

<img src="file location" width="#" height="#" alt="descriptive text">

The image tag is a self-closing tag and it allows you to insert an image into your code.

In the example below feel free to use any image you want – we found Spongebob in google images.

img src as url
image src url html

The src specifies the source of the image and can be a link instead of a file path on your computer – you don’t have to download an image to use it. For the example above we copied the image address by right-clicking on the image.

how to get img url

Please note the image address isn’t the same thing as link address.

However, using the image address is not reliable because if anything changes on the website you are pulling the image from, then your code will break. So if the image was taken down, deleted, or the site was updated or not working – all things that are out of your control – then there will be no image on your end.

The src attribute isn’t optional – the width and height attributes totally are. You can set the latter two using your style attribute inline or using an external style sheet.

If you don’t provide the source of the image (src) the browser won’t know where to locate the image file.

img attributes
Setting a different width & height for our Spongebob image
image attributes html

The alt attribute, which is optional, sets the alternative text for the image. The purpose is to provide a short description of the displayed image for when the image fails to load. It also helps visually impaired users as it’s read by screen readers.

For more helpful attributes of the image tag browse here.

File paths

If your image source is a URL, then you just need to paste the URL as we did with our Spongebob image.

But if your image is located in a certain folder on your computer, then you need to reference the file path correctly or the image won’t render.

File paths can be somewhat nuanced, especially in the beginning. Here’s a brief breakdown to get you started:

SrcLocated…
picture.jpgSame directory as the current file
images/picture.jpgImages directory in the current folder as the current file
/images/picture.jpgImages directory at the root of the current file
../picture.jpgIn directory one level up from the current directory

Directory = Folder

img src local filepath
image filepath located on desktop

In the example above with THT’s header, the image is located on the desktop which also happens to be the location of our HTML file. Therefore the two are in the same location, same directory – the desktop. We can then use the first file path from the table.

filepaths html images

Think of a directory as a folder. It designates a specific location on your computer where your files are located.

Hint: In VS Code, when you have the right file path you’ll notice autocomplete giving you a dropdown menu of options as you type. That’s one way to know your location is correct.

And that just about wraps up HTML lists & images. Hopefully, you had fun playing with images and are ready for more?

Related Posts