Enter atomic masses for each element (e.g., H: 1.008, O: 15.999). If left blank, common values will be used.
How to Calculate Molar Mass
Molar mass is a fundamental property of a chemical substance. It represents the mass of one mole of that substance and is typically expressed in grams per mole (g/mol). Calculating molar mass is essential in stoichiometry, allowing chemists to convert between mass and moles, predict reaction yields, and understand the composition of compounds.
The Formula
The molar mass of a compound is calculated by summing the atomic masses of all the atoms present in its chemical formula. The atomic mass of an element is found on the periodic table, usually displayed below the element's symbol.
Molar Mass of Compound = Σ (Number of atoms of element × Atomic mass of element)
Steps to Calculate Molar Mass:
Identify the Chemical Formula: Determine the correct chemical formula for the substance (e.g., Water is H₂O, Glucose is C₆H₁₂O₆).
Count the Atoms of Each Element: Note the number of atoms for each element in the formula. Subscripts indicate the number of atoms. If there is no subscript, it means there is only one atom of that element. For example, in C₆H₁₂O₆, there are 6 Carbon atoms, 12 Hydrogen atoms, and 6 Oxygen atoms.
Find Atomic Masses: Look up the atomic mass for each element from the periodic table. These are typically given in atomic mass units (amu), but for molar mass, we use the same numerical value in grams per mole (g/mol).
Multiply and Sum: For each element, multiply the number of atoms by its atomic mass. Then, add up these values for all elements in the compound to get the total molar mass.
Example Calculation: Water (H₂O)
Chemical Formula: H₂O
Atoms: 2 Hydrogen (H) atoms, 1 Oxygen (O) atom
Atomic Masses (approximate): H = 1.008 g/mol, O = 15.999 g/mol
This calculator helps automate this process. You input the chemical formula, and it will calculate the molar mass. You can also provide specific atomic masses if needed, which is useful for isotopes or when using more precise values than those commonly found on a standard periodic table.
// Default atomic masses for common elements
var defaultAtomicMasses = {
"H": 1.008, "He": 4.003, "Li": 6.941, "Be": 9.012, "B": 10.811, "C": 12.011,
"N": 14.007, "O": 15.999, "F": 18.998, "Ne": 20.180, "Na": 22.990, "Mg": 24.305,
"Al": 26.982, "Si": 28.086, "P": 30.974, "S": 32.065, "Cl": 35.453, "Ar": 39.948,
"K": 39.098, "Ca": 40.078, "Sc": 44.956, "Ti": 47.867, "V": 50.942, "Cr": 51.996,
"Mn": 54.938, "Fe": 55.845, "Co": 58.933, "Ni": 58.693, "Cu": 63.546, "Zn": 65.38,
"Ga": 69.723, "Ge": 72.630, "As": 74.922, "Se": 78.971, "Br": 79.904, "Kr": 83.798,
"Rb": 85.468, "Sr": 87.62, "Y": 88.906, "Zr": 91.224, "Nb": 92.906, "Mo": 95.95,
"Tc": 98.0, "Ru": 101.07, "Rh": 102.906, "Pd": 106.42, "Ag": 107.868, "Cd": 112.411,
"In": 114.818, "Sn": 118.710, "Sb": 121.760, "Te": 127.60, "I": 126.904, "Xe": 131.294,
"Cs": 132.905, "Ba": 137.327, "La": 138.905, "Ce": 140.116, "Pr": 140.908, "Nd": 144.242,
"Pm": 145.0, "Sm": 150.36, "Eu": 151.964, "Gd": 157.25, "Tb": 158.925, "Dy": 162.500,
"Ho": 164.930, "Er": 167.259, "Tm": 168.934, "Yb": 173.054, "Lu": 174.966, "Hf": 178.49,
"Ta": 180.948, "W": 183.84, "Re": 186.207, "Os": 190.23, "Ir": 192.217, "Pt": 195.084,
"Au": 196.967, "Hg": 200.590, "Tl": 204.383, "Pb": 207.2, "Bi": 208.980, "Po": 209.0,
"At": 210.0, "Rn": 222.0, "Fr": 223.0, "Ra": 226.0, "Ac": 227.0, "Th": 232.038,
"Pa": 231.036, "U": 238.029, "Np": 237.0, "Pu": 244.0, "Am": 243.0, "Cm": 247.0,
"Bk": 247.0, "Cf": 251.0, "Es": 252.0, "Fm": 257.0, "Md": 258.0, "No": 259.0,
"Lr": 266.0, "Rf": 267.0, "Db": 268.0, "Sg": 269.0, "Bh": 270.0, "Hs": 269.0,
"Mt": 278.0, "Ds": 281.0, "Rg": 281.0, "Cn": 285.0, "Nh": 286.0, "Fl": 289.0,
"Mc": 290.0, "Lv": 293.0, "Ts": 294.0, "Og": 294.0
};
function parseChemicalFormula(formula) {
var elements = {};
// Regex to find elements and their counts. Handles elements with one or two letters,
// followed by an optional number (defaulting to 1).
var regex = /([A-Z][a-z]*)(\d*)/g;
var match;
while ((match = regex.exec(formula)) !== null) {
var elementName = match[1];
var countStr = match[2];
var count = countStr === " ? 1 : parseInt(countStr, 10);
if (isNaN(count)) {
console.error("Invalid count parsed for element:", elementName, countStr);
return null; // Indicate parsing error
}
if (elements.hasOwnProperty(elementName)) {
elements[elementName] += count;
} else {
elements[elementName] = count;
}
}
return elements;
}
function calculateMolarMass() {
var formulaInput = document.getElementById("chemicalFormula");
var formula = formulaInput.value.trim();
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (!formula) {
resultDiv.innerHTML = "Please enter a chemical formula.";
return;
}
var parsedElements = parseChemicalFormula(formula);
if (parsedElements === null) {
resultDiv.innerHTML = "Invalid chemical formula format.";
return;
}
var totalMolarMass = 0;
var calculationDetails = "Molar Mass Calculation for " + formula + ":";
var hasErrors = false;
for (var element in parsedElements) {
if (parsedElements.hasOwnProperty(element)) {
var count = parsedElements[element];
var atomicMass = defaultAtomicMasses[element];
if (atomicMass === undefined) {
// Check if user provided custom mass (not implemented in UI, but good to have logic)
// For now, we assume it's an unknown element.
calculationDetails += " – " + element + ": Atomic mass not found. Please provide it.";
hasErrors = true;
} else {
var elementMolarMass = count * atomicMass;
totalMolarMass += elementMolarMass;
calculationDetails += " – " + element + " (" + count + " atoms) x " + atomicMass + " g/mol = " + elementMolarMass.toFixed(3) + " g/mol";
}
}
}
if (hasErrors) {
resultDiv.innerHTML = "Could not calculate. Please check elements and their masses." + calculationDetails;
} else if (totalMolarMass === 0 && Object.keys(parsedElements).length > 0) {
// This case might happen if formula is valid but all elements are unknown
resultDiv.innerHTML = "Could not calculate. Unknown elements or masses provided.";
}
else {
resultDiv.innerHTML = "Molar Mass: " + totalMolarMass.toFixed(3) + " g/mol" +
"(Sum of atomic masses)";
}
}