During this period, he started writing literature, mostly poetry, under the influence of Romantic and post-Romantic poets such as France Prešeren, Heinrich Heine, Simon Jenko and Simon Gregorčič. In 1893, he discovered the epic poetry of Anton Aškerc, which had a huge influence on the development of his style and ideals. Under Aškerc's influence, Cankar rejected the sentimental post-Romantic poetry and embraced literary realism and political national liberalism.
In 1896, he enrolled at the University of Vienna, where he studied engineering, but later switched to Slavic philology. In Vienna, he soon started to lead a bohemian lifestyle. He came under the influence of contemporary European literature, especially decadentism, symbolism and naturalism. He became friends with Fran Govekar, a young Slovene writer and intellectual living in Vienna, who introduced him to positivism and naturalism. In the spring of 1897 he moved back to Vrhnika. After his mother's death in autumn of the same year, he moved to Pula and in 1898 back to Vienna, where he lived until 1909.
During his second stay in Vienna, Cankar's worldview underwent a deep change. In a famous letter to the Slovene feminist author Zofka Kveder in 1900 he rejected positivism and naturalism. He embraced spiritualism, symbolism and idealism, and later publicly broke with Fran Govekar. At the same time, he became highly critical of Slovene liberalism, published a devastating criticism of Anton Aškerc's poetry and gradually moved towards socialism. He was strongly influenced by the Slovene Roman Catholic priest and thinker Janez Evangelist Krek, who advocated radical social activism on a Christian basis. He nevertheless continued to oppose the clericalism and conservativism of Austrian Christian socialists in general and Krek's Slovene People's Party in particular. He joined the Yugoslav Social Democratic Party, an Austro-Marxist party active in the Slovene Lands and in Istria. In the first general elections to the Austrian Parliament in 1907, he ran as a candidate for the party in the largely working-class electoral district of Zagorje-Litija in Carniola, but lost to a candidate of the Slovene People's Party.
In 1909, he left Vienna and moved to Sarajevo in Bosnia and Hercegovina, where his brother Karlo worked as a priest. The same year, he settled in the Rožnik district of Ljubljana. Although he remained an active member of the Yugoslav Social Democratic Party, he rejected the party's view on Yugoslav nation-building: in a resolution in 1909, the Party favoured a gradual unification of Slovene culture and language with the Serbo-Croatian ones in order to create a common Yugoslav nation. Cankar, on the other hand, strongly defended the national and linguistic individuality of Slovenes. Already after his electoral defeat in 1907, Cankar had started to publish numerous essays explaining his political and esthetical views and opinions. After his return to Carniola in 1909, he began travelling throughout the Slovene Lands, delivering lectures and conferences. The most famous of these lectures were "The Slovene people and the Slovene culture" (Slovensko ljudstvo in slovenska kultura), delivered in Trieste in 1907, and "Slovenes and Yugoslavs" (Slovenci in Jugoslovani), delivered in Ljubljana in 1913. In the latter, Cankar expressed a favourable opinion on the political unification of all South Slavs, but rejected a cultural merger of South Slavic peoples. Because of the lecture, he was sentenced to one week in prison for defamation of the Austro-Hungarian Monarchy. After the outbreak of World War I in 1914, he was again imprisoned in the Ljubljana Castle for supposed pro-Serbian attitudes, but was soon released. In 1917, he was drafted in the Austro-Hungarian Army, but was demobilized due to poor health. In his last lecture, delivered in the National Club of Trieste just after the end of the War, he called for a moral purification and rejuvenation of Slovene politics and culture. He moved from Rožnik to the center of Ljubljana, where he died in December 1918. His funeral was attended by a huge crowd and highest representatives from the cultural and political life in Slovenia. In 1936, his grave was moved to the Žale cemetery in Ljubljana, where he was buried next to his youth friends and fellow authors Dragotin Kette and Josip Murn.
Ivan Cankar wrote around 30 books and is considered one of the primary exponents of Slovene modernist literature, alongside Oton Župančič, Dragotin Kette and Josip Murn. Cankar is also considered one of Europe's most important fin de siècle. He dealt with social, national and moral themes. In Slovenia, his best-known works are the play Hlapci ("Serfs"), the satire Pohujšanje v dolini Šentflorijanski ("Scandal in the St. Florian Valley") and the novel Na klancu ("On the Hill"). However, his importance for Slovene and European literature probably lies in his symbolist sketches and other short stories, which, in their mixture of symbolism, modernism and even expressionism, convey a high degree of originality.
Cankar started as a poet. He published his first poems already as a teenager in the prestigious liberal literary magazine Ljubljanski zvon. In Vienna, he frequented a group of young Slovene artists and authors, among whom were Oton Župančič, Fran Eller and Fran Govekar, who introduced him to the modernist currents of European literature. In 1899, Cankar published his first collection of poetry under the title Erotika. Decadentist and sensualist influences were evident and the then bishop of Ljubljana Anton Bonaventura Jeglič was so scandalized by the book that he bought all the copies and ordered their destruction. Another edition was issued three years later, but by that time Cankar had already abandoned poetry and moved to engaged literature. In 1902, he wrote his first play Za narodov blagor ("For the Welfare of the Nation"), which was a violent parody of the liberal nationalist elite in the Slovene Lands, especially in Carniola. The same year, he published the short novel Na klancu ("On the Hill"), in which he described the misery of the small rural proletariat and the poor material and spiritual conditions of the common people. The novel, which still showed strong naturalistic features, combined with allegorical symbolism and an unusual, biblically inspired style, gained him widespread recognition.
In the novels Gospa Judit ("Madame Judit") and Hiša Marije Pomočnice ("House of Our Lady of Mercy") and Križ na gori ("Cross on the Mountain"), all published in 1904, he turned to spiritualism and idealism, maintaining as central theme the oppressed people and their yearning for a better life. In 1906, he wrote the short novel Martin Kačur with the subtitle "The Life Story of an Idealist", which is a ruthless analysis and self-analysis of the failure of an abstract idealist. During the general elections of 1907, he published the short story Hlapec Jernej in njegova pravica ("The Servant Jernej and His Right"), in which he describes a clash between the individual worker and both the capitalist and traditional society, the laws of which he cannot understand. Following the electoral victory of the Slovene People's Party, he wrote his most influential play, the satire Hlapci ("Serfs"), in which he satirized the conformism of the former progressive and agnostic public servants who embraced Catholicism after the defeat of the liberal party. Both the liberal and the Catholic conservative parties in the Slovene Lands reacted acrimoniously against the play: its staging was delayed until after Austria-Hungary's dissolution in Autumn 1918. In the play Pohujšanje v dolini Šentflorjanski ("Scandal in the St. Florian Valley"), Cankar made fun of the moral rigidness and culturally backward mentality of Carniola's small semi-urban society.
Cankar was also famous for his essays, most of which were published between 1907 and 1913, where he showed stylistic mastery great irony.
His last collection of short stories, entitled Podobe iz sanj ("Images from Dreams"), which were published posthumously in 1920, is a magically realistic and allegorical depiction of the horrors of World War I. It shows a clear move from symbolism to expressionism and it has been regarded as the finest example of Cankar's poetic prose.
Cankar was educated as a devout Roman Catholic. In his high school years, he became a typical liberal freethinker. He rejected the religious dogmas and embraced the rational explanations provided by contemporary natural and social sciences. Between 1898 and 1902, he fell under the influence of the thinkers Ralph Waldo Emerson and Friedrich Nietzsche. In the writings of the Belgian poet Maurice Maeterlinck Cankar found the idea of the existence of a world soul, with which the individual souls are connected and employed it in his own works. Already around 1903, however, he turned to an original, slightly anarchist interpretation of Marxism. His later life was marked by a gradual evolution towards orthodox Christianity, which became evident after 1910 and especially in the last year of his life. Although he never officially rejected his Roman Catholic faith, he was generally considered an agnostic, albeit sympathetic to some elements of traditional Catholic devotion.
Cankar was an influential author already during his lifetime. His works were widely read and Cankar was the first author in Slovene language who could make a living exclusively from writing. He became even more influential after his death. Due to his insistence on the cultural and national specificity of the Slovene people, Cankar became the referential figure for the young generations of Slovene intellectuals who rejected the centralistic and unitaristic policies of the Serb political elite in the Kingdom of Yugoslavia. In the early 1920s, a group of young Catholics, mostly of Christian Socialist convictions, took the title of one of Cankar's minor novels, Križ na gori ("Cross on the Mountain"), as the name of their journal. The group, known as "Crusaders" (Križarji), became the focal point in the emergence of the Christian left in Slovenia in the 1920s and 1930s.
Cankar's work and his personal world view influenced all three major literary trends in Slovene literature between 1918 and 1945: the expressionism of Catholic authors (Ivan Pregelj, Stanko Majcen, France Bevk) the social realism of the liberal left and Marxist authors (particularly Miško Kranjec, Prežihov Voranc, Ciril Kosmač, and Mile Klopčič) and the avantgardism of Anton Podbevšek and Srečko Kosovel. During the same period, Cankar's political ideas influenced the Slovene social-democratic ideologist Etbin Kristan, the Christian Democratic political theorist Andrej Gosar and the democratic thinkers Albin Prepeluh and Dragotin Lončar. Cankar's psychological introspections became a major source of Edvard Kocbek's and Anton Trstenjak's inquiry in the Slovene national character.
During the dictature of King Alexander (1929-1934), Cankar's works were removed from the school curriculum, because he was considered a dangerous advocate of Slovene particularism and nationalism. After 1935, his status as one of the greatest Slovene writers was never put under serious question. In 1937, the first integral collection of Cankar's work was published, edited and annotated by his cousin and conservative literary historian and critic Izidor Cankar. After World War II, the publishing house Cankarjeva založba ("Cankar's Publishing House") was established, which took care of the edition of his collected works.
Cankar was especially influential as a playwright. He is considered the father of modern Slovene theatre and has had a major influence on almost all Slovene playwrights thereafter, starting from the expressionist theatre of the 1920s (Slavko Grum, Stanko Majcen). Between the 1950s and 1970s, most of the modernisators of Slovene theatre, such as Jože Javoršek, Dominik Smole, Marjan Rožanc, Primož Kozak, and Bojan Štih, have been influenced by Cankar's plays. The works of many contemporary Slovene playwrights and screenwriters, including Drago Jančar, Dušan Jovanović, Tone Partljič and Žarko Petan, continue to show a clear influence of Cankar's concepts.
Already during his lifetime, his works were translated into German, Czech, Serbian, Croatian, Finnish and Russian. Later, his work has been translated also into French, English, Italian, Hungarian, Romanian, Polish, Slovak, Bulgarian, Macedonian, Albanian and Turkish. Cankar's influence outside the Slovene-speaking area has been small, although his work did influence some non-Slovene authors, such as the French Henri Bordeaux, who also published an essay on Cankar in the 1920s, the Austrian Josef Friedrich Perkonig and the Italian Fulvio Tomizza. According to the testimony of the literary critic Josip Vidmar, Cankar's novel "The House of Our Lady of Mercy" was well received by the famous German writer Thomas Mann, who helped to publish a German edition in 1930.
Numerous streets, squares, public buildings and institutions have been named after Ivan Cankar. During World War II, two military units of the Partisan resistance, the Cankar brigade and the legendary Cankar batallion, were named after him. Since the 1980s, Slovenia largest congress centre, the Cankarjev dom in Ljubljana, has borne his name. Between June 1994 and January 2007, Cankar was portrayed on the 10,000 Slovenian tolar bill.