Learn Basic HTML Complete Course part 5

2 min read

HTML Elements

An HTML file is made of elements. These elements are responsible for creating web pages and define content in that webpage. An element in HTML usually consist of a start tag , close tag and content inserted between them. Technically, an element is a collection of start tag, attributes, end tag, content between them.

Some elements does not have end tag and content, these elements are termed as empty elements or self-closing element or void elements.

Void element: All the elements in HTML do not require to have start tag and end tag, some elements does not have content and end tag such elements are known as Void elements or empty elements. These elements are also called as unpaired tag.

Some Void elements are <br> (represents a line break) , <hr>(represents a horizontal line), etc.

Nested HTML Elements
: HTML can be nested, which means an element can contain another element.


Block-level element:

  • These are the elements, which structure main part of web page, by dividing a page into coherent blocks.
  • A block-level element always start with new line and takes the full width of web page, from left to right.
  • These elements can contain block-level as well as inline elements.

Following are the block-level elements in HTML.

    <address>, <article>, <aside>, <blockquote>, <canvas>,
    <dd>, <div>, <dl>, <dt>, <fieldset>, <figcaption>,
    <figure>, <footer>, <form>, <h1>-<h6>, <header>, <hr>,
    <li>, <main>, <nav>, <noscript>, <ol>,<output>, <p>,
    <pre>, <section>, <table>, <tfoot>, <ul> and <video>.


Example

<!DOCTYPE html> 
<html> 
    <head> 
    </head> 

    <body> 
        <div style="background-color: lightblue">This is first div</div> 
        <div style="background-color: lightgreen">This is second div</div> 
        <p style="background-color: pink">This is a block level element</p> 
    </body> 
</html>  

output:

This is first div
This is second div

This is a block level element



In the above example we have used tag, which defines a section in a web page, and takes full width of page.

We have used style attribute which is used to styling the HTML content, and the background color are showing that it's a block level element.


Inline elements:

  • Inline elements are those elements, which differentiate the part of a given text and provide it a particular function.
  • These elements does not start with new line and take width as per requirement.
  • The Inline elements are mostly used with other elements.

<a>, <abbr>, <acronym>, <b>, <bdo>, <big>, <br>, <button>,
    <cite>, <code>, <dfn>, <em>, <i>, <img>, <input>, <kbd>,
    <label>, <map>, <object>, <q>, <samp>, <select>, <small>,
    <span>, <strong>, <sub>, <sup>, <textarea>, <time>, <tt>,
    <var>.

Example

<!DOCTYPE html> 
<html> 
    <head> 
    </head> 
   
    <body> 
        <a href="https://touchtogain.blogspot.com">Click on link</a> 
       
        <span style="background-color: lightblue">this is inline element</span> 
        <p>This will take width of text only</p> 
    </body> 
</html>   

output:

Click on link this is inline element

This will take width of text only


You may like these posts

  • HTML TableHTML table tag is used to display data in tabular form (row * column). There can be many columns in a row.We can create a table to display data in tabular form, using <…
  • HTML TagsHTML tags are like keywords which defines that how web browser will format and display the content. With the help of tags, a web browser can distinguish between an HTML co…
  • HTML Id AttributeThe id attribute refers to a unique value for an HTML element. This HTML id value can be used with CSS and JavaScript to perform certain task.HTML id with CSSIn CS…
  • HTML AnchorThe HTML anchor tag defines a hyperlink that links one page to another page. It can create hyperlink to other web page as well as files, location, or any URL. …
  • In this article, I am going to share some of the best, free online courses to learn Web Development using HTML and CSS. If you are new to web development space then you can use the…
  • HTML HeadThe HTML <head> element is used as a container for metadata (data about data). It is used between <html> tag and <body> tag.The head of an HTML document …

Post a Comment