Choose a cooking ingredient when converting between volume and weight. Different ingredients have different densities, so a cup of flour weighs less than a cup of honey.
Converted result
Suggested air fryer settings
This is a general starting estimate: reduce the oven temperature by about 15°C (25°F) and cooking time by approximately 20%. Check food early and ensure it is cooked safely.
Converted oven temperatures
Gas mark values are approximate. Check your recipe for fan-assisted oven adjustments.
Converted butter amount
Approximation based on 1 US cup of butter weighing 227 grams and 1 US stick weighing 113.4 grams.
(function () {
const root = document.getElementById(‘recipe-converter’);
if (!root || root.dataset.initialized === ‘true’) return;
root.dataset.initialized = ‘true’;
const $ = (id) => root.querySelector(‘#’ + id);
let decimals = 2;
let customDensity = null;
let customName = ”;
// Volume factors are in milliliters.
// Weight factors are in grams.
const units = {
cup_us: { name: ‘US cups’, type: ‘volume’, factor: 236.5882365 },
cup_metric: { name: ‘Metric cups’, type: ‘volume’, factor: 250 },
cup_imperial:{ name: ‘Imperial cups’, type: ‘volume’, factor: 284.130625 },
dl: { name: ‘dL’, type: ‘volume’, factor: 100 },
floz_uk: { name: ‘UK fl oz’, type: ‘volume’, factor: 28.4130625 },
floz_us: { name: ‘US fl oz’, type: ‘volume’, factor: 29.5735296 },
gal_uk: { name: ‘UK gallons’, type: ‘volume’, factor: 4546.09 },
gal_us: { name: ‘US gallons’, type: ‘volume’, factor: 3785.411784 },
l: { name: ‘liters’, type: ‘volume’, factor: 1000 },
ml: { name: ‘mL’, type: ‘volume’, factor: 1 },
pint_uk: { name: ‘UK pints’, type: ‘volume’, factor: 568.26125 },
pint_us: { name: ‘US pints’, type: ‘volume’, factor: 473.176473 },
quart_uk: { name: ‘UK quarts’, type: ‘volume’, factor: 1136.5225 },
quart_us: { name: ‘US quarts’, type: ‘volume’, factor: 946.352946 },
tbsp_us: { name: ‘US tablespoons’, type: ‘volume’, factor: 14.7867648 },
tbsp_metric: { name: ‘Metric tablespoons’, type: ‘volume’, factor: 15 },
tbsp_uk: { name: ‘Imperial tablespoons’, type: ‘volume’, factor: 17.7581641 },
tsp_us: { name: ‘US teaspoons’, type: ‘volume’, factor: 4.92892159 },
tsp_metric: { name: ‘Metric teaspoons’, type: ‘volume’, factor: 5 },
tsp_uk: { name: ‘Imperial teaspoons’, type: ‘volume’, factor: 5.91938803 },
mg: { name: ‘mg’, type: ‘weight’, factor: 0.001 },
g: { name: ‘grams’, type: ‘weight’, factor: 1 },
kg: { name: ‘kilograms’, type: ‘weight’, factor: 1000 },
oz: { name: ‘oz (weight)’, type: ‘weight’, factor: 28.3495231 },
lb: { name: ‘lb’, type: ‘weight’, factor: 453.59237 },
stick_us: { name: ‘US sticks’, type: ‘weight’, factor: 113.4 }
};
function selectedDensity() {
return customDensity !== null
? customDensity
: Number($(‘rc-ingredient’).value);
}
function ingredientName() {
if (customDensity !== null) return customName || ‘Custom ingredient’;
return $(‘rc-ingredient’).selectedOptions[0].text;
}
function format(value, places) {
return Number(value.toFixed(places)).toLocaleString(‘en-US’, {
maximumFractionDigits: places
});
}
function showError(id, message) {
const el = $(id);
el.textContent = message;
el.classList.add(‘rc-visible’);
}
function clearError(id) {
const el = $(id);
el.textContent = ”;
el.classList.remove(‘rc-visible’);
}
function showResult(id) {
$(id).classList.add(‘rc-visible’);
}
function hideResult(id) {
$(id).classList.remove(‘rc-visible’);
}
root.querySelectorAll(‘.rc-tab’).forEach((tab) => {
tab.addEventListener(‘click’, function () {
const target = this.dataset.tab;
root.querySelectorAll(‘.rc-tab’).forEach((button) => {
const active = button === this;
button.classList.toggle(‘active’, active);
button.setAttribute(‘aria-selected’, String(active));
});
root.querySelectorAll(‘.rc-tool’).forEach((panel) => {
panel.classList.toggle(‘rc-hidden’, panel.dataset.tool !== target);
});
});
});
root.querySelectorAll(‘[data-round]’).forEach((button) => {
button.addEventListener(‘click’, function () {
decimals = Number(this.dataset.round);
root.querySelectorAll(‘[data-round]’).forEach((item) => {
item.classList.toggle(‘active’, item === this);
});
});
});
$(‘rc-swap’).addEventListener(‘click’, function () {
const from = $(‘rc-from’);
const to = $(‘rc-to’);
const oldFrom = from.value;
from.value = to.value;
to.value = oldFrom;
});
$(‘rc-add’).addEventListener(‘click’, function () {
$(‘rc-custom-wrap’).classList.toggle(‘rc-hidden’);
});
$(‘rc-use-custom’).addEventListener(‘click’, function () {
const name = $(‘rc-custom-name’).value.trim();
const density = Number($(‘rc-custom-density’).value);
if (!Number.isFinite(density) || density <= 0) {
showError(‘rc-error’, ‘Enter a custom ingredient weight greater than zero grams per US cup.’);
return;
}
customDensity = density;
customName = name || ‘Custom ingredient’;
clearError(‘rc-error’);
$(‘rc-add’).textContent = ‘Custom: ‘ + customName;
$(‘rc-custom-wrap’).classList.add(‘rc-hidden’);
});
$(‘rc-ingredient’).addEventListener(‘change’, function () {
customDensity = null;
customName = ”;
$(‘rc-add’).textContent = ‘Add own’;
});
function convertAmount(amount, fromKey, toKey, density) {
const from = units[fromKey];
const to = units[toKey];
if (!from || !to) throw new Error(‘Please select valid conversion units.’);
if (from.type === to.type) {
return amount * from.factor / to.factor;
}
if (from.type === ‘volume’ && to.type === ‘weight’) {
// Convert volume to mL, then use ingredient grams per US cup.
const ml = amount * from.factor;
const grams = ml * density / units.cup_us.factor;
return grams / to.factor;
}
if (from.type === ‘weight’ && to.type === ‘volume’) {
const grams = amount * from.factor;
const ml = grams * units.cup_us.factor / density;
return ml / to.factor;
}
throw new Error(‘These units cannot be converted.’);
}
$(‘rc-convert’).addEventListener(‘click’, function () {
clearError(‘rc-error’);
hideResult(‘rc-result’);
const amount = Number($(‘rc-value’).value);
if ($(‘rc-value’).value.trim() === ” || !Number.isFinite(amount) || amount < 0) {
showError(‘rc-error’, ‘Please enter a valid amount of zero or more.’);
return;
}
const fromKey = $(‘rc-from’).value;
const toKey = $(‘rc-to’).value;
const density = selectedDensity();
try {
const result = convertAmount(amount, fromKey, toKey, density);
if (!Number.isFinite(result)) throw new Error(‘Unable to calculate this conversion.’);
$(‘rc-result-number’).textContent =
format(result, decimals) + ‘ ‘ + units[toKey].name;
$(‘rc-result-detail’).textContent =
format(amount, decimals) + ‘ ‘ + units[fromKey].name +
‘ = ‘ + format(result, decimals) + ‘ ‘ + units[toKey].name;
const needsDensity = units[fromKey].type !== units[toKey].type;
$(‘rc-result-note’).textContent = needsDensity
? ‘Ingredient used: ‘ + ingredientName() + ‘ (approximately ‘ +
format(density, 1) + ‘ g per US cup). Actual weights may vary.’
: ‘This conversion uses standard unit definitions and does not require ingredient density.’;
showResult(‘rc-result’);
} catch (error) {
showError(‘rc-error’, error.message);
}
});
$(‘rc-copy’).addEventListener(‘click’, async function () {
const text = $(‘rc-result-detail’).textContent;
try {
await navigator.clipboard.writeText(text);
this.textContent = ‘Copied!’;
} catch (error) {
const area = document.createElement(‘textarea’);
area.value = text;
area.style.position = ‘absolute’;
area.style.left = ‘-9999px’;
root.appendChild(area);
area.select();
const copied = document.execCommand(‘copy’);
area.remove();
this.textContent = copied ? ‘Copied!’ : ‘Select result to copy’;
}
setTimeout(() => { this.textContent = ‘Copy result’; }, 1800);
});
// Air fryer conversion
$(‘rc-air-calculate’).addEventListener(‘click’, function () {
clearError(‘rc-air-error’);
hideResult(‘rc-air-result’);
const temp = Number($(‘rc-air-temp’).value);
const time = Number($(‘rc-air-time’).value);
const unit = $(‘rc-air-unit’).value;
if ($(‘rc-air-temp’).value.trim() === ” ||
!Number.isFinite(temp) || temp < -50 || temp > 600) {
showError(‘rc-air-error’, ‘Enter a valid oven temperature.’);
return;
}
if ($(‘rc-air-time’).value.trim() === ” ||
!Number.isFinite(time) || time <= 0) {
showError(‘rc-air-error’, ‘Enter a cooking time greater than zero minutes.’);
return;
}
let celsius = unit === ‘F’ ? (temp – 32) * 5 / 9 : temp;
let adjustedC = celsius – 15;
let adjustedF = adjustedC * 9 / 5 + 32;
let adjustedTime = Math.max(1, Math.round(time * 0.8));
$(‘rc-air-output’).textContent = unit === ‘F’
? Math.round(adjustedF) + ‘°F (‘ + Math.round(adjustedC) + ‘°C)’
: Math.round(adjustedC) + ‘°C (‘ + Math.round(adjustedF) + ‘°F)’;
$(‘rc-air-time-output’).textContent =
‘Suggested cooking time: about ‘ + adjustedTime +
‘ minutes, starting from ‘ + time + ‘ minutes in the oven.’;
showResult(‘rc-air-result’);
});
// Oven temperature conversion
$(‘rc-oven-calculate’).addEventListener(‘click’, function () {
clearError(‘rc-oven-error’);
hideResult(‘rc-oven-result’);
const value = Number($(‘rc-oven-temp’).value);
const unit = $(‘rc-oven-unit’).value;
if ($(‘rc-oven-temp’).value.trim() === ” ||
!Number.isFinite(value) || value < -459.67 || value > 2000) {
showError(‘rc-oven-error’, ‘Enter a valid temperature.’);
return;
}
const c = unit === ‘F’ ? (value – 32) * 5 / 9 : value;
const f = c * 9 / 5 + 32;
const gas = Math.max(0, Math.round((c – 121.111) / 13.889));
$(‘rc-oven-output’).textContent = Math.round(c) + ‘°C / ‘ + Math.round(f) + ‘°F’;
$(‘rc-oven-details’).textContent = ‘Approximate UK gas mark: ‘ + gas + ‘.’;
showResult(‘rc-oven-result’);
});
// Butter converter
$(‘rc-butter-calculate’).addEventListener(‘click’, function () {
clearError(‘rc-butter-error’);
hideResult(‘rc-butter-result’);
const amount = Number($(‘rc-butter-value’).value);
const from = $(‘rc-butter-from’).value;
const to = $(‘rc-butter-to’).value;
if ($(‘rc-butter-value’).value.trim() === ” ||
!Number.isFinite(amount) || amount < 0) {
showError(‘rc-butter-error’, ‘Please enter a valid butter amount.’);
return;
}
// Convert the source amount to grams first.
const butterUnits = {
cup_us: 227,
tbsp_us: 227 / 16,
tsp_us: 227 / 48,
stick_us: 113.4,
g: 1,
oz: 28.3495231,
lb: 453.59237,
tbsp_metric: 227 / (236.5882365 / 15)
};
const grams = amount * butterUnits[from];
const result = grams / butterUnits[to];
const names = {
cup_us: ‘US cups’,
tbsp_us: ‘US tablespoons’,
tsp_us: ‘US teaspoons’,
stick_us: ‘US sticks’,
g: ‘grams’,
oz: ‘ounces’,
lb: ‘pounds’,
tbsp_metric: ‘metric tablespoons’
};
$(‘rc-butter-output’).textContent =
format(result, decimals) + ‘ ‘ + names[to];
showResult(‘rc-butter-result’);
});
})();