Enter symbols with correct capitalization (e.g., use 'Cl' for Chlorine, not 'cl').
Calculated Results:
0.00g/mol
Understanding Molar Mass and Molecular Weight
Molar mass is a fundamental physical property defined as the mass of a given substance divided by the amount of that substance, typically measured in moles (g/mol). In chemistry, this allows scientists to bridge the gap between the microscopic world of atoms and molecules and the macroscopic world we can measure in a laboratory.
How Molar Weight is Calculated
To calculate the molar weight of a chemical compound, you must sum the standard atomic weights of every atom present in the chemical formula. The formula is generally:
Molar Mass = Σ (Atomic Weight of Element × Number of Atoms)
Example Calculations
Compound
Formula
Calculation Logic
Molar Mass
Water
H2O
(2 × 1.008) + (1 × 15.999)
18.015 g/mol
Glucose
C6H12O6
(6 × 12.011) + (12 × 1.008) + (6 × 15.999)
180.156 g/mol
Sodium Chloride
NaCl
(1 × 22.990) + (1 × 35.45)
58.44 g/mol
Why is it important?
In stoichiometry, molar mass is used to convert between mass and moles. This is critical for determining how many reactants are needed to produce a specific amount of product in a chemical reaction. Without accurate molar weight calculations, industrial chemical production and pharmaceutical compounding would be impossible.
function calculateMolarMass() {
var periodicTable = {
"H": 1.008, "He": 4.0026, "Li": 6.94, "Be": 9.0122, "B": 10.81, "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.085, "P": 30.974, "S": 32.06, "Cl": 35.45, "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.63, "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, "Ru": 101.07, "Rh": 102.91, "Pd": 106.42, "Ag": 107.87, "Cd": 112.41, "In": 114.82, "Sn": 118.71,
"Sb": 121.76, "Te": 127.60, "I": 126.90, "Xe": 131.29, "Cs": 132.91, "Ba": 137.33, "La": 138.91, "Ce": 140.12, "Pr": 140.91, "Nd": 144.24,
"W": 183.84, "Pt": 195.08, "Au": 196.97, "Hg": 200.59, "Tl": 204.38, "Pb": 207.2, "Bi": 208.98, "Rn": 222, "U": 238.03
};
var formulaInput = document.getElementById("chemFormula").value.trim();
var sampleMass = parseFloat(document.getElementById("sampleMass").value);
var resultArea = document.getElementById("molarResultArea");
var weightOutput = document.getElementById("molarWeightOutput");
var breakdownOutput = document.getElementById("molarBreakdown");
var molesOutput = document.getElementById("molarMolesResult");
if (!formulaInput) {
alert("Please enter a chemical formula.");
return;
}
// Regex to find Elements (starts with Capital, maybe lowercase) and Numbers
var regex = /([A-Z][a-z]*)(\d*)/g;
var match;
var totalMolarMass = 0;
var breakdownHTML = "Breakdown:";
var foundSomething = false;
while ((match = regex.exec(formulaInput)) !== null) {
var element = match[1];
var count = match[2] === "" ? 1 : parseInt(match[2]);
if (periodicTable[element]) {
var elementMass = periodicTable[element] * count;
totalMolarMass += elementMass;
breakdownHTML += element + ": " + count + " x " + periodicTable[element] + " = " + elementMass.toFixed(3) + " g/mol";
foundSomething = true;
} else {
alert("Element '" + element + "' not recognized or not in our database. Please check capitalization.");
return;
}
}
if (!foundSomething) {
alert("Invalid formula format. Please use standard notation like H2O or CO2.");
return;
}
weightOutput.innerText = totalMolarMass.toFixed(4);
breakdownOutput.innerHTML = breakdownHTML;
if (!isNaN(sampleMass) && sampleMass > 0) {
var moles = sampleMass / totalMolarMass;
molesOutput.innerText = "Moles in " + sampleMass + "g: " + moles.toFixed(5) + " mol";
} else {
molesOutput.innerText = "";
}
resultArea.style.display = "block";
}