Getting That Bird Back Into It's HTML Nest
HTML is all about nesting. In this video we will talk about what nesting is and why its so important. In essence nesting is just like a bird that has a nest and in it it has a few chicks. That might sound odd but only if you didn't watch our video. So lets jump in and understand what Nesting is.
Video Transcript
00:00So, we're back
00:01-Hi 'ma , how are you doing so far?
00:03-okay
00:04-excellent
00:05I want to talk about few important things that you just have to know
00:09when you're working in HTML
00:11So far, we didn't really talk about them because
00:14we didn't want to talk to much, we wanted to start doing things
00:17One of the most critical things in html, as we said earlier,
00:21is that every tag that opens , has to close.
00:28Every time you open, you have to close.
00:30We didn't say though, when do you have to close it
00:33and it's really important to know when you have to close it
00:36for example in this scenario we have a head that opens and closes
00:39we wouldn't open up a title and then close the title up
00:43outside of it
00:45Because we would break the structure of the application
00:47every time we want to close something,
00:50before, we close the thing that was above it,
00:52So if we open up a head, and inside of it we open up a title,
00:56we have to close the title before we close the head
00:59- mmhmm. okay
01:01And the reason is very simple. HTML language
01:11is like a tree. A tree structure.
01:13And you can't create a branch, this is like a branch, and then
01:17in the branch itself have it leaf the branch it was in,
01:24HTML has a branch that inside of it has HTML,
01:27and has another one which is a body
01:29so the head and the body are siblings,
01:32And the title itself is like a child of the head, so the child of the head can't leave the parent
01:38it has to be bounded inside of that bounding area
01:42That's one thing that you just have to know,
01:44Second thing you have to know regarding HTML is
01:49that there's nesting going on, that's how they call it
01:52in a professional programming jargon,
01:54when you have the title,
01:56and the title is inside of the head - it's nested inside
01:59Just like a little bird is nested inside of a nest
02:03and it's literally all you have to know
02:04Most important thing when you're working with HTML any tag,
02:07doesn't matter what, you have to make sure that you're nesting it legally
02:11if for example I would give you question in an exam
02:15or homework assignment - something like this,
02:18Would this be legal HTML ?
02:20No, the way to fix that would be to make sure we close H1 before we open up the 'p' tag
02:31What if we took this H1 as a whole block and we just put it right inside of the paragraph,
02:36would that be legal ?
02:44-I don't have any answer.
02:46well, is the H1 completely nested inside of the p tag ?
02:50-yeah,
02:52-so it's legal.
02:54As long as it's bounded inside so what we just did is
02:58we turned a sibling relationship for that 'h1' an 'p'
03:03-we turned the H1 to be a child of the paragraph
03:06and that's completely legal, although you would never do that
03:09in our scenario because you would never want to put a title
03:11inside of a paragraph, but it's completely legal HTML,
03:14there's no law that forbids you doing that.
03:16It would be a completely valid HTML
03:20That's the most important thing you need to know
03:23when you're practicing with HTML and one of the things
03:26that junior developer tend to get confused with.
03:31The best way of avoiding getting confused is
03:33every time you open a tag, always close it.
03:36Never wait to close it later. If you always open and close
03:39you'll never have that issue.
03:41the second thing is one that I do a lot of times
03:44is just to make sure you're closing your head tag
03:47you're not closing it like this,
03:49because then it's hard for you to visually see that
03:51this is a child/parent relationship
03:54What I tend to do is I just click on that 'tab' button
03:57and I make sure that my title will be very visibly the child of the head
04:01Like that it's very easy to see that this belongs here
04:04and that belongs there
04:05and we have levels of importance.
04:07So for example in our scenario with this 'p' tag
04:10what I would do if I was building my own application at home
04:14well, with you - I would just click on the Tab
04:17make sure that it's align nicely
04:18Now, if you're not working with the modern editor,
04:21you will not see this,
04:22so you want to work with a nice , modern editor
04:24if it's DreamWeaver if it's SublimeText
04:27if it's any other editor that is really design for building code in HTML
04:31I just added another 'p' tag so I saw there's a paragraph here also
04:35and let me get rid of that as well, save that and there we go
04:39That is our video on the structure, basically on nesting,
04:44which is what it's called
04:46In our next video we're going to continue exploring a few other tags
04:50before we do that, we're gonna learn about tags that don't have any content
04:54and how you deal with tags that don't have any content
