- Advertisement -

HTML Elements

0

Get real time updates directly on you device, subscribe now.

HTML Elements

In the fundamentals, we simply ran many samples for you to understand how webpages are structured in browsers. From that lesson, we learnt that HTML uses tags to construct documents.

An HTML element is an opening tag which is ended by a closing tag with the content inserted in between. An element enables us to structure a web page.

<Open TAG>text being formatted</close TAG>

A tag, therefore, is symbolized character that is put in between a LESS and GREATER than sign also known as CURVED BRACKET.

<p>A PARAGRAPH ELEMENT</p>

The above tags create a PARAGRAPH elements. This shows that, for browsers to be able to read and format a web page, all instructions must be placed in between tags which form a given element within the web page.

The first tag without the forward slash is the OPENING TAG or STARTING TAG while the ENDING TAG or CLOSING TAG is the one ending the element is the tag with the forward slash.

<h1> Heading Element </h1>

<p> Paragraph Element </p>

Some elements don’t need ending tags. Such HTML elements with no content are called empty elements. The element <br> indicates a line break and doesn’t require a closing tag. Some empty elements can also be written as this <br />. In this case, we say the element is a SELF CLOSED element. 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.

Nested HTML Elements

HTML elements can contain other elements. Such elements are called Nested Element. Therefore, we can say that all HTML documents consist of nested HTML elements.

 




 

Coding :

<!DOCTYPE html>

<html>

<body>

<h1> Heading</h1>

<p> paragraph.</p>

</body>

</html>

 

The above code is an exact expression of all web pages. The <html> element defines the whole document. This means that other elements contained in between <html> and </html> are those that the designer considers formatting to display the web page. Note: any element outside the <html> element SHALL still be shown when you run the codes in the browser. This so because the <html> element only serves as a guide to the designer to structure the document and be able to organize other elements as possible.

The element content is another HTML element called the <body> element. It has a start tag <body> and an end tag </body>. The body elements also has nested the <h1> and <p> elements.

<html>

<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>

</html>

The <h1> element defines a heading.

It has a start tag <h1> and an end tag </h1>.

The element content is: My First Heading.

<h1>My First Heading</h1>

The <p> element defines a paragraph.

It has a start tag <p> and an end tag </p>.

The element content is: My first paragraph.

<p>My first paragraph.</p>

Do Not Forget the End Tag

Some HTML elements will display correctly, even if you forget the end tag:

Example

<html>
<body>

<p>This is a paragraph
<p>This is a paragraph

</body>
</html>
»

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.

<br> is an empty element without a closing tag (the <br> tag defines a line break).

Empty elements can be “closed” in the opening tag like this: <br />.

Use Lowercase Tags

HTML tags are not case sensitive: <P> means the same as <p>.

The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.

Run all the HTML elements

Attributes provide additional information about HTML elements.

HTML Attributes

All HTML elements can have attributes which provide additional information about the given element. Attributes are always coded in the opening tag. Usually, it begins with the NAME of the attribute and pairs like with the value.

name=”value”

The lang Attribute
The language of the document can be declared in the <html> tag.

The language is declared with the lang attribute.

Declaring a language is important for accessibility applications (screen readers) and search engines:

<!DOCTYPE html>
<html lang=”en-US”>
<body>

</body>
</html>
The first two letters specify the language (en). If there is a dialect, use two more letters (US).

The title Attribute

Here, a title attribute is added to the <p> element. The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph:

Example
<p title=”I’m a tooltip”>
This is a paragraph.
</p>
»
The href Attribute
HTML links are defined with the <a> tag. The link address is specified in the href attribute:

Example
<a href=”https://www.pentbooks.com”>This is a link</a>
»
You will learn more about links and the <a> tag later in this tutorial.

Size Attributes

HTML images are defined with the <img> tag.

The filename of the source (src), and the size of the image (width and height) are all provided as attributes:




Example

<img src=”image.jpg” width=”104″ height=”142″>

The image size is specified in pixels: width=”104″ means 104 screen pixels wide.

You will learn more about images and the <img> tag later in this tutorial.

The alt Attribute

The alt attribute specifies an alternative text to be used, when an image cannot be displayed.

The value of the attribute can be read by screen readers. This way, someone “listening” to the webpage, e.g. a blind person, can “hear” the element.

Example

<img src=”Omegas.jpg” alt=”Omegas.com” width=”104″ height=”142″>

We Suggest: Use Lowercase Attributes

The HTML5 standard does not require lowercase attribute names.

The title attribute can be written with uppercase or lowercase like title or TITLE.

My tutorial recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.

We Suggest: Quote Attribute Values
The HTML5 standard does not require quotes around attribute values.

The href attribute, demonstrated above, can be written as:

Example
<a href=https://www.pentbooks.com>
»
W3C recommends quotes in HTML, and demands quotes for stricter document types like XHTML.

Sometimes it is necessary to use quotes. This example will not display the title attribute correctly, because it contains a space:

Example

<p title=About Omegas>

Using quotes are the most common. Omitting quotes can produce errors.
At Omegas we always use quotes around attribute values.

Single or Double Quotes?

Double quotes around attribute values are the most common in HTML, but single quotes can also be used.

In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:

<p title=’Ampiaw “Rock” Sampson’>

Or vice versa:

<p title=”Sampson ‘Rock’ Ampiaw”>

Chapter Summary

All HTML elements can have attributes
The title attribute provides additional “tool-tip” information
The href attribute provides address information for links
The width and height attributes provide size information for images
The alt attribute provides text for screen readers
At Pentbooks we always use lowercase attribute names
At Pentbooks we always quote attribute values with double quotes

 

HTML Attributes

Below is an alphabetical list of some attributes often used in HTML:

Attribute Description

alt Specifies an alternative text for an image, when the image cannot be displayed
disabled Specifies that an input element should be disabled
href Specifies the URL (web address) for a link
id Specifies a unique id for an element
src Specifies the URL (web address) for an image
style Specifies an inline CSS style for an element
title Specifies extra information about an element (displayed as a tooltip)
A complete list of all attributes for each HTML element, is listed in our: HTML Attribute Reference.

2 Comments
  1. […] HTML Elements […]

  2. […] HTML Elements […]

Comments are closed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. AcceptRead More