Image Srcset Parser
Parse srcset candidates with positive width or density descriptors, rejecting mixed descriptor types and preserving commas within URL tokens.
Description
Srcset lists image candidates with width or pixel-density descriptors.
Srcset lists image candidates with width or pixel-density descriptors. Width and density are alternative candidate models, and commas may also occur within URL tokens.1
Parse srcset candidates with positive width or density descriptors, rejecting mixed descriptor types and preserving commas within URL tokens.
When to use Image Srcset Parser
Use this tool to parse srcset candidates with positive width or density descriptors, rejecting mixed descriptor types and preserving commas within URL tokens.
Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.
How to use Image Srcset Parser and understand its results
- Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.
- Enter srcset using the field table and calculation rules, then run the tool.
- Read candidates. The explanation below defines the units, signs, ordering and any flags or placeholder values.
- If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
| Input field | Meaning | Value type; see rules below | Requirement |
|---|---|---|---|
| srcset | Image srcset attribute value. | string; maximum length: 1000000 | Required |
Paste an attribute value. Read each URL token and its descriptor, retaining interior URL commas and stripping delimiter commas at a token's end. Accept one positive safe-integer w or positive finite x descriptor per candidate. Omitted descriptors mean 1x. Reject mixed kinds, duplicate numeric descriptor values and unsupported syntax; return ordered candidate records.
candidate=(URL token, optional descriptor); omitted descriptor implies density 1 Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.
| Output field | Meaning | Value type |
|---|---|---|
| candidates | Image candidates in source order. | list of object; minimum entries: 0; maximum entries: 100000 |
{
"input": {
"srcset": "small.png 1x, large.png 2x"
},
"output": {
"candidates": [
{
"url": "small.png",
"descriptor": "1x",
"kind": "density",
"value": 1
},
{
"url": "large.png",
"descriptor": "2x",
"kind": "density",
"value": 2
}
]
}
} Limitations and assumptions
This parser intentionally rejects malformed candidates instead of reproducing every browser recovery rule. It does not resolve URLs, evaluate sizes or choose/fetch an image; empty input gives an empty list.
Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.
Alternative or Complementary methods
Use URL Pathname: Extract the pathname of an absolute URL using the WHATWG URL parser, including its normalization rules. For a complementary task, use LinkPreloadDetector: Extract preload link hints from HTML source without fetching, validating browser support, or resolving their hrefs.
References
-
Image Srcset Parser — tool.io
Similar or alternative tools
- URL Pathname
Extract the pathname of an absolute URL using the WHATWG URL parser, including its normalization rules.
- LinkPreloadDetector
Extract preload link hints from HTML source without fetching, validating browser support, or resolving their hrefs.