Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Practical HTML and CSS

You're reading from   Practical HTML and CSS Elevate your internet presence by creating modern and high-performance websites for the web

Arrow left icon
Product type Paperback
Published in Nov 2024
Publisher Packt
ISBN-13 9781835080917
Length 492 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (3):
Arrow left icon
Brett Jephson Brett Jephson
Author Profile Icon Brett Jephson
Brett Jephson
Lewis Coulson Lewis Coulson
Author Profile Icon Lewis Coulson
Lewis Coulson
Ana Carolina Silveira Ana Carolina Silveira
Author Profile Icon Ana Carolina Silveira
Ana Carolina Silveira
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: Introducing HTML and CSS
2. Chapter 1: Introduction to HTML and CSS FREE CHAPTER 3. Chapter 2: Structure and Layout 4. Chapter 3: Text and Typography Styling 5. Part 2: Understanding Website Fundamentals
6. Chapter 4: Creating and Styling Forms 7. Chapter 5: Adding Animation to Web Pages 8. Chapter 6: Themes, Color, and Polishing Techniques 9. Part 3: Building for All
10. Chapter 7: Using CSS and HTML to Boost Performance 11. Chapter 8: Responsive Web Design and Media Queries 12. Chapter 9: Ensuring Accessibility in HTML and CSS 13. Part 4: Advanced Concepts
14. Chapter 10: SEO Essentials for Web Developers 15. Chapter 11: Preprocessors and Tooling for Efficient Development 16. Chapter 12: Strategies for Maintaining CSS Code 17. Chapter 13: The Future of HTML and CSS – Advancements and Trends 18. Index 19. Other Books You May Enjoy

Optimizing images for SEO

By optimizing images for SEO, you not only enhance the aesthetic appeal and accessibility of your website but also contribute to its overall performance, visibility, and user satisfaction.

Optimizing images for SEO involves several practices that help ensure images contribute positively to a website’s search engine ranking and overall user experience. Here are some key strategies:

  • Choose the right file format:
    • JPEG: Best for photographs and images with many colors, JPEG offers a good balance between quality and file size
    • PNG: Best for images that require transparency and for simpler images with fewer colors
    • WebP: A modern format that provides superior compression for both lossless and lossy images, supported by most browsers
    • SVG: Best for logos, icons, and simple graphics; it’s a vector format, so it’s scalable without loss of quality
  • Compress images: Use tools such as TinyPNG, ImageOptim, or ShortPixel to reduce image file sizes without compromising quality. Ensure that images are appropriately compressed to decrease load times, improving page speed, which is a ranking factor.
  • Use descriptive file names: Rename image files to include relevant keywords before uploading them. Instead of IMG_1234.jpg, use blue-widget-for-sale.jpg. Use hyphens to separate words (not underscores).
  • Implement responsive images: Use the srcset attribute to serve different image sizes based on the user’s device, ensuring images are not larger than necessary. Implement the <picture> element to offer different image formats.
  • Use lazy loading: Implement lazy loading to defer the loading of offscreen images until the user scrolls near them. This improves initial page load time. Use the loading="lazy" attribute on <img> tags or JavaScript libraries for lazy loading.
  • Ensure images are crawlable: Make sure images are not blocked by robots.txt. Use image sitemaps to help search engines discover and index images on your site.
  • Add structured data: Use structured data (schema.org) to mark up images with additional information such as product details, recipes, and more. This can enhance search results with rich snippets and improve visibility.
  • Optimize image dimensions: Serve images at the correct dimensions to avoid browser scaling. This ensures that images look sharp and load faster. Properly sizing images for the web involves optimizing images so they are displayed at the correct dimensions and file size, which helps improve the overall user experience.

    Use CSS to control image display and avoid inline styles that can override responsive behavior:

    • HTML/CSS layout: Determine the maximum display size of the image on your webpage using HTML/CSS
    • Responsive design: Consider responsive design principles to ensure images scale appropriately on different devices and screen sizes

    Here’s an example of a properly sized image with responsive design:

    <img
        src="image.jpg"
        alt="Description of the image"
        width="800"
        height="600"
    >
    <!--Example of using srcset for responsive images -->
    <img src="image.jpg"
        srcset="image-400.jpg 400w,
                image-800.jpg 800w,
                image-1200.jpg 1200w"
        sizes="(max-width: 600px) 400px,
               (max-width: 1000px) 800px,
               1200px"
        alt="Description of the image">
  • Leverage CDNs: Use CDNs to distribute image content globally, reducing latency and improving load times for users around the world.
  • Use caption and context: Provide captions and context for images. Search engines use surrounding text to understand the image content. Well-described images in context can rank better in image search.
  • Regularly audit and update: Regularly audit your site’s images for performance and SEO improvements. Update alt text, compress images, and check for broken links or outdated content.

Properly optimizing images in HTML is essential for enhancing both accessibility and SEO. Here is an example of HTML code demonstrating how to effectively use an optimized image:

<picture>
  <source srcset="image.webp" type="image/webp">
  <source srcset="image.jpg" type="image/jpeg">
  <img
    src="image.jpg"
    alt="Description of the image"
    loading="lazy" width="600"
    height="400"
  >
</picture>

We have established that optimizing images is crucial for improving website performance, user experience, and SEO. Here are some tools and resources that can help streamline the image optimization process:

  • Image compression: TinyPNG, JPEG-Optimizer, and ImageOptim
  • Responsive images: Cloudinary and Imgix
  • Lazy loading: LazySizes and the native HTML loading="lazy" attribute

These tools and resources cater to different aspects of image optimization, from compression and resizing to accessibility and SEO enhancement. By leveraging these tools effectively, web developers and content creators can ensure that their images contribute positively to overall website performance and user satisfaction.

By following these practices, you can ensure that your images contribute to a better user experience and improved SEO performance, helping your website rank higher in search results and perform better overall. Next, let’s examine the best practices for using the alt tag for images in accordance with SEO techniques.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image