HTML element is defined by a beginning tag, some content, and an ending tag.
A HTML element basically consist of pair of start tag and end tag. Lets have a example to understand this.
<strong>some content we write here...</strong>
A HTML consider everything from start tag to end tag
|Start tag||Element Content||End tag|
|<div>||c programming simply first div||</div>|
|<h1>||This is first heading||</h1>|
|<p>||This is first paragraph||</p>|
Nested HTML Elements
HTML element can nested as well. It means a HTML element can contain other element as well.
All HTML document used this format created using nested HTML elements.
Lets have a example where a element contains multiple elements.
<!DOCTYPE html> <html> <body> <p>My first our paragraph.</p> <h1>My First our Heading</h1> </body> </html>
The <HTML> element defines whole HTML document, it means it does contains all the child element.
As usually it have start tag <html> and end tag </html>
Inside <html> element we have <body> element which is child of <html>.
Inside <body> element we have two other elements which are <p>…</p> and <h1>…</h1>.
What if I forgot to add end tag?
<html> <body> <p>This is a paragraph <p>This is a paragraph </body> </html>
This example works in all major browser and return expected result because end tag is optional.
But NEVER rely on this, sometime it might reproduce expected result on major web pages so always prefer to add end tag (</>) for an element.
Empty HTML elements
The elements who doesn’t contains content are called empty HTML.
<p>This line are inside paragraph element <br> but having a line break element in it.</p>
Empty elements doesn’t have separate end tag because they are self closed. They can closed be something like this.
HTML is Not Case Sensitive
HTML tags are not case sensitive means <P> and <p> are same as <p>.
Basically HTML doesn’t require to write all the HTML element in lowercase but everyone recommend to use lowercase meet HTML standards.
Thanks for reading