Missing devicon variant class renders no icon without error
0 reputation · 17 Jun 2020, 00:35 UTC
0 reputation · 17 Jun 2020, 00:35 UTC
Applying a devicon CSS class to an element should display the corresponding icon, but when the class names a variant that the selected icon does not ship, the element stays empty and no error is raised. Because devicon is a static CSS, font, and SVG package with no migration or schema layer, variant availability depends entirely on the installed release and can change between upgrades.
The goal is to confirm which variant class names exist for a specific icon ID before using them in markup, without relying on visual inspection alone. Relevant constraints include silent rendering failure, the absence of built-in validation, and potential differences between font and SVG variants.
What variant class names does devicon.css define for a given icon ID? Does the library emit a console warning or fallback when an undefined variant class is applied? What programmatic check confirms supported variants before deploying markup?
37775 reputation · 17 Jun 2020, 02:04 UTC
Devicon does not warn or fall back when you apply an undefined variant class. The element simply stays empty. The variant class names that work for a given icon ID are exactly the devicon-{icon}-{variant} rules present in the devicon.css build you have installed; plain, wordmark, and colored are common, but not every icon ships all three, and the set can change between releases.
Devicon is static CSS with no JavaScript registry. When a variant rule is missing, the browser has no background image, glyph, or SVG to paint, and nothing in the library throws or logs a warning.
react and wordmark.devicon.css (or the SVG build if you are using SVG icons).devicon-{icon}-{variant} for that icon.Mount a temporary element with the candidate class and read its computed style. If background-image is none or empty, the variant is unsupported by the loaded stylesheet.
function deviconVariantExists(icon, variant) {
const el = document.createElement('div');
el.className = `devicon-${icon}-${variant}`;
document.body.appendChild(el);
const style = window.getComputedStyle(el);
const present = style.backgroundImage !== 'none' && style.backgroundImage !== '';
document.body.removeChild(el);
return present;
}
console.log(deviconVariantExists('react', 'wordmark'));
This check confirms only the CSS build currently loaded. Repeat it for the SVG build if you switch delivery methods.
Are you loading the font build, the SVG build, or both? This changes which variant names exist and which stylesheet you should inspect.
Assumption: devicon.css is loaded on the page. Exact variant names must be confirmed against your installed release; the names above are common examples, not a guaranteed list.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.