It varies dramatically depending on type of class. For example, the first of the 4 Harvard classes that permits simultaneously enrollment without stipulation is CS 50 – Introduction to CS. This class has an enrollment of 1,600 in-class students and ~40,000 virtual students. According to HarvardX: CS50's Introduction to Computer Science | edX , 7 million students have enrolled in CS 50X on edX.
Intro to CS apparently works okay as a large lecture without a lot of direct back and forth from professor during the lecture. The more personal interaction occurs during sections, which I expect are led by grad students. I’m more familiar with Stanford’s intro CS class, which sounds like it uses a similar approach. CS 106A is one of Stanford’s ~2 largest courses, with similar enrollment to the 1,600 in-class students in Harvard’s class per year. However, sections are limited to a maximum enrollment of ~6 students per section as I recall, giving students an opportunity for more personal attentions and questions in what is often their first CS class. Sections get larger for other CS classes. It’s more important to attend section in person (CS 50 has some sections over Zoom) than it is the lecture.
Upper level humanities and social science classes tend to be much smaller and often involve discussing readings with professors, with direct interactions. These types of classes seem more critical to attend in person than the intro to CS example above.
In my opinion, much of class attendance stems from the professor. If the professor offers a class for which in-class attendance is important, then the class can be structured such that students are penalized in some way for not attending class. This doesn’t necessarily mean taking attendance, which often isn’t practical and can be a waste of everyone’s time. The professor can instead have in-class activities that are influential on the student’s grade, either directly or indirectly.