HTML is called a markup language for a very good reason: It grabs ordinary, normal text and inserts various strings into that text to define, organize, and manage the flow and sequence of content on web pages.
The inserted strings define the markup, which web browsers — or other special programs known as user agents — pore over and use (along with CSS, of course) to guide their display of the content included.
Like any language, HTML is subject to a specific syntax, which defines the order in which markup must or can appear in a web page. There are also lots of interesting rules about what kinds of markup is legal in certain places but illegal in others. This may seem like a difficult concept, but these restrictions in HTML illustrate what this means and why it makes very good sense:
The
element is for providing a caption for a table. Thus it can appear only inside markup. If you want to provide a caption for a figure, you must use the
element instead. You need to employ the right markup for the right uses in HTML. HTML recognizes various kinds of lists, which can organize text items with numbers or bullets, as the markup directs. List items employ the tags to identify individual items in such lists. That’s why those particular tags are legal only if they occur within some kind of list element, such as
HTML supports all kinds of fields and input controls for online forms. As with tables, forms-related elements can appear only inside a pair of tags.
There are lots of forms-related elements and attributes that can appear only in such a context. These include numerous input types, various kinds of text boxes, button controls, and more. All of them are legal only in a form, so they must occur between and on a web page if they are to work.
Understanding HTML largely boils down to grasping how to create the markup it uses (that’s the syntax) and understanding the order (or context) in which individual markup elements may appear.
Those are the rules for creating valid or legal HTML. The same observations are true for CSS also, by the way, except that the syntax and the rules for its expression are different because CSS is a different markup language from HTML.