Fang Qiao (579 – 18 August 648), courtesy name Xuanling, better known as Fang Xuanling (Chinese: 房玄齡), posthumously known as Duke Wenzhao of Liang, was a Chinese statesman and writer who served as a chancellor under Emperor Taizong in the early Tang dynasty. He was the lead editor of the historical record Book of Jin (covering the history of the Jin dynasty (266–420)) and one of the most celebrated Tang dynasty chancellors. He and his colleague, Du Ruhui, were often described as role models for chancellors in imperial China.
 Fang Xuanling was born in 579, shortly before the founding of the Sui dynasty in 581, during Sui's predecessor state, Northern Zhou. His great-grandfather Fang Yi (房翼) was a general, official, and hereditary count under the Northern Wei dynasty, and his grandfather Fang Xiong (房熊) was also an official. His father Fang Yanqian (房彥謙) was a county magistrate during the Sui dynasty.
 Fang Xuanling was said to be intelligent and well-learned in his youth, and particularly skillful at calligraphy. It was said that once, when he accompanied his father to the capital Chang'an, the state was peaceful, and the popular sentiment was that Sui would last a long time. However, Fang Xuanling secretly opined to his father:
 The emperor [i.e., Emperor Wen of Sui] had no accomplishments or virtues, and he gained his power by trickery. He did not think about long-term benefits for his descendants, and he allowed his sons to have no differences between the heir and the non-heirs. They therefore compete with each other and plot against each other, and they also compete in their wastefulness and luxuries. They will eventually kill each other, and the state will not be preserved. Even though everything is peaceful now, I expect its fall to be soon. Fang Yanqian was surprised by his son's opinion, which, however, eventually turned out to be prophetic. When he was 17, he was successful at the imperial examination, and he became a military officer. He particularly impressed the deputy minister of civil service, Gao Xiaoji (高孝基). However, it appeared that he did not serve long, as his father became ill, and the illness lasted 10 years, during which Fang Xuanling attended to him earnestly. After his father's death, he fasted for five days. He later became the magistrate of Xicheng County (隰城, in modern Lüliang, Shanxi).
 In 617, when the general Li Yuan rebelled against the rule of Emperor Wen's son Emperor Yang, one of Li Yuan's major generals was his son Li Shimin. Fang Xuanling went to Li Shimin's camp and offered his services. It was said that as soon as Li Shimin met Fang, they became like old friends, and Li Shimin invited him to serve on staff. Fang served Li Shimin faithfully, and wherever Li Shimin campaigned, while his staff members would collect treasures, Fang spent the time interviewing the people of the area and retained the capable people to add to Li Shimin's staff.
 In 618, after news arrived at Chang'an (which Li Yuan had taken in winter 617 and where he declared Emperor Yang's grandson Yang You the Prince of Dai emperor (as Emperor Gong)) that Emperor Yang had been killed in a coup at Jiangdu (江都, in modern Yangzhou, Jiangsu), led by the general Yuwen Huaji, Li Yuan had Yang You yield the throne to him, establishing the Tang dynasty as its Emperor Gaozu. He created Li Shimin, the Prince of Qin. Fang continued to serve on Li Shimin's staff.
 In 621, when Li Shimin defeated Tang's major enemy Wang Shichong the Emperor of Zheng and captured the Zheng capital Luoyang (which had served as Sui's eastern capital), it was said that he sent Fang to the offices of Sui's legislative and examination bureaus of government to try to preserve Sui archives, but Fang's mission turned out to be unsuccessful as the archives had already been destroyed by Wang.
 Later in 621, when Emperor Gaozu, awarding Li Shimin for his great accomplishments, bestowed on him the unprecedented title of "Grand General of Heavenly Tactics" (天策上將, Tiance Shangjiang), Li Shimin built a mansion where he housed those staff members with the best literary talent, supplying them with the best food and supplies and had them conduct research and writing. Fang was part of this establishment, along with, among others, the fellow future chancellors Du Ruhui and Xu Jingzong. When Du was subsequently commissioned as a prefectural secretary general, Fang told Li Shimin that Du was an uncommon talent that he should do everything he could to retain, and Li Shimin thus persuaded Emperor Gaozu to allow Du to remain on his staff. It was said that Fang was capable in planning and strategizing, but not decisive in his decisions, while Du was capable in making quick and correct decisions, and they divided their strategical responsibilities while on Li Shimin's staff in that manner. (This eventually led to the Chinese proverb "Fang plans and Du decides" (房謀杜斷, Fang mou Du duan), after they became renowned.)
 By 626, Li Shimin was locked in an intense rivalry with his older brother, Li Jiancheng the Crown Prince, and Fang and Du often suggested that he act first against Li Jiancheng. As both Li Jiancheng and another brother who supported Li Jiancheng, Li Yuanji the Prince of Qi, feared Fang's and Du's strategic capabilities, they falsely accused both Fang and Du and had them demoted out of Li Shimin's staff. In summer 626, when Li Shimin decided to act against Li Jiancheng and Li Yuanji, however, he summoned Fang and Du to his mansion. Fang and Du, initially fearing Emperor Gaozu's orders forbidding them to serve Li Shimin, declined. In anger, Li Shimin sent the general Yuchi Gong to summon Fang and Du, with directions if they declined again, to kill them. Yuchi, however, was able to persuade them that Li Shimin was in fact intending on acting against Li Jiancheng and Li Yuanji, and so Fang and Du put on disguises as Taoist monks and were able to get to Li Shimin's mansions, where they assisted Li Shimin in planning the ambush against Li Jiancheng and Li Yuanji. Li Shimin subsequently ambushed his brothers as Xuanwu Gate and killed them, and then effectively forced Emperor Gaozu to create him crown prince. Once he was created crown prince, Fang and Du were restored to honored positions on his staff, and soon, Fang was made the Zhongshu Ling (中書令) — the head of the legislative bureau and a post considered one for a chancellor. Two months later, Emperor Gaozu yielded the throne to Li Shimin (as Emperor Taizong).
 Later in 626, when Eastern Tujue's Jiali Khan Ashina Duobi launched a major incursion into Tang territory, reaching all the way to Chang'an, Fang Xuanling, along with Gao Shilian, attended to Emperor Taizong as he personally met Ashina Duobi to promise additional tributes, to induce Ashina Duobi to withdraw.
 Later in 626, when Emperor Taizong personally ranked the contributions of the generals and officials in order to grant them fiefs, Emperor Taizong ranked five of them — Fang, Zhangsun Wuji, Du Ruhui, Yuchi Gong, and Hou Junji to be contributors of the highest grade, and Fang was created the Duke of Han. When Emperor Gaozu's cousin Li Shentong (李神通) the Prince of Huai'an, himself a key general, objected to being ranked below Fang and Du, stating that Fang and Du, in particular, were only bureaucrats, Emperor Taizong pointed out that it was with their strategies that he was able to become emperor, Li Shentong relented, which led to the other objectors to also cease their objections. Later in 627, under Emperor Taizong's direction, Fang carried out a major simplification of the central government, reducing the number of officials at the central government to 634.
 In 629, Fang, along with Du, became Puye (僕射), the head of the important executive bureau of the government (尚書省, Shangshu Sheng). It was said that at this time that the Fang and Du became known as the model for chancellors. It was also said that Fang, even though he had reached the pinnacle of officials' careers, was still very humble before the emperor, and whenever he received a rebuke, he would act as if a disaster was coming. He also became responsible for organizing the imperial archives and the writing of official histories. Later that year, the assistant imperial censor Quan Wanji (權萬紀) accused Fang and Wang Gui of being partial in their selections of officials, and Emperor Taizong initially ordered Hou to investigate. However, with the urging of another chancellor, Wei Zheng, who pointed out that Fang and Wang were trusted officials given important responsibilities, and it was inappropriate to pick on details of what they did, Emperor Taizong stopped the investigation.
 In 630, when Emperor Taizong began to have his crown prince Li Chengqian formally rule on a number of matters of state, he commissioned Fang and Li Gang (李綱) to sit with the Crown Prince and assist him in making the decisions. Also in 630, his title was changed to Duke of Wei.
 In 636, for reasons unknown, Fang was briefly removed from his post and returned to his mansion. When Emperor Taizong's wife Empress Zhangsun (Zhangsun Wuji's sister) died later that year, she, in her final words, pointed out to Emperor Taiizong that Fang had faithfully served him throughout his career and should not be removed. After her death, Emperor Taizong restored Fang to his post.
 In 637, as part of Emperor Taizong's scheme to bestow prefectures on his relatives and great generals and officials as their permanent domains, Fang's title was changed to Duke of Liang, and he was given the post of prefect of Songzhou, to be inherited by his heirs, although he did not actually report to Songzhou but remained at Chang'an as chancellor. Soon, however, with many objections to the system, the strongest of which came from Zhangsun Wuji, Emperor Taizong cancelled the scheme, although Fang's title remained Duke of Liang.
 Also in 637, a major revision of the laws, led by Fang, was completed, and the penal laws were said to be far more lenient than the Sui penal code, on which Fang's revision was based, with 500 statutory sections and 20 grades of penalty. Also that year, the code of rites, authored by him and Wei Zheng, was also completed.
 In 638, Emperor Taizong, celebrating the birth of a grandson, held a feast for imperial officials, at which he made the comment:
 Before I took the throne, it was by Fang Xuangling's assistance that I was able to seize power. After I took the throne, it was by Wei Zheng's assistance that I was able to have my errors corrected. He then awarded both Fang and Wei an imperial sword.
 In 639, Emperor Taizong made Fang a senior advisor to Li Chengqian, ordering him to bow to Fang as he would to Emperor Taizong. However, Fang was humble and never gave the Crown Prince any opportunity to bow to him, an act of humility which was praised. By this point, Fang's children were also highly honored, and his second son Fang Yi'ai (房遺愛) married Emperor Taizong's daughter Princess Gaoyang, while his daughter married Emperor Taizong's brother Li Yuanjia (李元嘉) the Prince of Han.
 In 641, Fang and Gao Shilian drew rebuke from Emperor Taizong when they inquired the deputy imperial architect, Dou Desu (竇德素) of imperial construction projects — which Emperor Taizong saw as an encroachment on his liberty. However, Wei pointed out that chancellors were supposed to be responsible for all affairs of state, and Emperor Taizong, realizing that he had erred, was humbled.
 in 642, Fang was awarded the additional highly honorable title Sikong (司空) — one of the Three Excellencies. Later that year, when Emperor Taizong was debating whether  warring with Xueyantuo or making peace by marrying his daughter Princess Xinxing to Xueyantuo's Zhenzhu Khan Yi'nan, Fang was a proponent of peace, and Emperor Taizong agreed, although Emperor Taizong later changed his mind and broke the marriage treaty.
 In 643, when Emperor Taizong commissioned the Portraits at Lingyan Pavilion to commemorate the 24 great contributors to Tang rule, Fang's was one of the portraits commissioned.
 Later in 643, when Li Chengqian, fearing that Emperor Taizong would depose him in favor of his more favored brother Li Tai the Prince of Wei, was revealed to have plotted with Hou Junji to overthrow Emperor Taizong, Emperor Taizong had Zhangsun, Fang, Xiao Yu, Li Shiji, along with the responsible officials at the legislative and examination bureaus and the supreme court, investigate the matter. They confirmed Li Chengqian's guilt, and Li Chengqian was subsequently deposed, although Emperor Taizong, believing that Li Tai's machinations were responsible for Li Chengqian's downfall, exiled Li Tai as well and created another son, Li Zhi, crown prince. He subsequently made Zhangsun, Fang, and Xiao Li Zhi's senior advisors.
 Later that year, Emperor Taizong requested to read the official history that Fang had written about during his reign, and Fang initially resisted, stating that it would set a bad precedent (as previously, it was considered inappropriate for emperors to read histories of their own reign, lest that historians be hindered from recording incidents accurately). Emperor Taizong disagreed, and Fang thus submitted what he and his staff had written. Emperor Taizong noticed that Fang had avoided some of the more sensitive parts of the Incident at Xuanwu Gate, and he ordered Fang to write a more complete and less censored version.
 In 645, when Emperor Taizong personally led a campaign against Goguryeo, Fang was put in charge of the capital. It was said that there was an incident where a man approached Fang and stated, "I am here to report that you are committing treason."  Fang bound him and delivered him to Emperor Taizong. When the man arrived at Emperor Taizong's camp and accused Fang of treason, Emperor Taizong immediately executed the man and sent an edict to Fang, rebuking him for lack of confidence in himself, stating, "If something like this happens again, you should carry out the decisive act yourself."
 In or around 646, Fang was again, for reasons unknown in history but described to be minor reasons, removed from his post and returned to his mansion. After Chu Suiliang submitted a petition stating that Fang's faithfulness should not be forgotten, Emperor Taizong visited Fang's mansion – a visit that Fang anticipated and had cleaned his house for – and he had Fang accompany him on the imperial wagon back to palace. Fang was said to be so influential in Emperor Taizong's decision-making by this stage that an amusing incident occurred in 647, involving the official Li Wei (李緯). Emperor Taizong, then at his summer palace Cuiwei Palace (翠微宮, in the Qinling Mountains), leaving Fang again in charge of Chang'an, had commissioned Li Wei as the minister of finances. When a messenger arrived from Chang'an, Emperor Taizong asked the messenger what Fang had said about Li Wei, and the messenger responded, "When Fang Xuanling heard that Li Wei was made a minister, all he stated was, 'Li Wei has a handsome beard.'"  Emperor Taizong, realizing that Fang was making a veiled comment that Li was not a proper minister, demoted Li Wei to the post of prefect of Luo Prefecture (洛州, roughly Luoyang).
 In 648, the Book of Jin, the official history of Jin dynasty, with Fang as its lead editor, was completed. Also in 648, when Emperor Taizong was at another summer palace, Yuhua Palace (玉華宮, in modern Tongchuan, Shaanxi), he again left Fang in charge of Chang'an, when Fang grew ill. Emperor Taizong summoned him to Yuhua Palace and had the imperial servants attend to him. For a while, Fang got better, and then grew worse. In his illness, Fang believed that the only danger that the empire faced at that point was Emperor Taizong's anger at Goguryeo, and therefore wrote an earnest petition urging the cessation of campaigns against Goguryeo. When Emperor Taizong saw the petition, he stated to Princess Gaoyang, "He is this ill, and yet he still worries so much about my empire."  He personally visited Fang to bid farewell, and in fall 649, Fang died at Yuhua Palace and was buried near Empress Zhangsun's tomb (where Emperor Taizong would eventually himself be buried as well).
 The Tang dynasty historian Liu Fang (柳芳) made these comments about Fang and Du Ruhui:
 Fang Xuanling assisted Emperor Taizong in conquering and pacifying the empire for 32 years, finally serving as chancellor. The people all called him an excellent chancellor, but could not think of his personal contributions. This showed how virtuous he was. Emperor Taizong pacified the disturbances, and Fang and Du did not refer to their own accomplishments; Wang Gui and Wei Zheng earnestly made suggestions to the emperor and Fang and Du praised them for their honesty; Li Shiji and Li Jing fought everywhere and won battles, and Fang and Du assisted them greatly on the political front. They brought peace for their time and they gave all their glory to the emperor. Is it not appropriate to refer to them as great contributors of Tang? However, the honors the Fang clan received would not last long after Fang Xuanling's death. Emperor Taizong himself died in 649 and was succeeded by Li Zhi (as Emperor Gaozong). In 653, Fang Yi'ai and Princess Gaoyang were accused of plotting, along with the general Xue Wanche (薛萬徹), Emperor Gaozong's uncle Li Yuanjing (李元景) the Prince of Jing, Li Ke the Prince of Wu, and another brother-in-law of Emperor Gaozong, Chai Lingwu (柴令武), to overthrow Emperor Gaozong and making Li Yuanjing emperor. Fang Yi'ai was executed, and his older brother Fang Yizhi (房遺直) was demoted to be a county sheriff in modern Guangdong. Fang Xuanling, whom Emperor Gaozong had ordered to be worshipped at the imperial shrine with Emperor Taizong, was removed from the imperial shrine.