Image optimization skill

When the user wants to optimize images for search engines and performance.

by kostja94·MIT license·★ 1,006 Stars on the repo·GitHub ↗

Use now

Files of Image optimization

kostja94/main1 file shown
SKILL.md
Show the full text263 lines

SEO On-Page: Image Optimization

Guides image optimization for Google Search (text results, Image Pack, Google Images, Discover), Core Web Vitals (LCP), and accessibility. Consolidates image-related best practices from components (hero, trust-badges) and pages (landing-page). References: Google Image SEO, Semrush Image SEO.

When invoking: On first use, if helpful, open with 1–2 sentences on what this skill covers and why it matters, then provide the main output. On subsequent use or when the user asks to skip, go directly to the main output.

Scope

  • Discovery & indexing: HTML img elements, image sitemap
  • Format & performance: WebP, responsive images, lazy loading, LCP; full CWV optimization in core-web-vitals
  • Metadata: Alt text, file names, captions
  • Preferred image: primaryImageOfPage, og:image; thumbnail next to title/description in search results
  • Structured data: ImageObject, image in Article/Product/etc.

Initial Assessment

Project context: Read root contextus.md when present and load only the modules relevant to this task. Without Contextus, use available project material or user-provided facts and ask for missing information; do not create a parallel context system.

Identify:

  1. Context: Hero, content page, product, trust badge, social preview
  2. Above vs below fold: LCP candidate (hero) vs lazy-loadable
  3. Image count: Single hero vs gallery, programmatic pages

1. Discovery & Indexing

Use HTML Image Elements

Google finds images in the src attribute of <img> (including inside <picture>). CSS background images are not indexed.

Do Don't
<img src="puppy.jpg" alt="Golden retriever puppy" /> <div style="background-image:url(puppy.jpg)">
Image Sitemap

Submit an image sitemap to help Google discover images it might otherwise miss. Image sitemaps can include URLs from CDNs (other domains); verify CDN domain in Search Console for crawl error reporting.

Structure (from Google):

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <url>
    <loc>https://example.com/page</loc>
    <image:image>
      <image:loc>https://example.com/image.jpg</image:loc>
    </image:image>
  </url>
</urlset>

See xml-sitemap for sitemap index and submission. Image sitemap is an extension; can be standalone or combined with page sitemap.


2. Format & Performance

Supported Formats

Google supports: BMP, GIF, JPEG, PNG, WebP, SVG, AVIF. Match filename extension to format.

Format Best for Notes
WebP Photos, graphics Smaller files, faster load; lossy + lossless; transparency, animation
AVIF Modern browsers Even smaller than WebP; check support
JPEG Standard photos Fallback; widely supported
PNG Transparency, detail Larger; use when needed
SVG Icons, logos Scalable; use <title> for inline SVG alt
GIF Simple animation First frame only for preview
Responsive Images

Use <picture> or srcset for different screen sizes. Always provide fallback src—some crawlers don't understand srcset.

<img
  srcset="image-320w.jpg 320w, image-480w.jpg 480w, image-800w.jpg 800w"
  sizes="(max-width: 320px) 280px, (max-width: 480px) 440px, 800px"
  src="image-800w.jpg"
  alt="Descriptive alt text">

Picture element (format fallback, e.g. WebP → PNG):

<picture>
  <source type="image/webp" srcset="image.webp">
  <img src="image.png" alt="Descriptive alt text">
</picture>
Data URI (Inline Images)

Base64 data URIs (data:image/...;base64,...) reduce HTTP requests but increase HTML size. Use sparingly for small icons; avoid for large images. See web.dev.

Resize & Compress
  • Max width: Generally ≤2,500px; match container max-width
  • Compression: WebP preferred; quality 75–85 for lossy; 72dpi for web
  • LCP: Hero/above-fold images are LCP candidates; optimize aggressively
Lazy Loading

Use loading="lazy" only for below-fold images. Above-fold images (hero) must load immediately—lazy loading them hurts LCP.

<img src="hero.jpg" alt="..." loading="eager">
<img src="below-fold.jpg" alt="..." loading="lazy">

3. Alt Text

Alt text improves accessibility (screen readers, low bandwidth) and SEO (Google uses it with computer vision to understand images). It also serves as anchor text if the image is a link.

Best Practices
Do Don't
Useful, information-rich description Keyword stuffing
Context of page content "image of" or "photo of" (redundant)
Max ~125 characters (some assistive tech truncates) Empty alt on meaningful images
Descriptive for functional images Alt on purely decorative images (use alt="")

Examples (from Google):

  • ❌ Missing: <img src="puppy.jpg"/>
  • ❌ Stuffing: alt="puppy dog baby dog pup pups puppies..."
  • ✅ Better: alt="puppy"
  • ✅ Best: alt="Dalmatian puppy playing fetch"
Captions

Google extracts image context from captions and nearby text. Use <figcaption> or descriptive text near the image.

Use Purpose
Topic relevance Caption describes image subject; supports indexing
Featured Snippets Images near answers with captions can capture thumbnail slots; see featured-snippet
Image Pack Alt + caption + file name help Image Pack display; see serp-features
Inline SVG

Use <title> inside SVG for accessibility:

<svg aria-labelledby="svgtitle1">
  <title id="svgtitle1">Descriptive text for the SVG</title>
</svg>

4. File Names

Descriptive filenames give Google light clues about subject matter.

Do Don't
apple-iphone-15-pink-side-view.jpg IMG00353.jpg
Short, hyphen-separated Generic: image1.jpg, pic.gif
Localize filenames for translated pages Overly long filenames

5. Preferred Image (SERP Thumbnail & Discover)

When users search for keywords, optimized images can appear as thumbnails next to the page title and description in search results—enhancing visibility and CTR. Google also uses these images for Google Discover. Search Engine Land

Google selects thumbnails automatically from multiple sources. Influence selection via:

Schema: primaryImageOfPage
{
  "@context": "https://schema.org",
  "@type": "WebPage",
  "url": "https://example.com/page",
  "primaryImageOfPage": "https://example.com/images/cat.png"
}

Or attach image to main entity (e.g. BlogPosting, Article) via mainEntity or mainEntityOfPage.

Open Graph
<meta property="og:image" content="https://example.com/images/cat.png">

Preferred image rules: Relevant, representative; avoid generic (e.g. logo) or text-heavy images; avoid extreme aspect ratios; high resolution. See open-graph, twitter-cards for social specs.

Google Discover (if targeting Discover): ≥1200px wide; ≥300KB; 16:9 aspect ratio preferred; important content visible in landscape crop.


6. Page Context

  • Title & meta description: Google uses page title and meta for image result snippets. See title-tag, meta-description.
  • Placement: Put images near relevant text; page subject matter influences image indexing.
  • Same URL: Reference the same image with the same URL across pages for cache efficiency and crawl budget.

7. Structured Data

Add structured data for rich results in Google Images (badges, extra info). Image attribute is required for eligibility. See schema-markup for ImageObject, Article, Product, Recipe, etc.


8. Specs by Context

Context Priority Notes
Hero LCP, alt, no lazy See hero-generator; above-fold, fast load
Article / Blog hero 1200–1600px wide; proportional height; 1200×630 for og:image Same image for Schema, Open Graph, Twitter Cards; under 200 KB; WebP preferred; descriptive alt; set width/height to prevent CLS; use srcset/sizes for responsive; articles with relevant images get ~94% more views
Trust badges Alt text See trust-badges-generator; e.g. "Norton Secured"
Landing page All above See landing-page-generator Pre-Delivery Checklist
OG / Twitter 1200×630, 1200×675 See open-graph, twitter-cards
Platforms Per-platform X, LinkedIn, Pinterest—see platform skills

9. Opt-Out & SafeSearch

  • Inline linking opt-out: Prevent full-sized image display in Google Images via HTTP referrer check (200 or 204). See Google docs.
  • SafeSearch: Label pages for explicit content if applicable.

Output Format

  • Alt text suggestions per image
  • Captions (if applicable; snippet/Image Pack context)
  • File name recommendations
  • Format (WebP, fallback)
  • Responsive (srcset/sizes or picture)
  • Lazy loading (above-fold vs below-fold)
  • Image sitemap (if many images)
  • Preferred image (schema, og:image) for key pages
  • core-web-vitals: LCP, INP, CLS; image optimization supports LCP
  • xml-sitemap: Sitemap structure; image sitemap extension
  • open-graph, twitter-cards: og:image, twitter:image; social preview
  • schema-markup: ImageObject, Article/Product image
  • content-optimization: Multimedia in content; defers image SEO to this skill
  • featured-snippet: Images near answers + captions; snippet thumbnail
  • serp-features: Image Pack; alt, captions, file names
  • visual-content: Visual content for social, infographics; website images use this skill
1---
2name: image-optimization
3description: When the user wants to optimize images for search engines and performance. Also use when the user mentions "image SEO," "alt text," "image captions," "figcaption," "image optimization," "WebP," "lazy loading," "LCP," "image sitemap," "responsive images," "srcset," "image format," or "hero image optimization." For CWV, use core-web-vitals.
4metadata:
5 version: 1.2.1
6---
7 
8# SEO On-Page: Image Optimization
9 
10Guides image optimization for Google Search (text results, Image Pack, Google Images, Discover), Core Web Vitals (LCP), and accessibility. Consolidates image-related best practices from components (hero, trust-badges) and pages (landing-page). References: [Google Image SEO](https://developers.google.com/search/docs/appearance/google-images), [Semrush Image SEO](https://www.semrush.com/blog/image-seo/).
11 
12**When invoking**: On **first use**, if helpful, open with 1–2 sentences on what this skill covers and why it matters, then provide the main output. On **subsequent use** or when the user asks to skip, go directly to the main output.
13 
14## Scope
15 
16- **Discovery & indexing**: HTML img elements, image sitemap
17- **Format & performance**: WebP, responsive images, lazy loading, LCP; full CWV optimization in **core-web-vitals**
18- **Metadata**: Alt text, file names, captions
19- **Preferred image**: primaryImageOfPage, og:image; thumbnail next to title/description in search results
20- **Structured data**: ImageObject, image in Article/Product/etc.
21 
22## Initial Assessment
23 
24**Project context:** Read root `contextus.md` when present and load only the modules relevant to this task. Without Contextus, use available project material or user-provided facts and ask for missing information; do not create a parallel context system.
25 
26Identify:
271. **Context**: Hero, content page, product, trust badge, social preview
282. **Above vs below fold**: LCP candidate (hero) vs lazy-loadable
293. **Image count**: Single hero vs gallery, programmatic pages
30 
31---
32 
33## 1. Discovery & Indexing
34 
35### Use HTML Image Elements
36 
37Google finds images in the `src` attribute of `<img>` (including inside `<picture>`). **CSS background images are not indexed.**
38 
39| Do | Don't |
40|----|-------|
41| `<img src="puppy.jpg" alt="Golden retriever puppy" />` | `<div style="background-image:url(puppy.jpg)">` |
42 
43### Image Sitemap
44 
45Submit an [image sitemap](https://developers.google.com/search/docs/crawling-indexing/sitemaps/image-sitemaps) to help Google discover images it might otherwise miss. Image sitemaps can include URLs from CDNs (other domains); verify CDN domain in Search Console for crawl error reporting.
46 
47**Structure** (from Google):
48 
49```xml
50<?xml version="1.0" encoding="UTF-8"?>
51<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
52 xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
53 <url>
54 <loc>https://example.com/page</loc>
55 <image:image>
56 <image:loc>https://example.com/image.jpg</image:loc>
57 </image:image>
58 </url>
59</urlset>
60```
61 
62See **xml-sitemap** for sitemap index and submission. Image sitemap is an extension; can be standalone or combined with page sitemap.
63 
64---
65 
66## 2. Format & Performance
67 
68### Supported Formats
69 
70Google supports: **BMP, GIF, JPEG, PNG, WebP, SVG, AVIF**. Match filename extension to format.
71 
72| Format | Best for | Notes |
73|--------|----------|-------|
74| **WebP** | Photos, graphics | Smaller files, faster load; lossy + lossless; transparency, animation |
75| **AVIF** | Modern browsers | Even smaller than WebP; check support |
76| **JPEG** | Standard photos | Fallback; widely supported |
77| **PNG** | Transparency, detail | Larger; use when needed |
78| **SVG** | Icons, logos | Scalable; use `<title>` for inline SVG alt |
79| **GIF** | Simple animation | First frame only for preview |
80 
81### Responsive Images
82 
83Use `<picture>` or `srcset` for different screen sizes. **Always provide fallback `src`**—some crawlers don't understand srcset.
84 
85```html
86<img
87 srcset="image-320w.jpg 320w, image-480w.jpg 480w, image-800w.jpg 800w"
88 sizes="(max-width: 320px) 280px, (max-width: 480px) 440px, 800px"
89 src="image-800w.jpg"
90 alt="Descriptive alt text">
91```
92 
93**Picture element** (format fallback, e.g. WebP → PNG):
94 
95```html
96<picture>
97 <source type="image/webp" srcset="image.webp">
98 <img src="image.png" alt="Descriptive alt text">
99</picture>
100```
101 
102### Data URI (Inline Images)
103 
104Base64 data URIs (`data:image/...;base64,...`) reduce HTTP requests but increase HTML size. Use sparingly for small icons; avoid for large images. See [web.dev](https://web.dev/articles/embedding-images-and-video#data_uris).
105 
106### Resize & Compress
107 
108- **Max width**: Generally ≤2,500px; match container max-width
109- **Compression**: WebP preferred; quality 75–85 for lossy; 72dpi for web
110- **LCP**: Hero/above-fold images are LCP candidates; optimize aggressively
111 
112### Lazy Loading
113 
114Use `loading="lazy"` **only for below-fold images**. Above-fold images (hero) must load immediately—lazy loading them hurts LCP.
115 
116```html
117<img src="hero.jpg" alt="..." loading="eager">
118<img src="below-fold.jpg" alt="..." loading="lazy">
119```
120 
121---
122 
123## 3. Alt Text
124 
125Alt text improves **accessibility** (screen readers, low bandwidth) and **SEO** (Google uses it with computer vision to understand images). It also serves as anchor text if the image is a link.
126 
127### Best Practices
128 
129| Do | Don't |
130|----|-------|
131| Useful, information-rich description | Keyword stuffing |
132| Context of page content | "image of" or "photo of" (redundant) |
133| Max ~125 characters (some assistive tech truncates) | Empty alt on meaningful images |
134| Descriptive for functional images | Alt on purely decorative images (use `alt=""`) |
135 
136**Examples** (from Google):
137 
138- ❌ Missing: `<img src="puppy.jpg"/>`
139- ❌ Stuffing: `alt="puppy dog baby dog pup pups puppies..."`
140- ✅ Better: `alt="puppy"`
141- ✅ Best: `alt="Dalmatian puppy playing fetch"`
142 
143### Captions
144 
145Google extracts image context from captions and nearby text. Use `<figcaption>` or descriptive text near the image.
146 
147| Use | Purpose |
148|-----|---------|
149| **Topic relevance** | Caption describes image subject; supports indexing |
150| **Featured Snippets** | Images near answers with captions can capture thumbnail slots; see **featured-snippet** |
151| **Image Pack** | Alt + caption + file name help Image Pack display; see **serp-features** |
152 
153### Inline SVG
154 
155Use `<title>` inside SVG for accessibility:
156 
157```html
158<svg aria-labelledby="svgtitle1">
159 <title id="svgtitle1">Descriptive text for the SVG</title>
160</svg>
161```
162 
163---
164 
165## 4. File Names
166 
167Descriptive filenames give Google light clues about subject matter.
168 
169| Do | Don't |
170|----|-------|
171| `apple-iphone-15-pink-side-view.jpg` | `IMG00353.jpg` |
172| Short, hyphen-separated | Generic: `image1.jpg`, `pic.gif` |
173| Localize filenames for translated pages | Overly long filenames |
174 
175---
176 
177## 5. Preferred Image (SERP Thumbnail & Discover)
178 
179When users search for keywords, optimized images can appear as **thumbnails next to the page title and description** in search results—enhancing visibility and CTR. Google also uses these images for Google Discover. [Search Engine Land](https://searchengineland.com/google-uses-both-schema-org-markup-and-ogimage-meta-tag-for-thumbnails-in-google-search-and-discover-470598)
180 
181Google selects thumbnails automatically from multiple sources. Influence selection via:
182 
183### Schema: primaryImageOfPage
184 
185```json
186{
187 "@context": "https://schema.org",
188 "@type": "WebPage",
189 "url": "https://example.com/page",
190 "primaryImageOfPage": "https://example.com/images/cat.png"
191}
192```
193 
194Or attach `image` to main entity (e.g. BlogPosting, Article) via `mainEntity` or `mainEntityOfPage`.
195 
196### Open Graph
197 
198```html
199<meta property="og:image" content="https://example.com/images/cat.png">
200```
201 
202**Preferred image rules**: Relevant, representative; avoid generic (e.g. logo) or text-heavy images; avoid extreme aspect ratios; high resolution. See **open-graph**, **twitter-cards** for social specs.
203 
204**Google Discover** (if targeting Discover): ≥1200px wide; ≥300KB; 16:9 aspect ratio preferred; important content visible in landscape crop.
205 
206---
207 
208## 6. Page Context
209 
210- **Title & meta description**: Google uses page title and meta for image result snippets. See **title-tag**, **meta-description**.
211- **Placement**: Put images near relevant text; page subject matter influences image indexing.
212- **Same URL**: Reference the same image with the same URL across pages for cache efficiency and crawl budget.
213 
214---
215 
216## 7. Structured Data
217 
218Add structured data for rich results in Google Images (badges, extra info). Image attribute is required for eligibility. See **schema-markup** for ImageObject, Article, Product, Recipe, etc.
219 
220---
221 
222## 8. Specs by Context
223 
224| Context | Priority | Notes |
225|---------|----------|-------|
226| **Hero** | LCP, alt, no lazy | See **hero-generator**; above-fold, fast load |
227| **Article / Blog hero** | 1200–1600px wide; proportional height; 1200×630 for og:image | Same image for Schema, Open Graph, Twitter Cards; under 200 KB; WebP preferred; descriptive alt; set width/height to prevent CLS; use srcset/sizes for responsive; articles with relevant images get ~94% more views |
228| **Trust badges** | Alt text | See **trust-badges-generator**; e.g. "Norton Secured" |
229| **Landing page** | All above | See **landing-page-generator** Pre-Delivery Checklist |
230| **OG / Twitter** | 1200×630, 1200×675 | See **open-graph**, **twitter-cards** |
231| **Platforms** | Per-platform | X, LinkedIn, Pinterest—see platform skills |
232 
233---
234 
235## 9. Opt-Out & SafeSearch
236 
237- **Inline linking opt-out**: Prevent full-sized image display in Google Images via HTTP referrer check (200 or 204). See [Google docs](https://developers.google.com/search/docs/appearance/google-images#opt-out).
238- **SafeSearch**: Label pages for explicit content if applicable.
239 
240---
241 
242## Output Format
243 
244- **Alt text** suggestions per image
245- **Captions** (if applicable; snippet/Image Pack context)
246- **File name** recommendations
247- **Format** (WebP, fallback)
248- **Responsive** (srcset/sizes or picture)
249- **Lazy loading** (above-fold vs below-fold)
250- **Image sitemap** (if many images)
251- **Preferred image** (schema, og:image) for key pages
252 
253## Related Skills
254 
255- **core-web-vitals**: LCP, INP, CLS; image optimization supports LCP
256- **xml-sitemap**: Sitemap structure; image sitemap extension
257- **open-graph, twitter-cards**: og:image, twitter:image; social preview
258- **schema-markup**: ImageObject, Article/Product image
259- **content-optimization**: Multimedia in content; defers image SEO to this skill
260- **featured-snippet**: Images near answers + captions; snippet thumbnail
261- **serp-features**: Image Pack; alt, captions, file names
262- **visual-content**: Visual content for social, infographics; website images use this skill
263 

Discussion

Alternatives

Agentic Browsing ReadinessAudit and fix agent readiness: the Lighthouse Agentic Browsing fraction, accessibility tree for agents, robots.txt and Content-Signal for AI agents, WAF treatment of agent traffic, llms.txt, Markdown delivery, ai-catalog.json, /.well-known discovery files, and WebMCP tools. Exclude AI citability and brand signals (seo-geo) and commerce protocol depth (seo-ecommerce).Marketing · MITBacklink Profile AnalysisBacklink profile analysis: referring domains, anchor text distribution, toxic link detection, competitor gap analysis. Works with free APIs (Moz, Bing Webmaster, Common Crawl) and DataForSEO extension. Use when user says backlinks, link profile, referring domains, anchor text, toxic links, link gap, link building, disavow, or backlink audit.Marketing · MIT/setup-cmsConnect a CMS to notfair SEO tools. Guides users through configuring WordPress, Strapi, Contentful, or Ghost — tests the connection, and writes credentials to .env.local. Once set up, seo-analysis automatically cross- references CMS content against Google Search Console data. Use whenever the user says "connect my CMS", "set up WordPress", "configure Strapi", "add Contentful", "connect Ghost", or "CMS setup". Also trigger if the user asks why no CMS data appears in a seo-analysis report. · MITBacklink checkBacklink profile for any domain — referring domains, authority, anchors, new/lost links, and a side-by-side vs a competitor. Use when asked "check my backlinks", "backlink profile of X", "who links to them", or "link gap vs competitor".Marketing · MIT