๐Ÿ“ Html Css

Links and Images in HTML

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
2 min
๐Ÿ‘๏ธ
Views
296
๐ŸŒฑ
Level
Beginner

Links and images are two elements that make the web what it is. The <a> tag connects pages together; <img> embeds visual content. We’ll cover the attributes beginners often miss and build a working DevBlog example.

Basic syntax:

<a href="https://docs.python.org">Python Documentation</a>

href (HyperText Reference) is the address the link points to. The text between the tags is the clickable label.

Absolute vs relative URLs

<!-- Absolute โ€” full address including protocol -->
<a href="https://python.org">python.org</a>

<!-- Relative โ€” path within the same site -->
<a href="/posts/asyncio.html">asyncio article</a>
<a href="../index.html">Back to home</a>
<a href="contact.html">Contact</a>

Relative URLs are preferred for internal links: if you ever change the domain, they don’t need updating.

Opening in a new tab

<a href="https://github.com/me" target="_blank" rel="noopener noreferrer">
  GitHub
</a>
  • target="_blank" โ€” open in a new tab/window.
  • rel="noopener noreferrer" โ€” security: the new tab won’t have access to the parent page’s window object.

Rule: always add rel="noopener noreferrer" to external links that use target="_blank".

Jump to a specific point on the same page:

<!-- Target: element with an id -->
<h2 id="installation">Installation</h2>

<!-- Anchor link -->
<a href="#installation">Go to installation</a>

<!-- Anchor on another page -->
<a href="/docs/setup.html#installation">Installation</a>

Anchors are perfect for tables of contents in long blog articles.

Special URL schemes

<!-- Open an email client -->
<a href="mailto:hello@devblog.com">Email me</a>

<!-- Download a file -->
<a href="/files/resume.pdf" download>Download resume</a>

The <img> tag โ€” images

<img
  src="/images/python-logo.png"
  alt="Python logo"
  width="200"
  height="200"
/>

Attributes:

Attribute Required Description
src Yes Path to the image
alt Yes Text description for accessibility
width Recommended Width in pixels
height Recommended Height in pixels

Why alt matters

The alt attribute serves three purposes:
1. Screen readers speak it aloud for visually impaired users.
2. The browser shows the text if the image fails to load.
3. Search engines index the image content via alt.

<!-- Bad: missing or empty alt -->
<img src="avatar.jpg" />

<!-- Good: describes what is shown -->
<img src="avatar.jpg" alt="Photo of blog author Alex Petrov" />

<!-- Decorative image: alt="" intentionally empty -->
<img src="divider.png" alt="" role="presentation" />

Why specify width and height

The browser reserves space for the image before it loads. This eliminates content jumping (Cumulative Layout Shift) and improves Core Web Vitals scores.

Image formats

Format Best for
.jpg Photographs
.png Icons with transparency, screenshots
.svg Vector logos and icons
.webp Replacement for jpg/png โ€” smaller file size
.avif Newest format, best compression

Wrap <img> with <a>:

<a href="/posts/python-decorators.html">
  <img
    src="/images/decorators-cover.jpg"
    alt="Cover image for the Python decorators article"
    width="640"
    height="360"
  />
</a>

Example: DevBlog post card

<article class="post-card">
  <a href="/posts/asyncio-guide.html">
    <img
      src="/images/asyncio-cover.webp"
      alt="Diagram of asyncio event loop"
      width="640"
      height="360"
    />
  </a>
  <div class="post-card__body">
    <h2>
      <a href="/posts/asyncio-guide.html">
        The Complete asyncio Guide
      </a>
    </h2>
    <p>
      We explore the event loop, coroutines, and practical patterns
      for writing asynchronous Python code.
    </p>
    <a href="/posts/asyncio-guide.html" class="read-more">
      Read more โ†’
    </a>
  </div>
</article>

Notice that links to the same URL appear three times โ€” on the image, in the heading, and in the “Read more” button. This is the standard pattern for content cards.

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

Semantic HTML5 Tags

Semantic tags describe the meaning of content, not just its appearance. A browser won't visually...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 315
๐Ÿ“

What is HTML

HTML is a markup language that tells the browser how to interpret a page's structure....

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 297
๐Ÿ“

HTML Lists

Lists are one of the most common markup elements. Navigation menus, post tags, how-to steps,...

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 337
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

Markup for Backend Developers Open course curriculum