It is not illegal to view pornography. It is illegal to possess or receive certain kinds of pornography, namely child porn, under 18 USC 2252 and 18 USC 2252a (there is a subtle legal difference between "child pornography" and "visual depiction (which) involves the use of a minor engaging in sexually explicit conduct"). In order to view anything on the internet, you have to first receive it, so there is potential criminal liability. These sections allows one affirmative defense, if one
knowingly possesses, or knowingly accesses with intent to view, any
book, magazine, periodical, film, videotape, computer disk, or any
other material that contains an image of child pornography that has
been mailed, or shipped or transported using any means or facility of
interstate or foreign commerce or in or affecting interstate or
foreign commerce by any means, including by computer, or that was
produced using materials that have been mailed, or shipped or
transported in or affecting interstate or foreign commerce by any
means, including by computer;
(1) possessed less than three images of child pornography; and
(2) promptly and in good faith, and without retaining or allowing any
person, other than a law enforcement agency, to access any image or
(A) took reasonable steps to destroy each such image; or
(B) reported the matter to a law enforcement agency and afforded that
agency access to each such image.
A person's belief that the website was moderated is not a defense.
There are also state statutes, typically stronger, which outlaw possession of child porn. Crabtree v. Kentucky is an example of such a (successful) conviction. The court addresses the question of whether "merely viewing" can constitute actual possession: the court found that it did:
Crabtree urges us to consider that his merely viewing child
pornography images before deleting them should not be deemed to
constitute actual possession. After reviewing the facts of this case,
we are not persuaded that this is a valid argument in light of the
Ninth Circuit's definition of possession in Romm, supra: that the act
of seeking out child pornography and exercising control over it
constitutes criminal possession—regardless of whether it is
downloaded. Crabtree admitted to seeking out the material and to
having it on his computer.
It would be impractical to try to review 50 states' worth of child porn laws plus the federal statute, but there is also a “Temporary innocent possession” defense, which is conceivably applicable to the situation where you click a link and surprise! In the above case, defendant had to click a link that indicated the nature of the contents, and had to confirm file-saving of a file whose name was indicative of its content. Such circumstances overrule the presumption of temporary innocent possession.
A question raised in the comments is whether a porn-ambush could lead to a conviction. Suppose that a web page has a number of embedded child-porn images which are saved to a user's computer without his knowledge. As pointed out in this report of the US Sentencing Commission,
A conviction for receipt, however, requires proof beyond a reasonable
doubt that a defendant knowingly came into possession of child
pornography at the time that the image or video was received
with case law citations. The case of US v. Kuchinski, 469 F. 3d 853 is instructive, because defendant did knowingly seek out and download a number of child porn images, and was convicted. In 94 of those cases, he knew he was receiving child pornography; in over 10,000 other cases, such images were found in his system cache (this is relevant to sentencing). The court found that it matters that "Kuchinski had no knowledge of the images that were simply in the cache files", and the court concluded, in K's favor, that
Where a defendant lacks knowledge about the cache files, and
concomitantly lacks access to and control over those files, it is not
proper to charge him with possession and control of the child
pornography images located in those files, without some other
indication of dominion and control over the images. To do so turns
abysmal ignorance into knowledge and a less than valetudinarian grasp
into dominion and control.
Do you know about the system cache, and do you know how to control it? If not, you might avoid the charge.
In other words, it depends on the circumstances surrounding the possession and the evidence of a knowing act, as well as the jurisdiction.