Badge
The /badge endpoint draws a standalone SVG badge, a pill with a label, optional icons and an optional second part, for a plain <img>.
curl -X GET \ "https://api.moxon.dev/v6/badge"Send the request to see the response here.
Only label is required. Every other parameter changes one aspect of the badge, and a badge without any of them is a dark pill with white bold text.
- —
labelstringrequiredText of the badge, up to
64characters - —
iconstringoptionalName of an icon drawn before the label
- sparkles
- github
- star
- rocket
- check
- +101 more
- —
trailstringoptionalName of an icon drawn after the text, after the message when there is one
- arrow-right
- chevron-right
- check
- +103 more
- —
messagestringoptionalText of a second part, drawn after the label on its own background, up to
64characters
A label or a message cannot hold control characters or invisible ones, and needs at least one character that draws something (see the box below). Runs of spaces count as one, and an accented letter sent as a letter followed by its accent is drawn like the single accented letter.
Characters that are refused
A label or a message with one of these characters is refused with a 400:
- Control characters, line and paragraph separators, and lone surrogates.
- Format characters that draw nothing: the soft hyphen, the zero-width space, the word joiner, the bidirectional marks and the tag characters.
- Invisible fillers: the Hangul fillers, the blank Braille pattern and the combining grapheme joiner.
- The noncharacters
U+FFFEandU+FFFF.
A text made only of spaces is refused as a missing text, and one made only of combining marks or variation selectors is refused like the characters above, as it draws nothing.
Still accepted: an emoji or a symbol followed by its variation selector (U+FE0E and U+FE0F, as in the red heart), accented letters, and no-break or ideographic spaces around a visible text.
startstringoptionalDefault:
#2d333b.Background color, or the first color of its gradient
endstringoptionalDefault:
start.Last color of the gradient. Without it, the background is a single color
inkstringoptionalDefault:
#ffffff.Color of the text and of the icons, except the trailing icon when there is a
messagemessageStartstringoptionalDefault:
#0969da.Background color of the second part, or the first color of its gradient
messageEndstringoptionalDefault:
messageStart.Last color of the gradient of the second part
messageInkstringoptionalDefault:
ink.Color of the text of the second part and, with a
message, of the trailing icon. Ignored without amessage- —
borderstringoptionalColor of a
1px outline. Without it, the badge has no outline
A color is a hexadecimal value of 3 or 6 digits, with or without the #. In a URL, write the # as %23, or leave it out. The colors of the second part are checked even without a message.
sizestringoptionalDefault:
sm.xs,sm,mdorlg: a badge16,20,24or28px high. The icons and the text follow- xs
- sm
- md
- lg
radiusnumberoptionalDefault:
pill.Corner radius in pixels, from
0(square) to100. A radius larger than half the height gives the pill, which is also the defaultanglenumberoptionalDefault:
135.Direction of the gradients in degrees, from
0to360, in the CSS convention:90runs from left to right and180from top to bottom. The default runs from corner to corner. The value is rounded to the nearest whole degreeliftnumberoptionalDefault:
0.From
0to10: the image grows by twice this value in height, which leaves that much free space under the badge, and the badge stays at the topfont"sans" | "serif" | "mono"optionalDefault:
sans.sans,seriformonoweight"normal" | "bold"optionalDefault:
bold.normalorbold
Good to know
radius, angle and lift take a plain decimal of up to three digits and two decimals (4, 12.5): a sign, an exponent or an empty value is refused. An empty size, font or weight is refused too, whereas an empty color, icon, border or message is ignored.
The width of the badge is measured on the server, so it is the same wherever it is shown. The text is drawn in the first font of its family that the viewer has installed (Verdana for sans, Georgia for serif, Menlo for mono), and it is stretched to the measured width, so a different font only changes the spacing between the letters.
icon and trail take the name of one of the 106 icons bundled with the API: 105 icons of Lucide and discord. Any other name is refused. The icons are drawn in the ink color, in the size of the badge, and the trailing one in messageInk when there is a message.
Click to expand all available icons
- Arrows and actions:
- arrow-down
- arrow-left
- arrow-right
- arrow-up
- check
- chevron-right
- download
- external-link
- minus
- plus
- refresh-cw
- upload
- x
- Status and distinctions:
- award
- badge-check
- bell
- bug
- circle-alert
- circle-check
- circle-dot
- circle-x
- construction
- flag
- flame
- heart
- info
- shield
- shield-check
- sparkles
- star
- thumbs-up
- triangle-alert
- trophy
- zap
- Everyday objects and media:
- calendar
- clock
- cloud
- coffee
- eye
- gift
- globe
- hourglass
- house
- image
- message-circle
- monitor
- moon
- music
- palette
- pause
- pencil
- play
- rocket
- smartphone
- sun
- timer
- trash-2
- user
- users
- video
- wifi
- Brands:
- chrome
- codepen
- discord
- dribbble
- figma
- framer
- github
- gitlab
- slack
- trello
- twitch
- youtube
The icons of Lucide are published under the ISC licence, and the ones it derives from Feather under the MIT licence: both licences are kept in the source code of the API.
With a message, the badge is split in two like the ones of shields.io: the label on the first background, the message on a second one, which has its own colors (messageStart, messageEnd and messageInk). The border and the radius go around the whole badge, and trail is drawn at the very end.
<img src="https://api.moxon.dev/v6/badge?label=build&message=passing&messageStart=16a34a&icon=circle-check" alt="build: passing" />The response is a standalone SVG (Content-Type: image/svg+xml), sized to its content, with no script and no external file. It is usable in an <img> tag, as a CSS background or in a Markdown image:
<img src="https://api.moxon.dev/v6/badge?label=New&icon=sparkles&start=7c3aed&end=db2777" alt="New" />The image only depends on the query string, so it is sent with Cache-Control: public, max-age=86400 (one day) and an ETag, and with Content-Security-Policy: default-src 'none'.
The badge function takes the same options as the query string, with lift, radius and angle as numbers, and returns { contentType, body }, body being the SVG. It throws an Error with a message of the table below when an option is invalid. Outside HTTP, a number is only checked for its range and rounded to two decimals. It is exported by @moxon/api/v6 and by the package root, which resolves to the latest version, see the npm package.
import { badge } from '@moxon/api/v6';
const { contentType, body } = badge({
label: 'New',
icon: 'sparkles',
start: '#7c3aed',
end: '#db2777',
lift: 2,
});
console.log(contentType); // 'image/svg+xml'
console.log(body); // '<svg xmlns="http://www.w3.org/2000/svg" ...'Every invalid value is refused with a 400 and a message that names it, instead of being replaced by a default.
- 400
Please provide a label (?label={text})Thelabelis missing or empty, holds only spaces, or is given more than once - 400
Label cannot exceed 64 charactersThelabelis longer than64characters. The same message exists for themessage, asMessage cannot exceed 64 characters - 400
Label cannot contain control or invisible charactersThelabelholds a control or invisible character, or nothing but combining marks or variation selectors (see the characters that are refused). The same message exists for themessage, asMessage cannot contain control or invisible characters - 400
Please provide a valid messageThemessageholds only spaces or is given more than once. An emptymessageis ignored - 400
Unknown icon "nope"Theiconis not one of the icons. The name is repeated in the message, cut at40characters - 400
Unknown trail icon "nope"Thetrailis not one of the icons - 400
Please provide a valid icon nameTheiconis given more than once. The same message exists for thetrail, asPlease provide a valid trail icon name - 400
Invalid start color (use hex like ff6600)Thestartis not a hexadecimal color. The same message exists forend,ink,messageStart,messageEnd,messageInkandborder, with the name of the parameter - 400
Please provide a valid start colorA color is given more than once. The same message exists for the other colors, with the name of the parameter - 400
Invalid size (use xs, sm, md or lg)Thesizeis not one of the four sizes - 400
Invalid font (use sans, serif or mono)Thefontis not one of the three fonts - 400
Invalid weight (use normal or bold)Theweightis neithernormalnorbold - 400
Invalid lift (use a number from 0 to 10)Theliftis out of range, not a plain decimal or has more than two decimals - 400
Invalid radius (use a number from 0 to 100)Theradiusis out of range, not a plain decimal or has more than two decimals - 400
Invalid angle (use a number from 0 to 360)Theangleis out of range, not a plain decimal or has more than two decimals
- getPlaceholder - SVG placeholders and skeleton loaders
- getAvatar Generation - Avatars generated from a seed
- postChart - SVG charts from data arrays
Last updated on November 17, 2026