MPG calculator template
Miles per gallon from a fill-up, with fuel cost per mile, the cost of the tank, and L/100 km and km/L. Three inputs, five calculation fields, no submit.
Try the live MPG calculator first- Import-ready Gravity Forms JSON
- One-page install guide
- The plugins it needs, with links
- Everything in Template
- Step-by-step PDF with screenshots of every field and formula
- The CSS skin from this site, with notes on matching your brand
What you'll need
Check these before you buy so there are no surprises. Links may be affiliate links.
- Required Gravity Forms (any license) Calculation fields are in core.
Free build guide: MPG calculator for WordPress
This guide rebuilds the MPG calculator from this site in Gravity Forms: 3 inputs, 5 live results and no submit button. Expect about 24 minutes by hand. The template above is the same form as an import file, and the bundle adds a PDF version of this guide with a screenshot of every setting, plus the stylesheet.
You will end up with:
- Miles per gallon
- Fuel cost per mile
- Cost of this tank
- Litres per 100 km
- Kilometres per litre
What you need
- Gravity Forms (any license) — Calculation fields are in core.
Everything here is core Gravity Forms. No add-ons.
1. Create the form
- Go to Forms → New Form and name it MPG.
- In Form Settings → Form Layout, set the CSS Class Name to
fo-live-only. Step 3 uses it to hide the submit button. - Leave the form open in the editor; the fields come next.
2. Add the fields, in this order
Field IDs are assigned as you add fields. If yours come out differently, change the {Label:ID} references in the formulas to match your IDs. Settings not mentioned stay at their defaults.
1. Miles driven since the last fill-up · Number · ID 1
Number Format 9,999.99; Default Value 320; Description “Reset the trip odometer when you fill up; read it at the next fill.”.
2. Gallons added · Number · ID 2
Number Format 9,999.99; Default Value 11.5; Description “From the pump receipt, filled to the first click both times.”; Layout: half width, on the same row as its neighbour (drag the field beside it in the editor; no CSS class needed).
3. Price per gallon · Number · ID 3
Number Format Currency; Default Value 3.50; Layout: half width, on the same row as its neighbour (drag the field beside it in the editor; no CSS class needed).
4. Miles per gallon · Number · ID 4
Number Format 9,999.99; Custom CSS Class (Appearance tab) fo-result; tick Enable Calculation, Rounding 1.
{Miles:1} / {Gallons:2}
5. Fuel cost per mile · Number · ID 5
Number Format 9,999.99; Description “Dollars per mile.”; Layout: half width, on the same row as its neighbour (drag the field beside it in the editor; no CSS class needed); Custom CSS Class (Appearance tab) fo-result fo-result--sub; tick Enable Calculation, Rounding 3.
{Price:3} * {Gallons:2} / {Miles:1}
6. Cost of this tank · Number · ID 6
Number Format Currency; Layout: half width, on the same row as its neighbour (drag the field beside it in the editor; no CSS class needed); Custom CSS Class (Appearance tab) fo-result fo-result--sub; tick Enable Calculation, Rounding 2.
{Price:3} * {Gallons:2}
7. Litres per 100 km · Number · ID 7
Number Format 9,999.99; Layout: half width, on the same row as its neighbour (drag the field beside it in the editor; no CSS class needed); Custom CSS Class (Appearance tab) fo-result fo-result--sub; tick Enable Calculation, Rounding 1.
235.215 * {Gallons:2} / {Miles:1}
8. Kilometres per litre · Number · ID 8
Number Format 9,999.99; Layout: half width, on the same row as its neighbour (drag the field beside it in the editor; no CSS class needed); Custom CSS Class (Appearance tab) fo-result fo-result--sub; tick Enable Calculation, Rounding 1.
{Miles:1} / {Gallons:2} * 0.4251
3. Hide the submit button
The results are live, so nothing needs submitting. Add this filter to your theme’s functions.php or a code-snippets plugin; it hides the button on any form carrying the fo-live-only class:
add_filter( 'gform_submit_button', function ( $button, $form ) {
return str_contains( (string) rgar( $form, 'cssClass' ), 'fo-live-only' ) ? '' : $button;
}, 10, 2 );
Or with CSS alone: .fo-live-only_wrapper .gform_footer { display: none; }
4. Put it on a page and make it look like this
Add the form to any page with the Gravity Forms block, or the shortcode [gravityform id="X" title="false" ajax="false"]. The form inherits your theme’s styles; the classes you set in step 2 are hooks for the look you see on this site:
fo-resulton a calculation field makes it the big teal result panel.fo-result fo-result--submakes the smaller secondary figures.fo-segmentedon a radio field turns it into a segmented switch.- Two fields on one row is the editor’s own column layout: drag a field beside another and the row splits in half. No CSS class is needed, and the old
gf_left_halfReady Classes are deprecated.
The bundle includes the two stylesheets that implement those classes, with notes on matching your brand colours. Without them the form still works; it just looks like your theme’s default Gravity Forms styling.
How the maths works is explained under “How it’s calculated” on the live MPG calculator.