TL;DR
xkcd provides a simple JSON API for every comic strip published since 2006. Get the current comic, any specific comic by number, or the latest 10 comics. Each response includes the comic title, image URL, alt text (mouseover text), transcript, and publication date. No API key, no rate limits — just plain JSON from Randall Munroe's servers.
Quick start: https://xkcd.com/info.0.json
No API key needed — free and open comics!
How to Use This API
1. Get the Current Comic
Always returns the most recently published xkcd strip:
https://xkcd.com/info.0.json
2. Get a Specific Comic by Number
Replace 0 with the comic number (e.g., comic 936 — "Password Strength"):
https://xkcd.com/936/info.0.json
3. JavaScript — Get Comic and Alt Text
fetch('https://xkcd.com/info.0.json')
.then(r => r.json())
.then(comic => {
console.log(`#${comic.num}: ${comic.title}`);
console.log(`Published: ${comic.month}/${comic.day}/${comic.year}`);
console.log(`Alt text: ${comic.alt}`);
console.log(`URL: ${comic.img}`);
});
4. Python — Fetch Random Comic
import requests, random
latest = requests.get('https://xkcd.com/info.0.json').json()
max_num = latest['num']
rand_num = random.randint(1, max_num)
comic = requests.get(f'https://xkcd.com/{rand_num}/info.0.json').json()
print(f"#{comic['num']}: {comic['title']}")
print(comic['alt'])
print(f"Image: {comic['img']}")
5. Get an Explanation (Explain xkcd)
For context on any comic, use the explain xkcd wiki (not official but community-run):
https://www.explainxkcd.com/wiki/index.php/{comic_num}
https://xkcd.com/info.0.json
Frequently Asked Questions
- What data fields are in the response?
- Each comic returns
num,title,img(image URL),alt(hover/alt text),transcript,day,month,year,safe_title, andlink(if the image links elsewhere). - How do I get all comics?
- Fetch the latest comic to get
num(latest number), then iterate from 1 to that number. There are currently over 3000 comics. Be respectful with request frequency. - Are images included in the response or just URLs?
- The API returns the image URL (
imgfield). Images are served fromimgs.xkcd.comin 2x PNG format. You must fetch images separately from the JSON. - Is there a rate limit?
- No official rate limit, but please be reasonable. For bulk downloads, spread requests over time rather than hammering the server.
- Are old comics available?
- Yes — all xkcd comics are available via the API. Comic #1 (drawn in 2006) through the latest. Some very early comics may have different styling.
- Can I use xkcd comics in my app?
- xkcd comics are licensed under Creative Commons BY-NC 2.5. You can share and adapt them for non-commercial use with attribution to Randall Munroe.
API Details
- API URL
https://xkcd.com/info.0.json- Documentation
- xkcd.com/json.html
- Category
- Fun
- Authentication
- Not Required
- Rate Limit
- None documented — be respectful
What You Can Build
- Daily comic viewer widget for desktop or mobile home screens
- xkcd search engine — search alt text and titles by keyword
- Random comic generator with shareable links
- Comic archive browser with thumbnail gallery by year
- Terminal-based comic viewer using alt text as captions