# Explaining basic html structure

I am trying to think of a lesson plan about html, and I am looking for a good way to explain the concept of the structure of an html file.

I was wondering whether the subject would be better understood if I firstly described xml in general. What I had in mind is teaching a basic xml block:

<rootElement>
<element withAttribute="that we can set" scndAttr="there can be more than 1 attribute">
<subElement otherAttr="these can also have attributes" />
</element>
</rootElement>


and then use this basic block to get into the subject, after which we veer off to html specific xmls.

The students are at a beginner's level, and HTML is the first technology with a structure like this that they will encounter, So this lesson is meant to introduce them to HTML.

So, is knowing the concept and basics of xml structure important and necessary for understanding html?

• What level is this? Are the students familiar with more abstract structures? – wythagoras May 24 '17 at 6:53
• @wythagoras their level is the most basic java. By that I mean only Scanner and the simplest of things. I will update the question to add this information. – ItamarG3 May 24 '17 at 6:54
• Do you teach the DOM? I found that the tree-like structure and the accompanying visualization helped illustrate how HTML works. – Peter May 26 '17 at 0:52
• @Peter I didn't think about showing it like that. Thanks – ItamarG3 May 26 '17 at 11:08
• Explain the structure: opening and closing tags; nesting (Russian dolls). Then use an editor that automatically adds closing tags, and indentation. – ctrl-alt-delor May 28 '17 at 12:01

How did you begin to teach Java to your students? I bet you didn't start by showing them the Backus-Naur form that the Java parser follows. Instead, you probably introduced a simple "Hello, world" program, and slowly built on that with assignments and projects for the students to work on.

I'm sure you can see the parallel here—teaching XML as a prerequisite for HTML is not, in my opinion, a productive or helpful exercise. XML is a rather boring language; it doesn't do anything, so you don't get that instant feedback when you write some code, unlike in HTML, where you can see the webpage unfold as you add elements.

HTML is also simple enough that you can generally pick it up as you go along; explaining that you start an element with <tag> and end with </tag> should be simple enough, and any mistakes in the markup will be visible when you load the page.

As a general rule, if you want to teach [insert language here], you probably don't need to teach a different language first; teaching XML to make HTML easier probably won't give you the benefits you're expecting.

I'm rather partial to the typical "Hello, world" for HTML. Almost certainly, your students will spot that the title is "My First Webpage", and I imagine that they'll be able to guess <h1> with some guidance.

<html>
<title>My First Webpage</title>
<body>
<h1>Hello, world!</h1>
</body>
</html>


The general structure should be obvious, and you can reinforce it with some tasks, such as:

• Add a paragraph (<p>) after the heading.
• Add this image: [insert image link here] using <img>

I would expect that <img> would need some explanation, because it will be the first element with attributes, and it's self-closing, which is different to all the others.

• If "any mistakes in the markup will be visible when you load the page" then you must be using a custom browser, because most of them go out of their way not to cover up mistakes in the markup. – Peter Taylor Jun 22 '17 at 10:08

I would avoid starting with something this abstract if the aren't used to it. Doing so might, in my experience, turn away students, especially since the beginning is usually the easiest. If the beginning is hard, they might not understand it.

I would start by explaining the basics like <html>, <body>, <head>, and also images, links, etc. Basically what you need to make a functioning, but not very special site. Then, if you have enough examples of structures like you describe in the question and the students already know these examples, you can show them the general, abstract form. Doing so avoids that they have to learn the examples and the abstract form at the same time.

• So effectively, going in reverse: teaching html structure and then showing that it is actually a particular case of a more abstract structure, which is xml? This suggestion actually makes the lesson plan flow better, so thanks for that – ItamarG3 May 24 '17 at 7:05
• @ItamarGreen Yes, that is what I suggest. In fact, I think that this is important in most CS: use examples as much as possible, and if possible, use examples students are already familiar with. – wythagoras May 24 '17 at 7:10
• I think html, head, body are abstract, they don't appear to do anything. Start with the tags that produce, obvious, output. – ctrl-alt-delor May 28 '17 at 11:59
• Technically, html is an irregular subset case of sgml, while xml is a compliant subset of sgml. Xhtml is a subset of sgml that is fully compliant with the xml that implements the html concepts. Html is irregular to reduce bandwidth usage on slow acoustic modems, and to minimize typing when web pages were all hand built – pojo-guy Oct 16 '18 at 2:43

To elaborate on my comment, I suggest approaching both (but HTML first) by way of the DOM. W3 Schools has a tutorial on both HTML and XML using this model for conceptualizing the structure of HTML/XML documents. The XML tutorial stresses the importance of knowing this structure:

Understanding the DOM is a must for anyone working with HTML or XML.

Here is a screenshot of a slide I used when introducing the structure of HTML (thanks to CS50 AP):

It's elementary, but with this basic structure it is easy to visualize nesting, siblings, and paths of traversal. Also, from a stylistic perspective vis-a-vis indentation, each child equals one further tab in, so this structure also makes it possible to address code style.

As a result I wouldn't say one needs to know XML before HTML. Instead, one should know the structure common to both to be effective with either.

• I see. I'll definitely use that slide. Thanks! – ItamarG3 May 28 '17 at 16:34
• I agree: start students with a minimal skeleton of working HTML. They can load the local file in their browser and see the effect of saved changes by refreshing the browser. But I precede the skeleton with an overview of server/client and HTML/CSS/JS. I immediately follow the skeleton by adding an <h1> element and then modify the start tag with style="color: #ff00ff;" and teach inline CSS, reinforcing hex RGB which I taught earlier in a different context. – Bennett Brown Jul 3 '17 at 2:38

I think that it's relevant to mention the ADEPT method of teaching here...

Perhaps one of the best ways I've found to explain these concepts to students is that of human anatomy... head, body, feet (foot).

• Welcome to cseducators. We're glad to have you here! This may be good advice generally, but it isn't really an answer to OP's question, which was asking about advice specific to explaining HTML. – Ben I. May 30 '17 at 4:18
• @austin good to see some teaching theory, in an answer. – ctrl-alt-delor Jun 22 '17 at 17:28
• I use this system when teaching html to young pupils – Harry Jul 21 '17 at 12:48

## Use Russian dolls

Russian dolls nest inside each other, much line block of code in almost all modern programming language (maybe all post “goto considered harmful” languages).

Russian dolls nest like this [({<>})], in programming we can also nest like this [][] no nesting, this[()()] or this[()({}{})({<><>})]

I have used Russian dolls to help to explain the idea of nesting.

• ... or next to another doll? How does this relate to using XML to teach HTML? – thesecretmaster May 28 '17 at 12:17
• This isn't an answer to the question as posed. Can you flesh this out? – Ben I. May 28 '17 at 12:46
• @thesecretmaster it relates to a comment on the question itself. I suggested adding an answer that explains what he meant, but I wasn't expecting this kind of answer o.o – ItamarG3 May 28 '17 at 12:52

My students are already familiar with Word documents by the time I get them (Grade 6 is when I start them on HTML) so those are the most common analogy that I use in my classes. I explain that HTML was invented as a way to share documents over the internet. I review document parts and compare examples in Word and HTML.

I typically start students with a Hello World example as several other answers have mentioned. Let students have that quick feedback from their browsers and get into the habit of making stuff. When it comes to anything more than a simple paragraph or two - especially the potentially messy nested elements like lists and tables - I fall back on that Word analogy. I consistently refer to HTML files as documents and reinforce the names of document parts that Word and HTML have in common (like headings, paragraphs, images, tables, lists, etc.). I demonstrate making a table in Word first and introduce the "row", "header", and "data" vocabulary to motivate the tr, th, and td abbreviations and give them meaning.

I also use spatial metaphors (for example, I tell students to make sure their head is "above" their body) and enforce fairly strict indentation rules so that students can see which elements are "inside" each other. I make sure students open and close tags and elements, and I frequently reinforce "element" and "tag" and related vocabulary words. I introduce parent/child/sibling a little later and tree diagrams a little later, with the family tree being the most obvious analogy there.

I give students lists of things to check for - for example, are all of their tags closed? All of their elements? Are all of their element names spelled correctly?

I basically build up from the practical and familiar towards the abstract and unfamiliar - and over time and practice that structure becomes much more obvious and familiar.

## Use Snap to model it.

• Use a third language to explain one of the other two? Can see why ... – ItamarG3 May 28 '17 at 12:53
• There is an editor called Pollo which has a similar aesthetic but is actually designed to edit XML. In addition, you can give it a schema and it will enforce it, which makes it useful for teaching the structure of a real document. I have actually used this with a custom schema for a configuration file which was essentially a basic programming language to teach someone who knew nothing of programming how to create config files without having to worry about syntax errors. – Peter Taylor Jun 22 '17 at 10:13
• @ItamarGreen what is the 2nd language? (I see html and snap). – ctrl-alt-delor Jun 22 '17 at 17:26
• @richard HTML and XML. – ItamarG3 Jun 22 '17 at 17:27

HTML is primarily a markup language, not a document structure. XHTML, which we use almost exclusively these days, is both.

But that means HTML is much easier to explain than XHTML. You can markup anything.

I can write something (and markup this bit:) with markup (:finished markup) without knowing or caring anything about document structure.

Once people are happy with markup, it's easier to introduce them to document structure - you're giving "the whole document" some markup.

N.B.: this is, of course, how most people learnt HTML back before XHTML existed; new students today possibly get forced through a harder route, going straight to XHTML, thanks to the predominance of XHTML in real-world use.