I am looking for the first work of science fiction in which no character is an earthling and Earth is never mentioned or referred to, even indirectly.
Star Wars would be an example of such a work.
Science Fiction & Fantasy Stack Exchange is a question and answer site for science fiction and fantasy enthusiasts. It only takes a minute to sign up.Sign up to join this community
It may not be the first--it's not nearly as old as HorusKol's suggested Flatland--but it's undeniably genre sci-fi, and there is hardly any mention of organic life forms, and nothing at all about Earth or Earthlings. "Into the Darkness" by Ross Rocklynne, the first story in his Darkness series, was first published in the June 1940 Astonishing Stories, available at the Internet Archive. The characters are gigantic energy beings, and the hero of the story is a young energy being named Darkness:
Darkness played. He played for many millions of years. With playmates of his own age, he roamed through the endless numbers of galaxies that composed the universe. From one end to another he dashed in a reckless obedience to Oldster's command.
He explored the surfaces of stars, often disrupting them into fragments, sending scalding geysers of belching flame millions of miles into space. He followed his companions into the swirling depths of the green-hued nebulae that hung in intergalactic space. But to disturb these mighty creations of nature was impossible. Majestically they rolled around and around, or coiled into spirals, or at times condensed into matter that formed beautiful, hot suns.
Energy to feed on was rampant here, but so densely and widely was it distributed that he and his comrades could not even dream of absorbing more than a trillionth part of it in all of their lives.
He learned the mysteries of the forty-seven bands of hyperspace. He learned to snap into them or out again into the first or true band at will. He knew the delights of blackness impenetrable in the fifteenth band, of a queerly illusory multiple existence in the twenty-third, and an equally strange sensation of speeding away from himself in an opposite direction in the thirty-first, and of the forty-seventh, where all space turned into a nightmarish concoction of cubistic suns and galaxies.
Incomprehensible were those forty-seven bands. They were coexistent in space, yet they were separated from each other by a means which no one had ever discovered. In each band were unmistakable signs that it was the same universe. Darkness only knew that each band was one of forty-seven subtly differing faces which the universe possessed, and the powers of his mind experienced no difficulty in allowing him to cross the unseen bridges which spanned the gulfs between them.
But the end of all that came, as he supposed it would. He played, and loved all this, until. . . .
He had come to his fifty-millionth year, still a youth. The purple globe in his core could have swallowed a sun a million miles in diameter, and his whole body could have displaced fifty suns of that size. For a period of a hundred thousand years he lay asleep in the seventh band, where a soft, colorless light pervaded the universe.
He awoke, and was about to transfer himself to the first band and rejoin the children of Radiant, Light-year, Great Power and all those others.
He stopped, almost dumbfounded, for a sudden, overwhelming antipathy for companionship had come over him. He discovered, indeed, that he never wanted to join his friends again. While he had slept, a metamorphosis had come about, and he was as alienated from his playmates as if he had never known them.
What had caused it? Something. Perhaps, long before his years, he had passed into the adult stage of mind. Now he was rebelling against the friendships which meant nothing more than futile play.
Play! Bouncing huge suns around like rubber balls, and then tearing them up into solar systems; chasing one another up the scale through the forty-seven bands, and back again; darting about in the immense spaces between galaxies, rendering themselves invisible by expanding to ten times normal size.
That is a very rare but not unknown type of story.
I believe that Boy's Life had a story with totally alien setting and characters back around 1960.
(added 08/01/15) - "Get Out of My Sky" James Blish Astounding Science Fiction 1956,1957 reprinted in Get Out of My Sky 1960, Get out of My sky and There Shall be no darkness 1980, In This World, or Another 2003, Flights of Eagles 2009.
Arthur C. Clarke wrote a story about centaur-like aliens on a distant planet with no mentions of Earth or Humans, but I forget the title and date; anyway it was probably a decade or two after Asimov's "Nightfall" and Rocklynne's "Darkness". (08/01/15 - probably "Second dawn", 1951)
"Cabin Boy" (1951) by Damon Knight, No it does have Human characters and mention of Earth - I remembered it wrong..1https://archive.org/stream/galaxymagazine-1951-09/Galaxy_1951_09#page/n115/mode/2up
Asimov "Nightfall" (1941)" previously mentioned by User14111.
Ross Rocklynne "Into the Darkness" (1940) mentioned by User14111.
(added 08/10/15) Milton A. Rothman's "Heavy Planet" Astounding August 1939. All the characters are natives of Heavyplanet in a solar system with five planets. The wrecked spaceship has a map of a solar system with nine planets, so it MIGHT be from Earth, but neither Earth nor Humans are identified or named in the story.
Harry Hasse's "He Who Shrank" (Amazing Stories 1936) may have the title character tell his story to an Earth Human but is otherwise set in totally alien settings.
In Profiles of the Future (1962) Clarke mentioned reading a series of science fiction short stories with sentient subatomic particles. The protagonists were a positron and electron named Posy and Negy who fell in love and wanted to get together. Even if Posy and Negy were supposed to be on Earth they shouldn't have any knowledge of it or Humans. (08/01/15) The series began with "The Romance of Posi and Nega" Joseph W. Skidmore Amazing September 1932.
Thus there may be other totally unearthly science fiction stories earlier than Rocklyne's "Darkness".
There might even be something earlier than Flatland (1884) dealing with angels or other supernatural beings or with aliens which do not mention Earth or Humans.
I would like to suggest the possibility of ""Heavy Planet".
Milton A. Rothman's "Heavy Planet" Astounding August 1939. All the characters are natives of Heavyplanet in a solar system with five planets. The wrecked spaceship has a map of a solar system with nine planets, so it MIGHT be from Earth, but neither Earth nor Humans are identified or named in the story.
It is later than Flatland and the Posi and Nega stories. But if you don't count geometric figures or subatomic particles as science fiction characters but consider them fantasy characters instead, "Heavy Planet" (1939) is the earliest story listed so far with nonhuman biological alien characters living in an unidentified alien solar system, a couple of years before "Nightfall".
The wrecked spaceship could be from Earth, but the remains of its crew are unidentifiable, and Earth is not mentioned in the story.