Cao Fang 曹芳 (r. 239-254), courtesy name Lanqing 蘭卿, was a ruler of the Cao-Wei dynasty 曹魏 (220-265). He was a foster-son of Emperor Ming 魏明帝 (r. 226-239 CE) and followed the latter to the throne because of his status as Prince of Qi 齊. At that time he was not more than 8 sui old, so that Emperor Ming had appointed General-in-chief (da jiangjun 大將軍) Cao Shuang 曹爽 and Defender-in-chief (taiwei 太尉) Sima Yi 司馬懿 as regents. Lady Zhen 甄氏 became empress.
In 246 Cao Fang proclaimed a law that liberated all debt slaves older than 70 sui with the promise that those not able to nourish themselves were to be supported by the state. Cao Shuang soon was able to usurp power and appointed his favourites like He Yan 何晏 or Ding Mi 丁謐 to ministerial posts. Sima Yi withdrew from government and secretly prepared his comeback.
In 249, when the emperor and Cao Shuang visited the tomb of Emperor Ming, Sima Yi occupied the capital Luoyang 洛陽 (modern Luoyang, Henan), killed Cao Shuang and his ministers and factually usurped the government of the Wei empire. In 251 Grand protector Wang Ling 王淩 rebelled with the intention to enthrone Cao Biao 曹彪, the Prince of Chu 楚, as emperor, and to get rid of the powerful Sima family. Yet was defeated and committed suicide, along with Cao Biao. In order to have a better control over the princes, Sima Yi ordered them to take residence in Yezhong 鄴中 (modern Linzhang 臨漳, Hebei) where they were put under the strict control of a censor.
When Sima Yi died his son Sima Shi 司馬師 assumed power, while Cao Fang was, like before only nominally the ruler. In 254 Sima Shi decided to demote Cao Fang to Prince of Qi again and to replaced him with Cao Mao 曹髦, Duke of Gaoguixiang 高貴鄉公, a grandson of Emperor Wen 魏文帝 (r. 220-226). Formally, this was done by an edict proclaimed by the Empress Dowager with the charge of insolence. When Sima Yan later ended the Wei and founded the Jin dynasty 晉 (265-420), Cao Fang was further demoted to Duke of Shaolingxian 邵陵縣公. He died in 274 and has been given the posthumous title of Duke Li of Shaolingxian 邵陵縣厲公.