Density is a fundamental physical property of a substance that describes how much mass is contained in a given volume. It is defined by the formula:
Density (ρ) = Mass (m) / Volume (V)
The Greek letter ρ (rho) is commonly used to represent density.
Why is Density Important?
Density helps us understand various phenomena:
Material Identification: Different substances have different densities, allowing us to identify them. For example, gold is denser than aluminum.
Buoyancy: An object will float in a fluid if its density is less than the fluid's density, and sink if it's denser. This is why a ship made of steel (which is denser than water) can float – its overall average density, including the air inside, is less than water.
Engineering and Design: Engineers use density to determine the weight of materials for structures, vehicles, and other applications, ensuring they meet strength and performance requirements.
Everyday Observations: From why some objects sink while others float, to understanding the "heft" of a material, density plays a role.
Units of Measurement
Density can be expressed in various units depending on the context and the units of mass and volume used. Common units include:
Kilograms per cubic meter (kg/m³) – The SI unit, often used in scientific and engineering contexts.
Grams per cubic centimeter (g/cm³) – Frequently used for solids.
Grams per milliliter (g/mL) – Commonly used for liquids, as 1 mL is equivalent to 1 cm³.
Pounds per cubic foot (lb/ft³) – Used in some imperial systems.
Our calculator allows you to input mass and volume in various common units and will output the density in grams per cubic centimeter (g/cm³) and kilograms per cubic meter (kg/m³), the two most prevalent units.
How the Calculator Works:
The calculator first converts your inputted mass and volume to a standard set of units (grams for mass, cubic centimeters for volume). Then, it applies the density formula (Mass / Volume) to compute the density in g/cm³. Finally, it converts this result to kg/m³ for a comprehensive answer.
Example:
Let's say you have a block of metal with a mass of 787.4 grams and a volume of 100 cubic centimeters.
Mass = 787.4 g
Volume = 100 cm³
Density = 787.4 g / 100 cm³ = 7.874 g/cm³
This density (7.874 g/cm³) is characteristic of iron. The calculator will also convert this to approximately 7874 kg/m³.
function calculateDensity() {
var massInput = document.getElementById("mass");
var volumeInput = document.getElementById("volume");
var massUnitSelect = document.getElementById("massUnit");
var volumeUnitSelect = document.getElementById("volumeUnit");
var resultDiv = document.getElementById("result");
var mass = parseFloat(massInput.value);
var volume = parseFloat(volumeInput.value);
var massUnit = massUnitSelect.value;
var volumeUnit = volumeUnitSelect.value;
// — Unit Conversion Factors to base units (grams and cm^3) —
var massToBaseGrams = {
'g': 1,
'kg': 1000,
'lb': 453.592,
'oz': 28.3495
};
var volumeToBaseCm3 = {
'cm3': 1,
'm3': 1000000, // 1 m = 100 cm, so 1 m^3 = (100 cm)^3 = 1,000,000 cm^3
'ml': 1, // 1 ml = 1 cm^3
'l': 1000, // 1 L = 1000 ml = 1000 cm^3
'in3': 16.3871, // 1 inch = 2.54 cm, so 1 in^3 = (2.54 cm)^3 approx 16.3871 cm^3
'ft3': 28316.8 // 1 ft = 30.48 cm, so 1 ft^3 = (30.48 cm)^3 approx 28316.8 cm^3
};
// — Input Validation —
if (isNaN(mass) || isNaN(volume) || mass <= 0 || volume <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for mass and volume.";
return;
}
// — Convert inputs to base units —
var massInGrams = mass * massToBaseGrams[massUnit];
var volumeInCm3 = volume * volumeToBaseCm3[volumeUnit];
// — Calculate density in g/cm³ —
var densityGramsPerCm3 = massInGrams / volumeInCm3;
// — Convert density to kg/m³ —
// 1 g/cm³ = 1000 kg/m³
var densityKgPerM3 = densityGramsPerCm3 * 1000;
// — Display Results —
resultDiv.innerHTML = "Density: " + densityGramsPerCm3.toFixed(4) + " g/cm³" +
"Density: " + densityKgPerM3.toFixed(2) + " kg/m³";
}