- HTML Elements
- HTML Elements
- Nested HTML Elements
- Example
- My First Heading
- Example Explained
- My First Heading
- My First Heading
- and an end tag
- My First Heading
- Never Skip the End Tag
- Example
- Empty HTML Elements
- Example
- HTML is Not Case Sensitive
- HTML Tag Reference
- What are empty elements in HTML ?
- Elements
- Description
- HTML Elements
- HTML Elements
- Nested HTML Elements
- Example
- My First Heading
- Example Explained
- My First Heading
- My First Heading
- and an end tag
- My First Heading
- Do Not Forget the End Tag
- Example
- Empty HTML Elements
- Use Lowercase Tags
- How to make a div with no content have a width?
- CSS
- HTML
- 15 Answers 15
HTML Elements
An HTML element is defined by a start tag, some content, and an end tag.
HTML Elements
The HTML element is everything from the start tag to the end tag:
Examples of some HTML elements:
Note: Some HTML elements have no content (like the
element). These elements are called empty elements. Empty elements do not have an end tag!
Nested HTML Elements
HTML elements can be nested (this means that elements can contain other elements).
All HTML documents consist of nested HTML elements.
The following example contains four HTML elements ( , , and
):
Example
My First Heading
My first paragraph.
Example Explained
The element is the root element and it defines the whole HTML document.
It has a start tag and an end tag .
Then, inside the element there is a element:
My First Heading
My first paragraph.
The element defines the document’s body.
It has a start tag
and an end tag .Then, inside the element there are two other elements: and
:
My First Heading
My first paragraph.
The element defines a heading.
It has a start tag
and an end tag
:
My First Heading
The
element defines a paragraph.
It has a start tag
and an end tag
:
Never Skip the End Tag
Some HTML elements will display correctly, even if you forget the end tag:
Example
This is a paragraph
This is a paragraph
However, never rely on this! Unexpected results and errors may occur if you forget the end tag!
Empty HTML Elements
HTML elements with no content are called empty elements.
The
tag defines a line break, and is an empty element without a closing tag:
Example
This is a
paragraph with a line break.
HTML is Not Case Sensitive
HTML tags are not case sensitive: means the same as
.
The HTML standard does not require lowercase tags, but W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.
At W3Schools we always use lowercase tag names.
HTML Tag Reference
W3Schools’ tag reference contains additional information about these tags and their attributes.
Tag | Description |
---|---|
Defines the root of an HTML document | |
Defines the document’s body | |
to | Defines HTML headings |
For a complete list of all available HTML tags, visit our HTML Tag Reference.
What are empty elements in HTML ?
In this article, we will see the empty tags in HTML & we will also focus on the purpose of using an empty tag. An empty element is a component that doesn’t have any embedded elements or text elements. Empty elements do not have successor nodes. In other words, the tags that do not contain any closing tags are empty tags. Empty tags contain only the opening tag but they perform some action in the webpage.
An element that does not have an enclosing tag is called an empty element. Adding the closing tags to the empty elements will be invalid syntax. The empty elements don’t have any child nodes. In short, Empty elements are self-closing or void and not container tags. The empty elements are used to embed images, lists, breaks, horizontal lines, hyperlinks, for input, meta-data, area, etc. For instance,
tag had a closing tag hence it was not an empty element.
The below are the lists of empty elements using in HTML:
Elements
Description
It is used to map a portion of an image to make it clickable by the end-user. It is used to direct the user to different links after the user clicks on the mapped portions of the image. It is used as a child tag of the tag.
For all relative URLs in a document, the base URL is specified to use with the element. Only one element can be used in a document.
The
element is used for a line break in a text (can also be called carriage-return). It is useful in the case of writing an address, story, blogs, etc where the long sentence needs to break for clear visibility.
The tag in HTML is used to set the column properties for each column within a tag. This tag is used to set the style property to each column. This tag does not contain closing tags.
The tag in HTML is used for embedding external applications which are generally multimedia content like audio or video into an HTML document. It is used as a container for embedding plug-ins such as flash animations.
A thematic break between paragraph-level components is represented by the
element. For instance, a change of shift in the topic within a section.
The element is used to embed an image into the document.
This empty element is used to create interactive controls for web-based applications and forms, for accepting the information from the user such as an address, name, phone number, etc, depending on a variety of types of input data and control widgets are available. All the input types and attributes are used inside the element.
The HTML element is used to establish a connection between the current content and an external resource. For instance, we can use it to link the external stylesheet or javascript file, etc.
The HTML element represents metadata i.e., information of a information.
The tag in HTML is used to define a parameter for plug-ins which is associated with element. It does not contain the end tag.
The element is an empty element that provides various media resources for the , , or elements. It provides the same media material in several file formats to ensure compatibility with a wide variety of browsers, as image and media file formats are supported by the browsers differently.
The tag specifies text tracks for media components audio and video. This part is employed to specify subtitles, caption files, or different files containing text, that ought to be visible once the media is taking part in. The element is an empty HTML element that is used as a child of the audio and video media components. It allows you to define timed text tracks (or time-based data), for example, to handle subtitles automatically. WebVTT format (.vtt files) — Web Video Text Tracks — is used for the tracks.
The tag in HTML stands for word break opportunity and is used to define the position within the text which is treated as a line break by the browser. It is mostly used when the used word is too long and there are chances that the browser may break lines at the wrong place for fitting the text.
The below code example illustrates the use of empty elements. We have used only a few of them here.
HTML Elements
HTML Elements
An HTML element usually consists of a start tag and end tag, with the content inserted in between:
The HTML element is everything from the start tag to the end tag:
HTML elements with no content are called empty elements. Empty elements do not have an end tag, such as the
element (which indicates a line break).
Nested HTML Elements
HTML elements can be nested (elemen
All HTML documents consist of nested HTML elements.
This example contains four HTML elements:
Example
My First Heading
My first paragraph.
!DOCTYPE>
Example Explained
The element defines the whole document.
It has a start tag and an end tag .
The element content is another HTML element (the element).
My First Heading
My first paragraph.
The element defines the document body.
It has a start tag
and an end tag .The element content is two other HTML elements ( and
).
My First Heading
My first paragraph.
The element defines a heading.
It has a start tag
and an end tag
.
The element content is: My First Heading.
My First Heading
The element defines a paragraph.
It has a start tag
and an end tag
.
The element content is: My first paragraph.
Do Not Forget the End Tag
Some HTML elements will display correctly, even if you forget the end tag:
Example
This is a paragraph
This is a paragraph
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.
Empty HTML Elements
HTML elements with no content are called empty elements.
is an empty element without a closing tag (the
tag defines a line break).
Empty elements can be “closed” in the opening tag like this:
.
HTML5 does not require empty elements to be closed. But if you want stricter validation, or if you need to make your document readable by XML parsers, you must close all HTML elements properly.
Use Lowercase Tags
HTML tags are not case sensitive: means the same as
.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.
How to make a div with no content have a width?
I am trying to add a width to a div , but I seem to be running into a problem because it has no content. Here is the CSS and HTML I have so far, but it is not working:
CSS
HTML
15 Answers 15
a div usually needs at least a non-breaking space ( ) in order to have a width.
‘ ‘ is a good technique as opposed to min-height because it doesn’t force a height. Say your font-size is set to 16px and your padding is 15px. Your div will retain the same height before and after text is added to the div (assuming it’s all on one line)
to me, putting a space doesn’t work! the div with width 100px and within doesn’t look like to be 100px in a div with flex inline elements
@Luccas or anyone who knows, why does «inline-block» work? I would expect the same behavior with the div’s default block.
Either use padding , height or   for width to take effect with empty div
Non zero min-height also works great
I prefer the padding solution, any padding greater than 0 will work. That way you don’t have a weird, selectable in the div .
Please note: for padding solution you need to provide both left/right and top/bottom padding for it to work.
Use min-height: 1px; Everything has at least min-height of 1px so no extra space is taken up with nbsp or padding, or being forced to know the height first.
Your solutions seems the cleanest to me, but I have been trying to find the reason for this in the CSS spec and I can’t find it anywhere, the nearest I found is in CSS 2.1, 9.5 Floats where it says Note: this means that floats with zero outer height or negative outer height do not shorten line boxes. , but it talks about line boxes i.e. lines in a paragraph, but not about adjacent boxes. Anyone more familiar with CSS spec?