Qibla Direction Widget
Help visitors face the Qibla from your city or any coordinates. The widget gives the bearing to the Kaaba in degrees from true north, draws it on a compass rose and shows the distance to Mecca, with a plain note on correcting for magnetic north.
Live preview
Under the widget on your page: Powered by A2Z Tools
Embed code
<iframe src="https://a2z.tools/embed/w/qibla-direction" title="Qibla Direction by A2Z Tools" width="100%" height="830" style="border:0;width:100%" loading="lazy" allow="clipboard-write"></iframe>
A plain iframe. Works everywhere, including site builders that strip scripts. Adjust height if your content needs more room.
<div data-a2z-widget="qibla-direction" data-height="830"></div> <script async src="https://a2z.tools/embed.js"></script>
Adds a small script (what it does) that sizes the widget to fit its content, loads it lazily and keeps it isolated from your page's CSS.
Works with
How it works
The Qibla is the direction of the Kaaba in Mecca, taken here at 21.4225 N, 39.8262 E. On a globe the shortest route between two points is a great circle, so the widget calculates the initial bearing of that route: with the place at latitude 1 and the Kaaba at latitude 2, the bearing is atan2(sin dLon cos lat2, cos lat1 sin lat2 - sin lat1 cos lat2 cos dLon), measured clockwise from true north. From London that is 119.0 degrees, east-south-east; from New York it is 58.5 degrees, north-east, which surprises people used to flat maps that suggest south-east. Distance uses the haversine formula on a sphere of 6,371 km mean radius. You can choose one of 24 cities, whose coordinates come from GeoNames, or type latitude and longitude. The bearing is relative to true north; a magnetic compass needs the local declination subtracted, which NOAA's magnetic field calculator gives for any place. The widget never uses device location.
Calculation method
- Kaaba: 21.4225 N, 39.8262 E
- Bearing = atan2(sin(dLon) cos(lat2), cos(lat1) sin(lat2) - sin(lat1) cos(lat2) cos(dLon)), normalised to 0-360 degrees clockwise from true north
- Distance = 2R asin(sqrt(sin^2(dLat/2) + cos(lat1) cos(lat2) sin^2(dLon/2))), R = 6,371.0088 km; miles = km / 1.609344
- Magnetic (compass) bearing = true bearing - magnetic declination (east positive)
Worked examples
London
Inputs: 51.5085 N, 0.1257 W
Result: 119.0 degrees from true north (ESE); 4,794 km
The arrow points a little south of due east-south-east.
New York City
Inputs: 40.7143 N, 74.0060 W
Result: 58.5 degrees from true north (ENE); 10,306 km
The great circle leaves New York heading north-east across the Atlantic.
A calculated direction for guidance; local mosques may use a slightly different orientation.
Limitations
- Uses a spherical Earth; an ellipsoidal calculation differs by a few tenths of a degree at most.
- Does not know the local magnetic declination - look it up and subtract it before using a compass.
- Within 1 km of the Kaaba, or near its antipode in the Pacific, no single direction is meaningful and the widget says so.
Where publishers use it
- Mosque websites for new worshippers and visitors who pray at home
- Muslim-friendly hotels and holiday rentals showing guests the direction in their rooms
- Islamic travel blogs with a widget per destination city
- University prayer-room pages for international students
- Architects and builders documenting the orientation of a prayer hall
Questions
Why does the Qibla from America point north-east?
Because the shortest path over the globe from North America to Mecca crosses the North Atlantic. From New York the great-circle bearing is about 58.5 degrees (north-east); a straight line on a flat Mercator map would wrongly suggest south-east.
Is the bearing from true north or magnetic north?
True north. A compass points to magnetic north, which differs by the local declination - a few degrees in most of Europe and the Middle East, up to around 15 degrees in parts of North America. Subtract an east declination (add a west one) to get the compass reading.
How accurate is it?
The spherical formula is within a few tenths of a degree of an ellipsoid calculation, far finer than a phone compass, which is often 5 degrees or more out near steel, speakers or cars.
Can I set my mosque's exact coordinates?
Yes. Choose Other place, or link with v_city=custom&v_lat=24.8608&v_lon=67.0104. Use decimal degrees: north and east positive, south and west negative.
Where do the city coordinates come from?
From the GeoNames geographical database, rounded to four decimals (about 11 m). The Kaaba's position is 21.4225 N, 39.8262 E.
Sources
- Kaaba (coordinates) - Wikipedia . Gives the Kaaba's position as 21.4225 N, 39.82617 E. Checked 2026-10-01.
- Magnetic Field Calculators - declination - NOAA National Centers for Environmental Information . Gives the magnetic declination for any place, to convert the true bearing into a compass reading. Checked 2026-10-01.
- GeoNames geographical database - GeoNames . Coordinates of the 24 preset cities (for example London 51.50853, -0.12574). Checked 2026-10-01.
Cite or recommend this tool
If you reference this tool in an article, course or documentation, these formats are ready to copy. They are optional - nothing is added to your site unless you paste it.
A2Z Tools Qibla Direction https://a2z.tools/qibla-direction-finder
<a href="https://a2z.tools/qibla-direction-finder">A2Z Tools Qibla Direction</a>
[A2Z Tools Qibla Direction](https://a2z.tools/qibla-direction-finder)
Qibla Direction by A2Z Tools - https://a2z.tools/qibla-direction-finder
Related widgets
-
Fajr, Sunrise, Dhuhr, Asr, Maghrib and Isha for any place, with the major calculation methods.
-
Gregorian to Hijri and back on the Umm al-Qura calendar, with today's Hijri date and month length.
-
Sunrise, sunset, solar noon, day length and twilight for any place and date.
-
Live countdown to the next Ramadan, then day N of Ramadan and the countdown to Eid al-Fitr.
-
Live days, hours, minutes and seconds to a date you set, with an "event has started" message.
-
Exact age in years, months and days, totals in months, weeks and days, and the next birthday.