Periodic Table Classification
Interactive periodic table for exploring how the elements are classified. Highlight metals, metalloids and nonmetals, the chemical families, or the s, p, d and f blocks.
Choose a classification scheme, then select one or more categories to highlight the elements that belong to them. Selecting nothing shows every element coloured by the current scheme.
An element can belong to more than one scheme at once. Tellurium is a metalloid by type and a chalcogen by family, and both are true; the schemes answer different questions, so each is shown on its own.
mutable ptcDark = document.documentElement.getAttribute('data-bs-theme') === 'dark'
|| document.body.classList.contains('quarto-dark')
ptcThemeObserver = {
const check = () => {
const dark = document.documentElement.getAttribute('data-bs-theme') === 'dark'
|| document.body.classList.contains('quarto-dark');
if (dark !== mutable ptcDark) mutable ptcDark = dark;
};
const obs = new MutationObserver(check);
obs.observe(document.documentElement, {attributes: true, attributeFilter: ['data-bs-theme']});
obs.observe(document.body, {attributes: true, attributeFilter: ['class']});
invalidation.then(() => obs.disconnect());
return true;
}ptcAxes = ({
type: {
label: "Type",
order: ["metal", "metalloid", "nonmetal"],
names: {metal: "Metal", metalloid: "Metalloid", nonmetal: "Nonmetal"}
},
// The family axis is single-valued by a stateable rule, not by accident:
// metals -> name the metal class (transition, post-transition, lanthanide, actinide)
// nonmetals and
// metalloids -> name the group family (alkali, alkaline earth, pnictogen,
// chalcogen, halogen, noble gas)
// neither -> "other" (groups 13 and 14 have no family name: H, B, C, Si, Ge)
// That rule is why Bi and Po read as post-transition while Te, As and Sb keep their
// group families. "other" is NOT "other nonmetal" — three of its five members are
// metalloids, which the Type axis already says.
family: {
label: "Family",
order: ["alkali", "alkaline-earth", "transition", "post-transition", "lanthanide",
"actinide", "pnictogen", "chalcogen", "halogen", "noble-gas", "other"],
names: {
"alkali": "Alkali metal", "alkaline-earth": "Alkaline earth metal",
"transition": "Transition metal", "post-transition": "Post-transition metal",
"lanthanide": "Lanthanide", "actinide": "Actinide", "pnictogen": "Pnictogen",
"chalcogen": "Chalcogen", "halogen": "Halogen", "noble-gas": "Noble gas",
"other": "No named family"
}
},
block: {
label: "Block",
order: ["s", "p", "d", "f"],
names: {s: "s-block", p: "p-block", d: "d-block", f: "f-block"}
}
})ptcWidget = {
const EL = ptcElements;
// ── state ──
let axis = "type";
let picked = new Set();
const root = document.createElement("div");
root.className = "ptc-widget";
// ── toolbar ──
const bar = document.createElement("div");
bar.className = "ptc-toolbar";
const axisGroup = document.createElement("div");
axisGroup.className = "ptc-axis";
// role=group with aria-pressed buttons, NOT radiogroup/radio: a radiogroup promises
// arrow-key navigation and a single tab stop, and claiming that without implementing it
// is worse than not claiming it. Plain toggle buttons behave exactly as they look.
axisGroup.setAttribute("role", "group");
axisGroup.setAttribute("aria-label", "Classification scheme");
const axisBtns = {};
for (const key of ["type", "family", "block"]) {
const b = document.createElement("button");
b.type = "button";
b.className = "ptc-axis-btn";
b.textContent = ptcAxes[key].label;
b.addEventListener("click", () => { axis = key; picked.clear(); render(); });
axisBtns[key] = b;
axisGroup.appendChild(b);
}
const actions = document.createElement("div");
actions.className = "ptc-actions";
const clearBtn = document.createElement("button");
clearBtn.type = "button";
clearBtn.className = "ptc-btn";
clearBtn.textContent = "Show all";
clearBtn.addEventListener("click", () => { picked.clear(); render(); });
const fsBtn = document.createElement("button");
fsBtn.type = "button";
fsBtn.className = "ptc-btn";
fsBtn.textContent = "Fullscreen";
fsBtn.addEventListener("click", toggleFullscreen);
actions.append(clearBtn, fsBtn);
bar.append(axisGroup, actions);
// ── legend: the chips ARE the interface, so no separate control panel is needed ──
const legend = document.createElement("div");
legend.className = "ptc-legend";
// ── table ──
const wrap = document.createElement("div");
wrap.className = "ptc-table-wrap";
wrap.tabIndex = 0; // scrollable region must be keyboard reachable
wrap.setAttribute("role", "group");
wrap.setAttribute("aria-label", "Periodic table");
const grid = document.createElement("div");
grid.className = "ptc-grid";
wrap.appendChild(grid);
// The f-block sits on its own two rows. Column comes from an element's POSITION within
// its series, not from a hardcoded z offset: whether lanthanum and actinium count as
// f-block or as group 3 is a live convention question (IUPAC's 2021 provisional
// recommendation puts Lu and Lr in group 3), and a fixed `z - 57` would open a gap at
// column 3 the moment the series starts at cerium instead.
const fSeries = {early: [], late: []};
for (const e of EL) if (e.block === "f") fSeries[e.z >= 89 ? "late" : "early"].push(e.z);
fSeries.early.sort((a, b) => a - b);
fSeries.late.sort((a, b) => a - b);
const cellOf = {};
for (const e of EL) {
const c = document.createElement("div");
c.className = "ptc-cell";
c.dataset.z = e.z;
let row, col;
if (e.block === "f") {
const late = e.z >= 89;
row = late ? 10 : 9;
col = 3 + fSeries[late ? "late" : "early"].indexOf(e.z);
} else {
row = e.period;
col = e.group;
}
c.style.gridRow = row;
c.style.gridColumn = col;
const sym = document.createElement("span");
sym.className = "ptc-sym";
sym.textContent = e.sym;
const num = document.createElement("span");
num.className = "ptc-z";
num.textContent = e.z;
c.append(num, sym);
grid.appendChild(c);
cellOf[e.z] = c;
}
// ── status ──
// Two parts in one live region. The visible line stays short, because spelling out
// 88 symbols on screen is a wall of text nobody reads. The full member list is still
// announced to a screen reader, where it is the whole point and beats 118 tab stops.
const status = document.createElement("p");
status.className = "ptc-status";
status.setAttribute("role", "status");
status.setAttribute("aria-live", "polite");
const statusText = document.createElement("span");
const statusSr = document.createElement("span");
statusSr.className = "ptc-sr";
status.append(statusText, statusSr);
const note = document.createElement("div");
note.className = "ptc-notes";
root.append(bar, legend, wrap, status, note);
// ── rendering ──
function paint() {
// Read the theme from the DOM rather than from the `ptcDark` cell on purpose: if this
// cell referenced ptcDark, OJS would re-run the whole builder on every theme flip and
// rebuild the widget from scratch, throwing away the user's current selection.
// ptcRepaint below owns the reactive dependency and calls back in here.
const dark = document.documentElement.getAttribute('data-bs-theme') === 'dark'
|| document.body.classList.contains('quarto-dark');
const scheme = ptcPalette[axis][dark ? "dark" : "light"];
// "No named family" is the absence of a family, so it gets a deliberate neutral
// rather than a hue from the optimised palette. That also spends one fewer colour
// out of a budget that is already over what can be told apart.
const NEUTRAL = dark ? "#3a3f52" : "#c9cedb";
const colour = k => scheme[k] || NEUTRAL;
// Per-cell ink. A palette that spans light to dark cannot share one text colour:
// on the Block axis, black clears 20:1 on the s fill but only 1.4:1 on the f fill.
// Pick whichever of black/white has the better ratio against each fill, which is
// never worse than 4.5:1 for any fill in the middle of the range either.
const srgbLin = v => (v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4));
const relLum = hex => {
const h = hex.replace("#", "");
const [r, g, b] = [0, 2, 4].map(i => srgbLin(parseInt(h.substr(i, 2), 16) / 255));
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
};
const inkFor = hex => (relLum(hex) > 0.179 ? "#000000" : "#ffffff");
const active = picked.size > 0;
for (const e of EL) {
const c = cellOf[e.z];
const key = e[axis];
const on = !active || picked.has(key);
const fill = colour(key);
c.style.background = fill;
c.style.color = inkFor(fill);
c.classList.toggle("ptc-on", active && on);
c.classList.toggle("ptc-off", active && !on);
}
for (const chip of legend.querySelectorAll(".ptc-chip")) {
const k = chip.dataset.key;
chip.style.setProperty("--chip", colour(k));
const sel = picked.has(k);
chip.classList.toggle("ptc-chip-on", sel);
chip.setAttribute("aria-pressed", sel ? "true" : "false");
}
}
function render() {
for (const [k, b] of Object.entries(axisBtns)) {
b.classList.toggle("ptc-axis-on", k === axis);
b.setAttribute("aria-pressed", k === axis ? "true" : "false");
}
legend.textContent = "";
const present = new Set(EL.map(e => e[axis]));
for (const key of ptcAxes[axis].order.filter(k => present.has(k))) {
const chip = document.createElement("button");
chip.type = "button";
chip.className = "ptc-chip";
chip.dataset.key = key;
const sw = document.createElement("span");
sw.className = "ptc-swatch";
const lab = document.createElement("span");
lab.textContent = ptcAxes[axis].names[key];
chip.append(sw, lab);
chip.addEventListener("click", () => {
picked.has(key) ? picked.delete(key) : picked.add(key);
paint(); announce();
});
legend.appendChild(chip);
}
paint();
announce();
}
function announce() {
note.textContent = "";
if (picked.size === 0) {
statusText.textContent = "All 118 elements, coloured by "
+ ptcAxes[axis].label.toLowerCase() + ".";
statusSr.textContent = "";
note.hidden = true;
return;
}
const names = [...picked].map(k => ptcAxes[axis].names[k]);
const hits = EL.filter(e => picked.has(e[axis]));
statusText.textContent = names.join(", ") + " — " + hits.length
+ (hits.length === 1 ? " element" : " elements") + " highlighted.";
// Screen-reader only: the members by symbol, which is what makes the widget usable
// without sight but is unreadable as on-screen prose.
statusSr.textContent = " Elements: " + hits.map(e => e.sym).join(", ") + ".";
const notes = hits.filter(e => e.note);
note.hidden = notes.length === 0;
for (const e of notes) {
const card = document.createElement("div");
card.className = "ptc-notecard";
const badge = document.createElement("span");
badge.className = "ptc-badge";
badge.textContent = e.sym;
const txt = document.createElement("span");
txt.textContent = e.note;
card.append(badge, txt);
note.appendChild(card);
}
}
function toggleFullscreen() {
// Fullscreen API keeps the widget's state; a new tab would lose the selection.
// The CSS class is the fallback where the API is unavailable or refused.
if (document.fullscreenElement === root) {
document.exitFullscreen && document.exitFullscreen();
return;
}
if (root.requestFullscreen) {
root.requestFullscreen().catch(() => root.classList.add("ptc-faux-fs"));
} else {
root.classList.toggle("ptc-faux-fs");
}
}
document.addEventListener("fullscreenchange", () => {
const on = document.fullscreenElement === root;
root.classList.toggle("ptc-fs", on);
fsBtn.textContent = on ? "Exit fullscreen" : "Fullscreen";
});
render();
root.ptcPaint = paint; // handle for the theme-reactive cell below
return root;
}