Void Elements in html and example

Void Elements in html and example
Nikhil
Published on 2021-07-02 03:45:55

Not all HTML tags are of the same structure. While most elements require an opening tag, a closing tag, and contents, some elements - known as void elements - only require an opening tag as they themselves do not contain any elements. This topic explains and demonstrates the proper usage of void elements in HTML.

HTML Void elements


HTML 4.01/XHTML 1.0 Strict includes the following void elements in html:

  • area - clickable, defined area in an image
  • base - specifies a base URL from which all links base
  • br - line break
  • col - column in a table [deprecated]
  • hr - horizontal rule (line)
  • img - image
  • input - a field where users enter data
  • link - links an external resource to the document
  • meta - provides information about the document
  • param - defines parameters for plugins

HTML 5 standards include all non-deprecated tags from the previous list

  • command - represents a command user can invoke [obsolete]
  • keygen - facilitates public key generation for web certificates [deprecated]
  • source - specifies media sources for pictures, audio, and video elements

 

The example below does not include void elements in html:

<!DOCTYPE html>
<html>

<head>
    <title>Atutorialhub demo title</title>
</head>

<body>
    <div>
        <a href="https://notes4free.in/">
            <h3>Click here to visit <i>Notes4free</i></h3>
        </a>
        <button onclick="alert('Hello!');">Say Hello!</button>
        <p>My favorite language is <b>HTML</b>. Here are my others:</p>
        <ol>
            <li>CSS</li>
            <li>JavaScript</li>
            <li>PHP</li>
        </ol>
    </div>
</body>

</html>

 

Notice how every element has an opening tag, a closing tag, and text or other elements inside the opening and closing tags. Void tags however are shown in the

example below:

<!DOCTYPE html>
<html>
<head>
    <title>Atutorialhub demo title</title>
</head>
<body>
    <img src="http://www.notes4free.in/assets/images/logo_dark.png" />
    <br>
    <hr>
    <input type=" number" placeholder=" Enter your favorite number">
</body>
</html>

 

With the exception of the img tag, all of these void elements have only an opening tag. The img tag, unlike any other tag, has a self-closing / before the greater than a sign of the opening tag. It is best practice to have space before the slash.

ATutorialHub Related Guide

HTML Tutorials Comments (8)

Leave a Comment

Your email address will not be published. Required fields are marked*

User Comments

html tutorial comments

panduranga gupta

2021-07-05 07:03:13

good website for learning and help me a lot

html tutorial comments

raju

2021-09-25 14:58:47

The awsome website i am looking like for a long time, good work atutorialhub team keep doing

html tutorial comments

Shivani

2021-09-01 15:03:56

Learning a lot from the courses present on atutorialhub. The courses are very well explained. Great experience

html tutorial comments

Harshitha

2021-09-10 15:05:45

It is very helpful to students and easy to learn the concepts

html tutorial comments

Sowmya

2021-09-14 15:06:41

Great job Tutorials are easy to understand Please make use of it

html tutorial comments

Zain Khan

2021-09-18 15:07:23

Great content and customized courses.

html tutorial comments

Rudrakshi Bhatt

2021-09-09 15:08:10

Well structured coursed and explained really well!

html tutorial comments

Pavana Somashekar

2021-09-11 15:09:08

Good platform for beginners and learn a lot on this website