HTML CSS, Links and Images
Three building blocks turn a plain HTML document into a real web page: CSS for appearance, links for moving between pages, and images for visual content. Each one is added with a specific tag and a few important attributes, and getting those attributes right matters for both users and search engines.
Connecting CSS to HTML
The recommended way to style a page is an external stylesheet linked from the head with a link element. The rel="stylesheet" attribute tells the browser what the file is, and href gives its path. For a few page-specific rules you can use a style block in the head, and for a one-off tweak a style attribute on the element itself, though inline styles quickly become hard to maintain.
Making links with the anchor tag
The a element creates a hyperlink. Its href attribute decides where it goes:
- Absolute URL: a full address including the protocol, used for other websites.
- Relative URL: a path such as
about.htmlor../index.html, resolved from the current page's location. - Fragment:
#contactjumps to the element withid="contact"on the same page. - Special schemes:
mailto:opens the email app andtel:starts a call on phones.
Adding target="_blank" opens the link in a new tab. Modern browsers automatically apply rel="noopener" behaviour to these links, but adding rel="noopener" yourself is still good practice for older browsers.
Adding images
The img element is a void element with no closing tag. It needs a src pointing at the file and an alt text describing the image. Setting width and height lets the browser reserve the right space before the image loads, so the page does not jump around. loading="lazy" delays downloading images further down the page until the user scrolls near them.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Travel Notes</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<nav>
<a href="index.html">Home</a>
<a href="#gallery">Gallery</a>
<a href="mailto:hello@example.com">Email us</a>
</nav>
<section id="gallery">
<img src="images/hills.jpg" alt="Tea gardens on misty green hills"
width="800" height="533" loading="lazy">
<a href="images/hills-large.jpg">
<img src="images/hills-thumb.jpg" alt="Open the large hills photo"
width="200" height="133">
</a>
</section>
</body>
</html>
The second image is wrapped in a link, making the thumbnail clickable. Its alt text describes what clicking does, because for a screen reader the image is the link text.
Writing useful alt text
Alt text is read aloud by screen readers and shown if the image fails to load. Describe what the image shows or does in context, briefly. Skip phrases like "image of", since screen readers already announce that. For purely decorative images, use an empty value, alt="", so assistive technology skips them. Leaving the attribute out entirely is different: some screen readers then read the file name aloud.
Path mistakes that cause broken images and styles
Most broken images and missing styles come from wrong paths. Relative paths are resolved from the HTML file's folder, not from where the CSS or project root lives. On many servers paths are also case-sensitive, so Images/Hills.JPG and images/hills.jpg are different files even if your own computer treats them as the same. Avoid spaces in file names and check the browser's network tab, which lists every failed request in red.
Takeaway: link stylesheets in the head, choose the right kind of URL for each link, give every image meaningful alt text and dimensions, and double-check relative paths and letter case.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.