alt=|thumb|The central street of the [[Mellah of Fez|Mellah of Fez featuring balconies—which distinguished domestic architecture of Jewish homes from contemporary inward-facing Muslim homes in Morocco—that were rebuilt in modern styles after French artillery fire in 1912 caused severe structural damage to the buildings.]]

A mellah ( or 'saline area'; and ) is the place of residence historically assigned to Jewish communities in Morocco.

The rural mellah, as it exists or existed in the mountainous regions of the Atlas and the Rif and in the plains regions reaching to the Sahara, is a relatively isolated open village inhabited exclusively by Jews. Since the time of Idris II (early 9th century) a Jewish community was concentrated in the neighbourhood known as Foundouk el-Yihoudi ("Caravanserai of the Jew") near Bab Guissa in the northeast of the city.

thumb|Bab el-Mellah, the historic entrance to the Jewish [[Mellah of Fez]]

In 1276 the Marinid sultan Abu Yusuf Yaqub ibn Abd al-Haqq founded Fes el-Jdid, a new fortified administrative city to house their troops and the royal palace. The city included a southern district, known as Hims, which was initially inhabited by Muslim garrisons, particularly the Sultan's mercenary contingents of Syrian archers, which were later disbanded. The surrounding area, located in the middle of the city's main commercial districts where Jewish merchants were quite active, was turned into a horm (sanctuary) where non-Muslims were not allowed to enter, resulting in the expulsion of the Jewish inhabitants and businesses there.

In any case, the transfer (whether progressive or sudden) occurred with some violence and hardship. The political motivations for this may have been similar to those of the Marinids in creating the Mellah of Fez, which served as a precedent followed by the Saadian dynasty. as industrial imports from Europe drove traditional Jewish crafts out of the market. As a result, Moroccan Jews started migrating from the interior to coastal cities such as Essaouira, Mazagan, Asfi, and later Casablanca for economic opportunity, participating in trade with Europeans and the development of those cities. Some impoverished migrants to overpopulated urban mellahs (Jewish quarters) struggled to survive as shopkeepers, peddlers, artisans or beggars.

(In Tetouan, the Spanish word judería was later used as the name of the district.)

The mellah in Rabat was established in 1808 by Sultan Mawlay Sulaiman; this separated the Jewish and Muslim people who had lived together in a shared area of the city. The street called Rue des Synagogues also had mosques and zawiyas.

Since the establishment of the State of Israel in 1948, almost all Moroccan Jews, for a variety of reasons, have emigrated either to the new Jewish state or to countries like France and Canada—some in government-coordinated programs such as Operation Yachin, some fleeing persecution, some for religious reasons, and some encouraged by the Jewish Agency. As a result, nowadays mellahs are only inhabited by Muslims, the few remaining Jews have moved to modern quarters of Moroccan towns. The changing economy of Morocco has also meant that the majority of Moroccan Jews now live in the modern metropolis of Casablanca, with an estimated 5,000 living there in 1997 (with only 150 living in Fez, by comparison).

thumb|Most of the Jews of [[Essaouira left after 1948 Due to poor drainage and invasive seawater, abandoned buildings fell into disrepair and dilapidation, as seen in this image from 2009. The Mellah of Fez faces a similar fate; however, it is currently undergoing renovation thanks to UNESCO funding.

thumb| Detail of the gate of the Jewish cemetery of the [[Mellah of Fez]]

The legacy of the Moroccan Jewish districts on commerce remain, as the markets constructed and brought alive by Jewish merchants not only exist as of 2014 but still in the lively forms they served in previous centuries for the Jewish communities. The former mellahs continue to be visited as historical sites. One writer notes: "The quarters’ squalor still exists, but they’re also picturesque and bustling — and that, too, speaks to Morocco’s vibrant Jewish past."<blockquote>"The one gate that gave way to the medina, which could have easily been repudiated as an emblem of imprisonment, instead came to be treated as an object of reverence by the mellah ’s inhabitants, as we see in this description from the early twentieth century: If one stops for a moment in front of this gate, one sees a curious thing: All who pass, children, beggars, peddlers driving their donkeys loaded with merchandise, old women, hunched-over men, all approach this dusty wall and press their lips against it with as much fervor as if they were kissing the holy Torah."</blockquote>The mellahs of Morocco primarily came about as Jews migrated to Morocco after being expelled from the Iberian Peninsula during the Spanish Inquisition. Even more so, the mellah's market became a prominent space for not only the Jewish community, but non-Jewish peoples who would come to shop on market days. Because Jews commonly held merchant and artisan positions, the mellah was an attractive trade post for the entire city, not just the Jewish quarter.