Fes · Morocco
What Is a Medina? The Rules Behind North Africa's Old Cities
Fez, Tunis and Marrakech look like labyrinths. They were shaped by thousands of small quarrels between neighbours, settled by judges and master masons. Then French scholars turned the result into a model. The model has outlived its evidence.
The story is old enough that nobody can swear to it. In the time of the caliph Umar, a man who owned an upper room opened a new window in its wall. From that window, his neighbour said, you could see into his house. Umar did not ask the two men to argue it out. According to the version the jurists repeated for centuries, he told his officer to put a bed under the window and stand on it. If a man standing on the bed could look into the neighbour's house, the window had to go.
The case travelled. Mustapha Ben Hamouche, who studied how these rules shaped houses in the Maghreb, traces it to a letter Umar sent to his governor in Fustat. This is legal tradition, not a scene from Umar's life: the jurists told it that way. No seventh-century copy of the letter survives to check. Seven hundred years later the story turns up again in Tunis, in a book on building disputes written by a master mason called Ibn al-Rami. Majdi Faleh quotes the same bed from the modern Tunis edition of that book. In some tellings the window was later allowed back, on condition that it sat high enough to let in air and light without letting the owner look down.
That small procedure, a man on a bed testing a view, is a good place to start.
A word that means city
In Arabic madina simply means city. In North Africa the word is used for something narrower: the historic walled town, as opposed to the new towns built beside it in the twentieth century. Ask for the medina in Fez, Tunis or Marrakech and you will be sent through a gate into streets that bend, narrow and stop.
To a first-time visitor the plan looks like an accident. Lanes end in blank walls. Doors do not face each other. Houses show the street almost nothing but a door and a few small windows set high up. You can walk for ten minutes and come out two hundred metres from where you started.
The usual explanation, repeated in guidebooks and lecture halls, is that this is "the Islamic city": a type with a mosque at its heart, markets arranged around it and private quarters behind. That explanation has a history of its own. It was written down by a handful of French scholars between the 1920s and the 1940s, mostly from what they saw in North Africa. For the last forty years historians have been taking it apart.
The better answer is less tidy. The law did not design the medina. The towns, their courtyard houses and their closed quarters were older than the rulings. What the law did was regulate how that fabric changed: every new window, door, shop and storey could be challenged by a neighbour. In Tunis, where a builder wrote those disputes down, you can watch it happen. In Fez and Marrakech the same law applied, but the records are thinner. There the argument is a comparison, not a proof. So the three cities do different jobs here. Tunis is where the records are. Fez is the labyrinth that confuses only outsiders. Marrakech is the reminder that a city is more than its walls.
The model everyone learned
The model has a clear family tree. In 1928 the Arabist William Marçais gave a lecture in Paris called "L'islamisme et la vie urbaine", Islam and urban life. His brother Georges, an art historian in Algiers, turned the idea into a shape in two articles, "L'urbanisme musulman" (1940) and "La conception des villes dans l'Islam" (1945). They were not alone. Jean Sauvaget wrote on Aleppo and Damascus. Gustave von Grunebaum generalised the picture in "The Structure of the Muslim Town" (1955). For North Africa, though, the Marçais brothers drew the shape everyone learned.
In Georges Marçais's version a true Islamic city needs a congregational Friday mosque with a main market close by. The markets are not scattered at random. Next to the mosque you find the trades that serve it and the cleanest, most valuable goods: candle sellers, sellers of incense and perfume. Further out come cloth and leather. The noisy, smelly and dangerous trades sit near the gates. Behind the markets lie the residential quarters, closed and inward-looking.
Tunis seems to prove him right. The perfumers' market, Souk el-Attarine, still runs along the wall of the Zitouna Mosque. The chechia makers, who knit and felt the red wool caps, have their own covered souk a few steps away. The model was not invented from nothing. Marçais generalised real patterns he could see in a few North African cities. The trouble began when those patterns became a type.
The problem, as the urban sociologist Janet Abu-Lughod pointed out in 1987, is where the model came from. In "The Islamic City: Historic Myth, Islamic Essence, and Contemporary Relevance", published in the International Journal of Middle East Studies, she showed that virtually all of the cases Marçais cited were North African. It was also, she argued, a model of outcomes rather than of processes: it described a finished city without explaining how it came to be.
Abu-Lughod opened her article with a warning that still matters. Planners in Saudi Arabia and the Gulf, she wrote, were trying to reproduce in new cities the patterns that had been "identified as Islamic", often without knowing that the identification came from this small Orientalist literature.
For the processes, go back to the mason in Tunis.
![]()
The medina of Tunis from above, with the minaret of the Zitouna Mosque. Photo: IssamBarhoumi, CC BY-SA 3.0, via Wikimedia Commons.
A book by a builder
Muhammad ibn Ibrahim ibn al-Rami was a mason. Not a jurist who happened to know about walls, but a builder whose judgement the courts of Hafsid Tunis called on when neighbours went to law. He died in or after 1333 (Simon O'Meara; Ben Hamouche gives 1334). His teacher in law was Ibn Abd al-Rafi, chief judge of Tunis, who died in 1332 and whose rulings fill many of the book's pages.
The book is called Kitab al-I'lan bi-ahkam al-bunyan, usually translated as The Book of Pronouncing Judgements in Matters of Building. It has five parts: on buildings and walls, on the removal of harm, on defects in building, on orchards, on mills. O'Meara counts some twenty surviving manuscripts across the Arab world, a sign that people kept copying it because they used it. It was printed in a Moroccan journal of Maliki law in 1982 and in a critical edition by Farid Ben Slimane in Tunis in 1999.
Ibn al-Rami says plainly where his material came from. In the introduction he lists government records, the books of his contemporaries, the court records of judges and the fatwas of muftis, then the standard works of the Maliki school back to the Mudawwana compiled in Kairouan in the ninth century. He did not invent the rules. He gathered what judges in his part of the world had decided when people quarrelled over buildings, sorted it by subject and often added his own verdict.
The quarrels are specific.
Windows. A new window that lets you see into a neighbour's courtyard is a harm. Ibn al-Rami says he never saw a judge in Tunis rule otherwise. An old window, one that was there before the neighbour built, may stay. Its owner, however, has no right to use it to look in. If the view still troubles the neighbour, the neighbour may raise his own wall.
Screens. One case concerns a sharjab, a projecting latticed window of the kind Cairo calls a mashrabiya. A judge ruled that if the lattice let the owner see out as clearly as if it were not there, it was worse than an open window. The neighbour would never know he was being watched.
Mosques. Even public buildings had to respect the houses around them. When worshippers began using the roof of a mosque as extra prayer space, the owner of the house next door complained that anyone standing up there could see into his home. The ruling Ibn al-Rami cites from the great Kairouan jurist Sahnun was that the mosque had to build a parapet. Nobody was to pray on the roof until it was screened. Minarets raised the same problem several times a day. One Andalusian judge recommended screening the sides of a minaret that faced houses. Ibn al-Rami's own conclusion was practical: a minaret was acceptable if the houses around it were far enough away that you could not make out faces.
Shops. A man opened a shop opposite his neighbour's door. The neighbour complained. The chief judge of Tunis tested it: the complainant opened his door wide and stood on his own threshold, while a witness stood by the shop to see what could be seen. He found no harm. The complaint was dismissed.
The rest of the book is less dramatic. Ovens, bathhouses and mills could be stopped if their smoke harmed the people around them. Most of all there are walls: who owns the one between two houses, whether a neighbour may rest a beam in it, who pays when it falls.
Behind all of this sits a single short saying of the Prophet that the jurists quoted more than any other: la darar wa la dirar, no harm and no returning harm. Almost every case is a test of what counts as harm in a particular street.
![]()
The cloth market of Tunis on an early 20th-century postcard. Public domain, via Wikimedia Commons.
Law that only woke up when someone complained
It would be easy to read Ibn al-Rami as a building code. O'Meara argues that this is the wrong way round. The law said what a neighbour could stop you building and it came into force only when someone objected. If nobody minded your new window, nobody sealed it.
In Tunis at least, what regularity there is comes from objections, some upheld and some dismissed, each one adjusting a door, a window, a parapet or a wall by a few hand-spans. O'Meara stresses that the law was applied through local custom ('urf) and local practice. That is one reason the same principles could give different streets in different cities.
Nor was this law unique in kind. O'Meara points to the London Assize of Nuisance, whose records from 1301 to 1431 deal with similar quarrels in a Christian city. The kinds of dispute match; the courts and the property law behind them were different. O'Meara calls the years from about 950 to 1350, half in jest, a golden age: at least five surviving treatises on building law were written in that period. The earliest is by Ibn al-Imam of Tudela, in al-Andalus, who died in the 990s.
In Tunis this system did much of the work a city council would do. The historian Meriem Ben Ammar notes that jurists and judges regulated the urban fabric of the medina until 1858, when Tunis got its first municipality. Even then the change was gradual rather than a clean break. As late as the turn of the nineteenth century a Tunis jurist, al-Baroudi, was still writing a treatise on disputed party walls.
What the rules make
In 1986 the architect Besim Hakim put these rulings together. His book Arabic-Islamic Cities: Building and Planning Principles read Ibn al-Rami's cases alongside local custom and building practice and drew out a set of design principles, with drawings, dimensions and examples photographed in the medina of Tunis in 1974 and 1975.
In short: The house turns inward to a courtyard, because almost any opening onto a neighbour risks a complaint. The entrance bends, so that an open front door shows a passer-by a wall rather than the courtyard. Faleh describes the sequence a visitor walks through in Tunis: gate, market, square, street, house door, a vestibule called the sqifa. Only then the courtyard. Doors on opposite sides of a lane are staggered rather than facing. Windows onto the street sit above head height.
The lanes follow the same logic. A through street belongs to everyone; anyone may walk it. A dead-end lane is different. In Hakim's reading, the households that open onto it hold particular rights over it. Together they can agree to things a stranger could not demand. That is why medinas are full of short blind alleys that branch off the main streets like twigs. Each one is a small, self-governing neighbourhood of a few doors. Even the width of streets had a legal reference point: a hadith says that when people disagree about the width of a road it should be seven cubits. O'Meara notes, drily, that real streets were often wider or narrower.
Moncef M'halla, the Tunisian scholar Ben Ammar quotes, puts the wall at the centre of it all. The medina grows by clustering, house against house, around shared walls. Look down on the medina of Tunis and the point is plain: roofs and courtyards packed so tightly that the streets almost disappear.
It is a persuasive picture. It is also, its critics say, too neat. Hakim's book was criticised for oversimplifying. Abu-Lughod, who admired it, made a sharper point in a footnote. Hakim's evidence came almost exclusively from Tunis. She doubted that Islamic law could be the whole explanation. The cellular pattern of closed quarters in that climate and culture long predated Islam. In Yemen, southern Morocco and Saudi Arabia, cities built tall tower houses instead, which were just as Islamic.
O'Meara reaches a similar conclusion from the legal side. The kind of space the jurists regulated was older than the law that regulated it. Islam modified it, above all by adding the rules on privacy, but did not create it. What the law added was a vocabulary of rights and harms. Jurists carried those principles across the Maghreb and al-Andalus for centuries. Judges applied them differently from place to place.
![]()
Talaa Kebira, one of the two main streets of Fes el-Bali. Photo: Jorge Franganillo, CC BY 2.0, via Wikimedia Commons.
Fez: a city of two banks
Fez began as two towns. Idris I founded the first settlement around 789. His son Idris II founded a second in 808, on the other side of the river. UNESCO describes the result as two fortified quarters facing each other across the Fez river: the bank of the Andalusians and the bank of the Kairouanis, named for the migrants from Cordoba and from Kairouan who settled them. In the eleventh century the Almoravids put both inside one rampart. By the time of the Almohads, in the twelfth and thirteenth centuries, the old town had reached roughly its present size.
Then a ruler did what rulers in this story rarely do and built a planned city. In 1276 the Marinids founded Fes Jdid, "New Fez", to the west of the old one, with the royal palace, the barracks and new residential quarters. UNESCO notes that it was modelled on the earlier plan of Marrakesh. The old town, Fes el-Bali, kept growing the old way.
Fez el-Bali is the medina most often called a labyrinth. It is also the one that most often surprises people who look closely. The historian O'Meara called his book on it Space and Muslim Urban Life: At the Limits of the Labyrinth of Fez (2007). Its argument is that the labyrinth is a matter of where you stand. To someone who lives in a derb, a dead-end lane, the way home is obvious. To someone from outside, the same lanes are a wall of closed doors. For the people who live there the lanes are easy to read.
The twentieth century nearly ended that. In 1912 France made Morocco a protectorate. The first Resident General, Hubert Lyautey, asked the architect Henri Prost to plan Morocco's cities. Prost's office, set up in 1914, drew new towns beside the old ones rather than on top of them.
That decision is often told as a story of respect, with Lyautey cast as the man who saved the medinas. In a narrow sense the medinas were saved. Decrees of 23 August 1923 and 29 October 1954 defined a buffer zone around the medina of Fez that, in UNESCO's words, protects its visual integrity. The other side of the story is segregation. As the historian Lahbib El Moumni puts it, Prost's plans physically separated the population. Moroccans were housed in the medinas and in "new towns for natives", European settlers in "new towns for Europeans". Abu-Lughod, who studied Rabat, called the result urban apartheid. The medina survived partly because it was set apart.
Being set apart had a price. The old town stayed poor and grew crowded. Today the Moroccan state has an agency whose name says everything: the Agency for De-densification and Rehabilitation of the Medina of Fez.
On Exhibo, the best place to see the old fabric from the inside is the Nejjarine Museum, a museum of woodwork in a former fondouk, the merchants' inn that sat inside the market streets. There is also the Batha Museum, which reopened in 2025 as a museum of the arts of Islam. The Museum of Moroccan Jewish Culture tells the story of the mellah, the Jewish quarter of Fez.
Tunis: the city that fought back
The medina of Tunis is older than Fez. UNESCO dates the first Arab-Muslim town here to 698, one of the earliest in the Maghreb. Most of what stands today is much later. Under the Almohads and Hafsids, from the twelfth to the sixteenth century, it was one of the richest cities in the Arab world. The listed area is a central medina with two suburbs, north and south, added in the thirteenth century. It holds about 700 historic monuments.
This is Ibn al-Rami's city. It is also the city where the model and its critique meet. Marçais could point to the perfumers by the Zitouna Mosque. Hakim could point to the lanes and walls of the residential quarters, where the mason's rulings had been applied for centuries.
The pressure came first from outside the walls. After 1860, according to the MIT project history, wealthy families began to move out to the European town growing up between the medina and the lake, beyond the sea gate, Bab el Bhar. That town became the grid of boulevards around what is now Avenue Habib Bourguiba. Much of the medina was left to poorer families and newcomers.
The clearest case is Hafsia. According to the project history compiled at MIT, Hafsia, known as the Hara, had been the Jewish quarter of Tunis since the tenth century. When its wealthier families moved to the European districts, it became one of the poorest parts of the medina. In 1928 the French authorities declared it a health hazard. Much of it was demolished between 1933 and 1939. The plan was to rebuild it as a grid of large European apartment blocks. The war stopped that halfway.
Independence in 1956 did not end the idea. The new municipality had its own grand projects. In 1957, Ben Ammar records, the city's master plan proposed cutting a boulevard straight through the medina, east to west, from Avenue Bourguiba to the Kasbah.
Then the residents pushed back. According to the MIT history, the demolition of another quarter, Sidi El Bechir, in 1967 met such anger from residents that it nearly turned into an uprising. After that the grand projects were dropped. The boulevard was never built. In the same year the city set up the Association de Sauvegarde de la Médina, the Association for Safeguarding the Medina, to study the old town and improve the lives of the people in it.
The association's work in Hafsia became one of the most influential conservation projects of its time. The first phase built new housing on the cleared land, following the logic of courtyard houses and narrow lanes rather than copying old buildings. It won the Aga Khan Award for Architecture in 1983. A second phase rehabilitated the surrounding area and won the award again in 1995. The idea behind both was that you could keep a medina alive by building new houses that obeyed its old rules.
It was not a complete victory. At the time of UNESCO's listing in 1979, half of the built heritage of Tunis was in a bad state or close to ruin. Ben Ammar, who studies the medina's legal heritage, notes that height overruns and broken volumes still appear despite the rules. Ben Ammar also finds that the old customs still operate between neighbours, tacitly and unwritten: do not look into the house next door, do not take over the street, do not build too high.
To see the inside of a Tunis house, go to Dar Ben Abdallah, a nineteenth-century palace in the medina that now houses the museum of popular arts and traditions. Its rooms open onto a marble courtyard, the way the law expected.
![]()
A mosque and a synagogue facing each other in Hafsia, the former Jewish quarter of Tunis. Photo: Jamel eddine ben saidane, CC BY-SA 4.0, via Wikimedia Commons.
Marrakech: the square that would not be planned
Marrakech was a capital from the start. UNESCO gives its foundation as 1070 to 1072, by the Almoravids. It was then the capital of the Almohads, whose Koutoubia Mosque has a minaret of 77 metres. The medina inside the walls and gates covers some 700 hectares, by UNESCO's count. The listed property, with its gardens and palm groves, is larger. When the Marinids built Fes Jdid two centuries later, they copied Marrakesh.
The most famous space in Marrakech is the one that looks least like a medina. Jemaa el-Fna is a large, open, triangular square at the entrance to the old town. By day it sells water, fruit, henna tattoos, traditional medicine and fortune-telling. By night it fills with storytellers, musicians, Gnawa dancers and food stalls. It has been protected as part of Morocco's artistic heritage since 1922.
In the 1990s that was not enough. The Spanish novelist Juan Goytisolo feared that local plans for the area would destroy the square's life. In 1996, through his publisher, he warned UNESCO's director-general, Federico Mayor. In June 1997 UNESCO and the Moroccan national commission held an international consultation in Marrakech, partly to study the square. Out of that meeting came a new UNESCO programme for the "oral heritage of humanity". In 2001 Jemaa el-Fna was among the first spaces proclaimed a Masterpiece of the Oral and Intangible Heritage of Humanity. In 2008 it passed onto the Representative List.
No ruling of Ibn al-Rami explains a storyteller. In Tunis the old town was saved by a near-riot. In Marrakech it was a novelist and an international list.
The newer threats are quieter. UNESCO's own assessment lists uncontrolled alterations to upper floors among the main risks to the medina of Marrakech, together with the abandonment of the khettaras, the underground water galleries. A fourteenth-century mason would have recognised the first problem at once. A new storey changes who can see into whose courtyard.
Marrakech got its European new town too, Guéliz, outside the walls of the medina. On Exhibo it is its own district, Guéliz, next to the Medina, the Kasbah and the Mellah.
Inside the walls, the best way to see how a Marrakech house turns inward is to visit the restored courtyards. Le Jardin Secret is a riad garden in the Mouassine quarter that opened to the public in 2016. Nearby, the Mouassine Museum occupies a house of the sixteenth and seventeenth centuries whose upper apartment, the douiria, keeps its painted wood. The Ben Youssef Madrasa shows the same inward plan at monumental scale, its student rooms arranged around a courtyard.
![]()
Jemaa el-Fna, Marrakech. Photo: Jakub Hałun, CC BY 4.0, via Wikimedia Commons.
Irregular, but not random
Law was not the only force. Rivers and hills set the ground in Fez. Gardens and underground water galleries shaped the edges of Marrakech. Rulers founded cities and new quarters when they could.
There was still rarely a plan. The historian Patrick Lantschner, comparing cities across the later medieval Mediterranean, argues that places where rulers really imposed a spatial order, like Mamluk Cairo, were the exception rather than the rule. Most of the time the shape of a medina was left to its inhabitants.
What they shared was a procedure. A set of agreed harms (overlooking, smoke, blocked light and air, a door opposite a door). A set of agreed rights (a beam in a shared wall, an old window, a passage to your own door). Judges and masons who could be called on to decide. Local custom to fill the gaps. Run that procedure for a few hundred years over a dense town and you get something that looks irregular from above and makes sense from inside.
The Marçais brothers looked at the finished medina and described a mosque, a market and closed quarters. Ibn al-Rami, a builder in Tunis, recorded the arguments that made them.
From the nineteenth century the procedure was taken apart piece by piece. Municipalities took over the streets. The European new towns drew off the money. The medinas grew poorer and more crowded. They survived anyway, because they were listed, protected, studied and in Tunis defended by their own residents. Today they are kept by heritage rules more than by neighbours' complaints.
![]()
Roofs in the medina of Fez. Photo: Adam Jones, CC BY-SA 3.0, via Wikimedia Commons.
Look across the roofs of Fez today and you see the last layer: aerials and satellite dishes, each house reaching out to the world from the top. The courtyard below still faces in.
Where to see it
- Medina of Tunis. Start at Bab el Bhar and walk up to the Zitouna Mosque through the market streets. The perfumers of Souk el-Attarine are still next to the mosque.
- Hafsia, Tunis. The twice award-winning rebuilding of the old Jewish quarter, where new houses follow the old rules.
- Dar Ben Abdallah, Tunis. A medina palace turned museum, built around its courtyard.
- Nejjarine Museum, Fez. Woodwork in a merchants' inn inside the market streets of Fes el-Bali.
- Batha Museum, Fez. The arts of Islam in Fez, reopened in 2025.
- Museum of Moroccan Jewish Culture, Fez. For the mellah, the Jewish quarter of Fez.
- Walls and gates of Marrakech. The Almoravid boundary of the medina.
- Le Jardin Secret and the Mouassine Museum, Marrakech. Two inward-facing houses in the same quarter.
- Ben Youssef Madrasa, Marrakech. The courtyard plan at its grandest.
- Jemaa el-Fna, Marrakech. Go in the evening, when the square changes from a market into a stage.
Check opening hours on each place's page before you go.
Cover: Fes el-Bali from the hills. Photo: Petar Milošević, CC BY-SA 4.0, via Wikimedia Commons.
Museums mentioned
Places mentioned
Al-Attarine Madrasa
Al-Qarawiyyin Mosque
Avenue Habib Bourguiba, Tunis
Bab Bou Jeloud
Bab el Bhar, Tunis
Bou Inania Madrasa
Chouara Tannery
Fes el-Bali, Medina of Fez
Hafsia Quarter, Tunis
Kasbah Square, Tunis
Koutoubia Mosque and Minaret
Marrakech Medina Walls and Gates
Medina of Tunis
Souk El Attarine and Souk Chaouachia, Tunis
Zitouna Mosque, Tunis
Related reading
Built for the Passer-by: Mamluk Cairo, 1250–1517
Why the mosques, tombs and gates of Mamluk Cairo were made to be seen from the street
What Is a Mashrabiya? The Screen That Became an Algorithm
The Arab lattice window once cooled water, softened glare, let air in and kept the street from looking back. Its high-tech heirs in Abu Dhabi, Doha, Dubai and Paris kept the pattern. What happened to the rest?
The Flying Carpet Was Never About Flying
For most of their history, carpets carried people into a season, into the presence of a king or toward Mecca. The flight came late.