Lists in HTML5

Lists in HTML5


In this article we learn about different types of lists in HTML5 like ordered lists, unordered lists, and description lists along with suitable examples on each type of list.

To display a list of items in a web page we can use the HTML5 lists. The list can contain items that are either ordered or unordered. All the three types of lists are block elements which by default contain a space above and below the list. First, let’s look at how to display ordered list of items using ordered lists.

Ordered Lists


To display a list of items where the items follow a certain order, we can use ordered lists. The entire list is written in between <ol> tags, and each list item in the list is written in between <li> tags. Following HTML5 code demonstrates an ordered list:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <h1>HTML5 Lists</h1>
        <h2>List of toppers</h2>
        <ol>
<li>Manoj</li>
<li>Shalini</li>
<li>Manohar</li>
<li>Harshita</li>
<li>Ramesh</li>
</ol>
</body>
</html>

By default the ordering is maintained using numbers. This can be changed to lowercase and uppercase letters or lowercase and uppercase roman numbers. To change the type of ordering, we have to use the type attribute as shown in the following HTML5 code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <h1>HTML5 Lists</h1>
        <h2>List of toppers</h2>
        <ol type="A">
<li>Manoj</li>
<li>Shalini</li>
<li>Manohar</li>
<li>Harshita</li>
<li>Ramesh</li>
</ol>
</body>
</html>

The above list replaces numbers with uppercase letters. Similarly you can use roman numbers also either in uppercase or lowercase.

To start the ordering from a different number or letter, we can use the start attribute as shown in the HTML5 code below:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <h1>HTML5 Lists</h1>
        <h2>List of toppers</h2>
        <ol type="1" start="5">
<li>Manoj</li>
<li>Shalini</li>
<li>Manohar</li>
<li>Harshita</li>
<li>Ramesh</li>
</ol>
</body>
</html>
In the above list, the ordering starts from number 5 as mentioned with the start attribute in the <ol> tag.

In HTML5, we can also reverse the ordering in the list by using the reversed attribute as shown in the code below:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <h1>HTML5 Lists</h1>
        <h2>List of toppers</h2>
        <ol type="1" start="5" reversed>
<li>Manoj</li>
<li>Shalini</li>
<li>Manohar</li>
<li>Harshita</li>
<li>Ramesh</li>
</ol>
</body>
</html>

In the above list the ordering will start from 5 and will go in the reverse direction as 4,3,2,etc. The reversed attribute is a HTML5 only attribute.

Unordered Lists


To display a list of items with bullets or other list markers like in Microsoft Word, we can use unordered lists. The entire list is written in between <ul> tags and each list item is written in between <li> tags. Following HTML5 code demonstrates an unordered list which displays a list of countries:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <h1>HTML5 Lists</h1>
        <h2>List of countries</h2>
        <ul>
<li>USA</li>
<li>UK</li>
<li>India</li>
<li>China</li>
<li>Russia</li>
</ul>
</body>
</html>
Like ordered lists, we can change the list markers in unordered lists. Different list markers for unordered lists are disc (default), square, and circle. But changing the list marker using the type attribute is obsolete now-a-days. Later we will see how to change the list markers in an unordered list using other techniques.

Description Lists


To display terms and their respective definitions, we can use description lists in HTML5. Previously these were called as definition lists. A list item in a description list contains two parts. One is the definition term and the other is the term definition.

The entire description list in written between <dl> tags. The definition term is written between <dt> tags and the term definition is written between <dd> tags. Following HTML5 code demonstrates a description list:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <h1>HTML5 Lists</h1>
        <h2>Important Terms and Definitions</h2>
        <dl>
<dt>HTML</dt>
<dd>HyperText Markup Language is used to describe the content in the web page</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets is used to style the content in the web page</dd>
</dl>
</body>
</html>

The term definitions are by default indented from the left margin of the web page. The description lists can also be used for displaying frequently asked questions and answers.

netaji gandi Saturday, November 30, 2019
HTML5 Structural Elements

HTML5 Structural Elements


In this article we learn about different structural elements introduced in HTML5 like header, nav, main and footer with suitable examples.

Prior to HTML5, web developers used the div element for grouping related elements together and apply common styles. As the use of div element is too generic in web pages, HTML5 introduced a bunch of structural elements that can assign some semantic meaning to the content inside them.

The new structural elements introduced in HTML5 are header, nav, main, footer, section, article, and aside. Here we will learn about header, nav, main, and footer. The rest of the structural elements will be covered in future articles.

header Element


The header element contains the main title of the website and/or logo of the website along with other elements that are common at the top of a web page in a website. All the elements that are part of the page header element goes in between the <header> tags.

nav Element


The nav element is used to display the main navigation of the website and is placed directly under the header of the web page generally. A set of hyperlinks to different important pages of the website are placed in the nav element. All the hyperlinks are placed in between <nav> tags.

main Element


The main content of the web page is placed in between the <main> tags. Generally the main element also contains other structural elements like div, section, article, and aside.

footer Element


The footer content of a web page is placed in between the <footer> tags. General candidate for footer content is the copyright statement.

The following HTML5 code demonstrates the use of the structural elements described above:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Basic HTML webpage</title>
<meta charset="utf-8">
</head>
<body>
        <header>
<h1>This is the header of the web page</h1>
</header>
<nav>This is the navigation bar of the website</nav>
<main>
<p>Main section start: This is the main section of the web page</p>
<h2>Important Terms and Definitions</h2>
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language is used to describe the content in the web page</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets is used to style the content in the web page</dd>
</dl>
<p>Main section end</p>
</main>
<footer>
<p>This is the footer of the website.</p>
<p>
&copy; Copyright 2019 NETAJI Tutorials. All rights reserved.
</p>
</footer>
</body>
</html>

netaji gandi
Contents of a Web Page

Contents of a Web Page

HTML has come a long way right from its initial version HTML. However, despite the fact that you can use HTML for much more than serving up static text documents, the basic organization and structure of the HTML document remains the same.

Before we dive into the specifics of various elements of HTML, it is important to summarize what each element is, what is it used for, and how it affects other elements in the document? A high-level overview of the standard HTML document and its elements is given below.

Specifying Document Type


The <!DOCTYPE> tag in a HTML document is used to specify a Document Type Definition (DTD). This tag is frequently overlooked by many of the web developers. This tag precedes all other tags in a HTML document. It specifies the format of the content that follows – what tags to expect, methods to support and so forth.

Validation systems use DTDs to actually perform the validation, using the DTD contents as a road map and a syntax guide. HTML editors use the DTD to provide tag auto completion and on-the-fly syntax checking.

The <!DOCTYPE> tag is generally written as follows:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

This above tag specifies the following information:
  • The document’s top tag level is HTML (html).
  • The document adheres to the formal public identifier (FPI) ‘‘W3C HTML 4.01 Strict English’’ standards (PUBLIC “-// W3C//DTD HTML 4.01//EN”).
  • The full DTD can be found at the URL www.w3.org/TR/html401/strict.dtd.

HTML Document Structure


All HTML tags will have three document-level tags in common. These tags (essential or fundamental tags in HTML), <html>, <head> and <body> delimit certain sections of the HTML document.

The <html> tag


The <html> tags enclose the entire HTML document. This tag tells the browser where the HTML markup begins and ends. Also tells the browser that it is a webpage. We can think of the <html> tags as the virtual top and bottom of a web page, as shown below:


Additional attributes can be specified along with the <html> tag. Attributes like lang and dir can be specified which tells the browser about the language in the document and about the direction of the text respectively. For the dir attribute, the possible values are ltr (left to right) and rtl (right to left).

The <head> tag


The <head> tag delimits the header section of a HTML document. The document’s title, meta information, scripts and style information are all contained in the <head> section. Most of the information available in the head tag is not visible to the user.

The information specified in the meta tags is useful for search engines like google, yahoo etc…  The <head> tag contains one of the important tags in html, the <title> tag, which is used to specify the title for the web page.

The <body> tag


The HTML document’s main visual content is contained within the <body> tags. That’s not to say that everything appearing between the <body> tags will be visible, but, like a printed document, this is where the main body of the document is placed and appears.

Styles


Styles effect the way how the elements in a webpage are presented to the user. This mechanism should not be neglected while developing web pages. Style definitions may appear in the head section of a document or linked from a separate file or specified inside the tags by using the style attribute.

The important point about styles is that they enable you to radically change a document’s appearance by simply applying new styles. This enables you to display the document differently for different uses – different display or output devices or to provide a different look and feel for different audiences.

Block Elements


Like word processors (Ex: Microsoft Word, Notepad, Wordpad etc…), HTML includes several tags to format blocks of text. These tags include the following:
  • <p> – Paragraphs
  • <h1> through <h6> – Headings
  • <blockquote> – Quoted text
  • <pre> – Preformatted text
  • <ul>, <ol> and <dl> – Lists
  • <div> – Divisions

Each of the block elements results in a line break and noticeable space padding after the closing tag. The block elements works only on blocks of text. They cannot be used to format characters or words inside blocks of text.

Paragraphs: The paragraph tag (<p>) is used to delimit entire paragraphs of text.

Headings: HTML supports six levels of headings. A heading is displayed generally large and in bold formatting to identify it as a heading. Level 1 heading (<h1>) is the largest and Level 6 heading (<h6>) is the smallest.

Quoted Text: The <blockquote> tag displays the text as a quote instead of plain text. The text inside a block quote will be offset from the left margin.

List Elements: The list elements are used to display a list of items in a web page. There are three types of lists namely: unordered lists (<ul>), ordered lists (<ol>) and definition lists (<dl>).

Preformatted Text: Generally, while displaying text in a web browser, the browser eliminates unnecessary white spaces and tab spaces before displaying it to the user. To prevent that and to display the text along with all the whitespaces and tab spaces, the preformatted text tag (<pre>) can be used.

Divisions: Divisions are a higher level of block formatting, usually reserved for groups of related elements, entire pages or sometimes just a single element. Divisions are generally used as containers for elements in a web page. Divisions make it easier to apply styles to a set of elements.

Inline Elements


The finest level of markup possible in HTML is at character level. Like in a word processor, HTML allows formatting on individual characters. Inline formatting elements include the following:
  • <b> – Bold
  • <i> – Italics
  • <big> – Big text
  • <small> – Small text
  • <em> – Emphasized text
  • <strong> – Strong text
  • <tt> – Teletype (monospaced) text

Several inline tags like strikethrough <strike> and underline <u> tags, have been deprecated in the current HTML specifications. Even the <font> tag has been deprecated in favor of styles. The <strike> and <u> tags have been replaced with <del> (deleted) and <ins> (inserted).

Several experienced web developers recommend the usage of <strong> and <em> tags for strong and emphasized text instead of using <b> and <i> respectively. The reasoning has to do with what is to be accomplished – is it strengthen or emphasize text or the look (bold and italic).

The span tag (<span>) is used to span styles across one or more inline characters or words. In effect, the <span> tag enables you to apply your own inline styles.

Special Characters (Character Entities)

Some special characters must be referenced directly instead of simply typed into the document, and some of these characters cannot be typed on a standard keyboard, such as the trademark symbol (™) or the copyright symbol (©). Others could cause the HTML client confusion (such as the angle brackets,and >). These specially coded characters are commonly referred to as character entities.

Entities are referenced by using a particular code in your documents. This code always begins with an ampersand (&) and ends with a semicolon (;). Three different ways to specify an entity exist:
  • mnemonic code (such as copy for the copyright symbol)
  • decimal value corresponding to the character (such as #169 for the copyright symbol)
  • hexadecimal value corresponding to the character (such as #xA9 for the copyright symbol)

The following are all examples of valid entities:
  • &nbsp;—A nonbreaking space (used to keep words together)
  • &lt;—The less-than symbol, or left-angle bracket ()
  • &copy;—The copyright symbol (©)
  • &amp;—An ampersand (&)
  • &#151;—An emdash ( — )

Organizational Elements


Two HTML elements allow us to organize information in a document: tables and forms. Tables allow us to present the data in column and row format, like a spreadsheet. Forms enable us to retrieve and present data using elements common to GUI interfaces (textboxes, radio buttons, check boxes etc…).

Linking to Other Pages (Hyperlinks)


The main advantage of the World Wide Web (WWW) is the ability to link to other documents on the web. A link typically appears as underlined text and is often rendered in a different color than normal text. Hyperlinks (links) are created by using the anchor tag (<a>). The href attribute of the anchor tag specifies the address (URL) of the destination resource. For example a link to Google appears as follows:

<a href=”http://www.google.com”>Google</a>

Images


One of the great innovations that the World Wide Web (WWW) and HTTP brought to the internet was the ability to serve up multimedia to the clients. The precursors to full-motion video and audio were graphical images in the Web-friendly Graphics Interchange Format (GIF) and Joint Photographic Experts Group (JPEG) format.

Images can be inserted into web pages by using the image tag (<img>). A typical image tag looks as shown below:

<img src=”/images/sun.jpg” alt=”Sunrise” width=”200” height=”100” />

The src attribute specifies the location of the image. The alt attribute specifies the alternate name for the image and the height and width attributes specifies the dimensions of the image.

Comments


Although HTML documents tend to be fairly legible all on their own, there are several advantages to adding comments in our HTML code. Some typical uses are: comments aid in document organization or marking particular document sections for later reference.

Comments in HTML begin with <!– tag and end with –> tag. A comment can span multiple lines. All the text in between the comment tags, is not visible to the end user.

Scripts


HTML is used to deploy content which is static in nature. The static content is sent to a user agent (browser) where it is rendered and presented to the user, but once it is sent, it doesn’t change. However, there is a need in HTML documents for such things as decision making ability, form validation and in the case of Dynamic HTML (DHTML), dynamic object attribute changes.

In these cases, client-side scripting can be used. One of the famous client-side scripting languages is Javascript. Scripts can be included in HTML documents by using the script tag (<script>) inside the <head> tag.

Summary


After looking at all the elements that can be placed inside a HTML document, it can be said that all HTML documents should have a <!DOCTYPE> declaration, <html>, <body> tags and atleast a <title> tag within the <head> section. The rest of the elements are strictly optional, but they help define a document’s purpose, style and ultimately its usability.

netaji gandi Thursday, November 21, 2019

NPTEL Programming in Java Jan 2024 Week 11

  Week 11 : Programming Assignment 1 Due on 2024-04-11, 23:59 IST The following code is missing some information needed to run the code. Add...