Image alt text and optimization in SEO Fundamentals - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When we add images to a webpage, the way we write alt text and optimize images affects how fast the page loads.
We want to understand how the time to load changes as we add more images or bigger images.
Analyze the time complexity of loading images with alt text and optimization.
<img src='image1.jpg' alt='A sunny beach' width='300' height='200' loading='lazy' />
<img src='image2.jpg' alt='Mountain view' width='300' height='200' loading='lazy' />
<img src='image3.jpg' alt='City skyline' width='300' height='200' loading='lazy' />
// Images use optimized sizes and lazy loading to improve performance
This code loads three images with descriptive alt text and uses lazy loading to delay loading until needed.
Look at what repeats when loading images on a page.
- Primary operation: Loading each image file from the server.
- How many times: Once per image, so the number of images (n) times.
As you add more images, the total loading time grows roughly in direct proportion to the number of images.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Loading 10 images |
| 100 | Loading 100 images |
| 1000 | Loading 1000 images |
Pattern observation: Doubling the number of images roughly doubles the loading work.
Time Complexity: O(n)
This means the loading time grows linearly with the number of images on the page.
[X] Wrong: "Adding alt text or optimizing images does not affect loading time."
[OK] Correct: Alt text itself is small but helps accessibility; optimization reduces image size, which directly speeds up loading.
Understanding how image loading scales helps you build faster websites and shows you care about user experience and performance.
What if we changed from lazy loading to eager loading for all images? How would the time complexity change?
Practice
alt text in images on a website?Solution
Step 1: Understand the role of alt text
Alt text provides a description of images for people who use screen readers or when images fail to load.Step 2: Identify the correct purpose
It helps accessibility and SEO by describing the image content clearly.Final Answer:
To describe the image for users who cannot see it -> Option DQuick Check:
Alt text = Image description for accessibility [OK]
- Thinking alt text changes image appearance
- Using alt text for decoration only
- Ignoring alt text for SEO benefits
Solution
Step 1: Review correct HTML syntax for images
The<img>tag uses thealtattribute to provide alternative text.Step 2: Identify the valid syntax
Only<img src='photo.jpg' alt='A sunny beach'>uses the correctimgtag,srcandaltattributes, and proper quoting for values. The others use wrong tags (image), incorrect attributes (alttext,description), or unquoted values with spaces.Final Answer:
<img src='photo.jpg' alt='A sunny beach'> -> Option CQuick Check:
Usealtattribute inside<img>tag [OK]
alt attribute inside <img> tag [OK]- Using wrong attribute names like alttext or description
- Using
<image>instead of<img> - Failing to properly quote attribute values
<img src='logo.png' alt='Company logo' width='200' height='100'>What is the main SEO benefit of including the
alt attribute here?Solution
Step 1: Analyze the role of alt text in SEO
Alt text provides a textual description that search engines can read to understand what the image represents.Step 2: Identify the SEO benefit
This helps improve the website's relevance and ranking for related searches.Final Answer:
It helps search engines understand image content -> Option BQuick Check:
Alt text = SEO image description [OK]
- Confusing alt text with image size or speed
- Thinking alt text hides images
- Assuming alt text changes image appearance
Solution
Step 1: Identify the cause of slow loading
Large image files cause slow loading; compressing reduces file size without losing much quality.Step 2: Maintain SEO best practices
Keeping descriptive alt text ensures accessibility and SEO benefits remain intact.Final Answer:
Compress images before uploading and keep descriptive alt text -> Option AQuick Check:
Compress images + keep alt text = faster and SEO-friendly [OK]
- Removing alt text to save size (hurts SEO/accessibility)
- Uploading large images without compression
- Removing images entirely reduces user experience
Solution
Step 1: Combine SEO and user experience best practices
Descriptive alt text improves SEO and accessibility; compressing images speeds up loading; captions help users understand images.Step 2: Evaluate other options
Generic alt text or removing alt text harms SEO; large images slow loading; skipping captions reduces clarity.Final Answer:
Use descriptive alt text, compress images, and add captions for clarity -> Option AQuick Check:
Alt text + compression + captions = best SEO and UX [OK]
- Using vague alt text hurting SEO
- Uploading large images slowing site
- Ignoring captions reduces user understanding
