This isn't a page about how to code websites, but information about how they work. I've been writing websites for two decades, this is a summary of what I've discovered for myself, from writing sites, from using other people's websites, from analysing the access logs of my webserver, as well as what's been discussed with other webmasters.
If you're about to create a website, you have to think who and what it's for. In particular, thinking about whether the site is for yourself, or for others (does it serve yourself, a group you're part of, or is it information for everyone else).
And in my experience, there's two main types of websites: (a) There's the useful and useable website. (b) And then there's the pretty useless website (it's been made to look pretty, but it's also rather useless; whether that's due to being devoid of information that people wanted to find out, or it being next to impossible to find it).
I should probably add a third kind, (c) the deceptive type. The kind that's some kind of exploitation, whether that's the malicious kind, or just commercial. In either case the site hooks you in by offering something you sought (or pretends to offer it), but it's really just bait to get you to look at the what they're actually trying to do. Accuracy, facts, even safety, are not their concern, they just want to trick you. That type of dishonesty is very different from an genuine advertisement website (a site that's directly about a thing, you visit it on purpose because you actually wanted to).
There's generally three ways that people come across a website:
They've searched for an answer to a something, maybe just from a keyword, or they've actually asked a question, and a search engine has returned a page from your website in its list of results.
And generally it is going to be a link to a page within your site, the one which seems most pertinent to their query. It's not going to be a general link to your homepage for them to try and find their answer by exploring your website. This is why it's important to type your pages well, title them appropriately, and organise things logically; because search engines are not magic, and people do not like to use frustrating websites. While you may see some search results with mainpage links at the top of a google search, it's important to remember that they're paid advertisements. General search results point to individual pages as standalone material.
In general, search engines find a website by following links to it from other websites that they've already visited. How those other sites refer to you, and how many other websites refer to you, affects how search engines catalogue you. And links to you from dodgy sites (such as search engine optimising spam sites) will negatively affect you.
Search engines catalogue individual pages, rather than lump an entire website together as one object. They will read the text in links pointing to a webpage, they'll look at titles and headings on those pages, and the main body content. All of that will be used to catalogue a page. And they'll step through a site, following all the links that they can. Things that corroborate each other (e.g. titles being appropriate for their associated content) should increase the ranking, attempts to game the system will negatively affect it. And flashy websites that make machine navigation of the site difficult will negatively affect ranking, too.
Writing all of those things (link names, page titles and headings, etc), in a coherent and logical manner is called search engine optimisation (SEO). It's a service that some people will fleece money from you for, but you can do it yourself. All you have to do is write pages well, and use the terminology that people are likely to search for (as well as using the correct terminology, of course). One thing a genuine SEO service could help you with (that's if you can actually find a genuine one), is discovering alternative terms that people might search for, ones that you didn't think of. Though search engines are getting better at this, by themselves (finding useful results for you when you use search words that are related to a site, but might not actually be used within it).
Once they get there, people often only look at one page, the one they landed on. If that page is unrelated to their query, and doesn't appear to link to something that does, they're quite likely to immediately leave your site and go elsewhere (this is why pages have to be authored well, individually). And if their search leads them to the page with the answer, they've got what they want, and probably don't have much reason to look around. If they're interested in what you offer, then the next thing they look for is likely to be your contact details. Make them easy to find.
The trick is to ensure that one page fully satisfies their needs, don't make people needlessly plod about because you want to snare them in your website. Dedicate a page to a topic, don't fill a page with multiple unrelated things, don't spread a topic across multiple pages unless it's actually useful to do so (e.g. related subsections of a lengthy matter, where you deal with each subsection on a page, each subsection works well as a standalone document, and the subsections link with each other in a sensible manner).
If your site has other things that are likely to be of interest to your reader, then make sure that it's easy to see what else is on offer, that it's easy to navigate there, and it's easy to get back to where they started from (your navigation links need to be coherent, and should not prevent them using the back button on their browser). Typically, people explore websites by trying a link, then going back to a previous page. If you want to encourage someone to wander through your website, it should be by offering other content that's interesting.
Where possible, websites should be made useful for everyone, not just to a limited set of conditions. For example:
The web is also used by people with visual disabilites, they may listen to websites, they may view websites with extreme magnification, or modified colours. Convoluted and image-dependent layouts are hostile. Search engines are essentially blind, you can cater for everyone by creating websites accordingly.
Many people browse with scripting blocked. Some do it for security reasons, some do it to remove cruft from websites (annoying advertising, mainly), some do it so their browser doesn't grind to a halt with badly coded sites. And some web browsers simply don't support some scripting features. Again, search engines have limited support for scripting, and you cater for everyone when you limit its use.
More and more people use smart phones and tablets. They don't have a mouse, they use a touch screen. Some navigational tricks are hard to use without a mouse, likewise it's hard to pick individual links when they're closely crammed together.
What's wrong with pretty websites? Nothing, in itself. You just need to ensure you don't do it at the expense of being useful. While a website like YouTube can make it's appearance a very high priority, it still has to actually do what people want from it, and should not be painful to use.
Informational websites need to make useability a prime consideration. Your appearance didn't bring someone to your website, information did. Good information and useability keeps them there. Prettiness should be done as an enhancement, it should never get in the way. And in today's environment of small touchscreen devices, complex designs are even more difficult to use.
Arguably, the world's most useful website is Google. It's main interface has embraced minimalism. By contrast, some of the other search engines are horrendous to use. You went to them for one reason (to find something), but that function is crowded out by a plethora of other irritating things that you didn't go there for.
End of page content, site navigation links follow.