HTML elements
In this article we are going to learn about common html elements, to study about some of html elements with their rules.
We learnt about html, text in html, lists in html, links in html, inputs in html, buttons in html and forms in html so, now we are going to learn common html elements.
HTML elements
HTML elements are different and each element has its own role and rule in html so, we will be focusing on div, paragraph, heading and span elements.
Div element
Div element (<div></div>) is the main html element that can have other div child elements and contain other elements like paragraph, list, form and span.
Let us create a div element with child divs, copy and paste below code.
<!-- This is a parent div element with div child elements. -->
<div>
<div>This is a first child div element.</div>
<div>This is a second child div element.</div>
</div>
So, we should have the following results and the first and second div elements are child elements and are both inside parent div element.
Paragraph element
Paragraph element (<p></p>) is an html element that can have other child elements or contain other elements like link, span, italic and bold.
Let us create a div element with child divs, copy and paste below code.
<!-- This is a parent paragraph element with span and italic child elements. -->
<p>
<span>This is child span element.</span>
<br/>
<i>This is child italic element.</i>
</p>
So, we should have the following results and paragraph elements cannot contain div and other paragraph elements.
This is span element.
This is italic element.
Heading element
Heading element (<h1></h1>) is an html element that can have other heading child elements or contain other elements like div, paragraphs, italic and bold.
Let us create a heading two element with child heading and div element, copy and paste below code.
<!-- This is a parent heading two element with another heading and div child elements. -->
<h2>
<h3>This is child heading two element.</h3>
<div>This is child div element.</div>
</h2>
So, we should have the following results and heading one is a parent element while heading two and div elements are child elements.
This is child heading three element.
This is child div element.
Span element
Span element (<span></span>) is an html element that can have other span child elements and contain other elements like div, heading, paragraphs, italic and bold.
Let us create a span element with child span, heading six and div element, copy and paste below code.
<!-- This is a parent span element with another span, heading six and div child elements. -->
<span>
<span>This is child span element.</span>
<h6>This is child heading six element.</h6>
<div>This is child div element.</div>
</span>
So, we should have the following results and span is a parent element while heading six and div elements are child elements.
This is child span element.