A lightweight, browser-based unit converter built with HTML, CSS and JavaScript.
Convert values between different units (length, weight, etc.) directly in your browser — no dependencies, no build process.
- About
- Features
- Demo / Screenshot
- Getting Started
- Supported Units
- Code API
- Future Improvements
- Contributing
- License
Unit-converter is a simple, user-friendly tool to convert numeric values between different measurement units.
It’s built purely with vanilla JavaScript, HTML and CSS — so you can drop it into any static website or open index.html directly in the browser.
I created this project to provide a minimal, easy-to-use converter without relying on external libraries or heavy frameworks.
- ✅ Convert between common units of length/ distance (e.g. millimeter, centimeter, meter, kilometer, meter ↔ feet/miles, etc.)
- ✅ Convert between common units of weight/mass (e.g. gram, kilogram, pounds, ounces, etc.)
- ✅ Browser-based — no build tools, frameworks or dependencies required
- ✅ Clean and minimal UI (HTML + CSS) — easy to embed or extend
Nothing special — you just need a modern web browser (e.g. Chrome, Firefox, Safari).
No build system, no npm, no dependencies.
- Clone the repository:
git clone https://github.com/jaybhinsara/Unit-converter.git
- Navigate into the project folder:
cd Unit-converter
- Open index.html in your browser:
open index.html
Usage
- Enter a numeric value in the input field.
- Select the “From” unit (the unit you currently have).
- Select the “To” unit (the unit you want to convert to).
- The converter will automatically compute and display the converted value.
For developers calling the conversion logic programmatically (from index.js), there is a function, e.g.:
// Example usage
const result = convert(value, fromUnit, toUnit, /* optional: shouldRound */);
console.log(${value} ${fromUnit} = ${result} ${toUnit});
value: number — the input value to convert fromUnit: string — the unit to convert from (e.g. "cm", "kg", "km", "lb", etc.) toUnit: string — the unit to convert to shouldRound: boolean (optional) — whether to round the result
Supported Units
Currently supported unit types include (but may not be limited to):
Type Units (examples) Length / Distance mm, cm, m, km, inches, feet, yards, miles — and conversions between them Weight / Mass g, kg, mg, lb (pounds), oz (ounces) — and conversions between them
Code API If you want to use the converter logic in your own JS code (not just via the HTML UI), you can call:
convert(value, fromUnit, toUnit[, shouldRound]);
Parameters value: number — input value fromUnit: string — unit to convert from toUnit: string — unit to convert to shouldRound: boolean — whether to round the result (optional)
Returns: number — the converted value
Future Improvements
Potential enhancements you could consider: ➕ Add more unit categories: volume, temperature, time, area, speed, etc. 🎛️ Better UI / UX: display a list of conversions, support chaining conversions, responsive design. 🌐 Internationalization (i18n): support different number formats (decimal commas, thousands separators, etc.). 🔄 Add option to swap “From” and “To” units quickly. 🧪 Add tests (unit tests) for conversion logic to catch bugs if you expand unit set. 🚀 Package as an npm module or Web Component for easier reuse in other projects.
Contributing
Contributions, issues and suggestions are welcome! If you add new units, fix bugs or improve UI — feel free to open a pull request or an issue.
Please make sure to: Keep code clean and well-commented Update this README if you add new unit categories or features (Optional) Add tests for conversion logic
License This project is open-source.