Void Elements in html and example

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 (9)
User Comments

panduranga gupta
2021-07-05 07:03:13good website for learning and help me a lot

raju
2021-09-25 14:58:47The awsome website i am looking like for a long time, good work atutorialhub team keep doing

Shivani
2021-09-01 15:03:56Learning a lot from the courses present on atutorialhub. The courses are very well explained. Great experience

Harshitha
2021-09-10 15:05:45It is very helpful to students and easy to learn the concepts

Sowmya
2021-09-14 15:06:41Great job Tutorials are easy to understand Please make use of it

Zain Khan
2021-09-18 15:07:23Great content and customized courses.

Rudrakshi Bhatt
2021-09-09 15:08:10Well structured coursed and explained really well!

Pavana Somashekar
2021-09-11 15:09:08Good platform for beginners and learn a lot on this website

Sax
2021-09-25 19:35:50Nice website
Leave a Comment