HTML
HTML
Introduction HTML
HTML
• Hypertext Markup Language
is the standard markup language used to create web pages.
HTML describes the structure of a website semantically along with cues for
presentation. The purpose of HTML is to add meaning and structure to the
content.
its a markup language, rather than a programming language
HTML documents consist of a tree of elements and text.
Each element is denoted in the source by a start tag,
such as "<body>", and an end tag, such as "</body>".
Web browsers can read HTML files and render them into visible or audible web
pages.
Anatomy of HTML document
The <!DOCTYPE html> declaration defines this
document to be HTML.
The <html> element is the root element of an
HTML page
The lang attribute defines the language of the
document
The <meta> element contains meta information
about the document
The charset attribute defines the character set
used in the document
The <title> element specifies a title for the
document
The <body> element contains the visible page
content
The <h1> element defines a large heading
The <p> element defines a paragraph
HTML Anatomy ...
• Stylesheet (CSS)
<head>
...
<link href=“styles.css” rel=“stylesheet”>
<head>
• Javascript
<head>
...
<script src=“jscript.js”></script>
<head>
Meta Element ...
• The <meta> element lives inside the <head> element and contains information about that web
page.
• It is not visible to users It is not visible to users but fulfills a number of purposes such as telling
search engines about your page(used for SEO(Search engine Optimization)), who created it, and
whether or not it is time sensitive, its description.
• Used for several purpose
○Putting keyword for the page that helps easier for searching
■<meta name=“keyword”, content=“ IR, Information retrieval “>
○
HTML Anatomy ...
Elements
Elements define the structure and content of objects within a page.
Enclosed inside angel brackets < and > : E.g. <a> , <p>, <div>,
<span>, <strong>, <h1>…
meta information is placed in the head element
content information is placed in the body element
Tags
The use of less-than and greater-than angle brackets surrounding an
element creates what is known as a tag.
Tags most commonly occur in pairs of opening and closing
tags.
Content of the elements always falls between the opening (e.g. <p>)and
closing (e.g. </p>) tag: E.g. <p> …content here…</p>
Tags have to be nested such that elements are all completely within
each other, without overlapping:
Tag, Attribute and Value
• Tag
• Void element: <input> <hr> <br>
• Non void element:
<a>Link</a>
• Attribute and Value
Attributes
Attributes are properties used to provide additional information about an element.
The most common attributes include id, class, src, herf
Attributes are defined within the opening tag, after an element’s name.
Tag, Attribute and Value
Generally attributes include a name and a value.
The format for these attributes consists of the attribute name followed by an equals sign
and then a quoted attribute value.
E.g.
• <a href="demo.html"> simple </a>
• <input name=“email” value=“[email protected]”>
• Atrribute: name, value
• Value: email, [email protected]
Classifying HTML elements
top-level elements: html, head and body
head elements: placed inside the head
Title, style, link, meta, base, script
Wouldn’t display on the page
block-level elements: flow elements that behave like paragraphs
occupy 100% of available width
stacked vertically with preceding and subsequent block elements
article, h1-h6, header, footer, section, p, figure, canvas,
pre, div, ul, ol, dl, table, form, video
Classifying HTML elements
inline elements
phrasing elements that behave like words
flow horizontally
usually placed inside block elements
a (anchor), audio, br, code, img, em, nav, samp
span, strong, sub, sup, time, var
Syntax of HTML
All tags begin with < and end with >
tag name is given immediately following opening <
unrecognized tags and attributes are ignored
attributes are given following the tag name:
<tag attribute1=“value” attribute2=“value” ...>
‘ can be used instead of “
forgetting to close a quote can result in a blank page
It’s good practice to keep HTML markup lowercase.
values are case sensitive (used to).
Syntax of HTML
elements without closing tags are of the form <img />
ending / is optional for HTML5, needed for XHTML documents
elements must be well-formed: no bad nesting
<p>Stuff <strong></p></strong>
attributes can be in any order.
white space is allowed
between tag name and attributes
around the = sign
within attribute value (but should be avoided)
Standard HTML Tags
• Heading • Form
<h1>, <h2>, .... <h6> <form>
• Table • Form Component
<table>, <tr>, <th>, <input>, <select>,
<td>, <tbody>, <textarea>
<thead> • Link/Anchor
• Paragraph <a>
<p> • Layer Box
• List <div>
<ol>, <ul>, <li> • Formatting
• Image <strong>, <em>, <sub>
<img> • Line Break
• Horizontal Line <br>
<hr>
HTML Comments
• If you want to add a comment to your code that will not be visible in the user's
browser, you can add the text between these characters:
<!-- comment goes here -->
• Comments are used to indicate where sections of the page start or end, and to pass
on notes to help anyone who is looking at the code understand it.
Example
Try to design web page.
Text Formatting
• One of the components on webpage is elements used to mark up text.
• A semantically marked-up document ensures your content is available and accessible in the
widest range of browsing environments. i.e. ,desktop computers, mobile devices and assistive
screen readers.
• Search engine programs indexing programs can also correctly parse the content and make
decisions about the relative importance of elements on the page.
Paragraph
• <p> </p>
E.g. <p> Serif typefaces have small slabs at the ends of letter strokes. In general, serif fonts can
make large amounts of text easier to read.</p>
• Visual browsers nearly always display paragraphs on new lines with a bit of space between them
by default.
• Paragraphs may contain text, images, and other inline elements (called phrasing content), but
they may not contain headings, lists, sectioning elements, or any elements that typically display
as blocks by default.
Heading
• There are actually six levels of headings, from h1 to h6.
• When you add headings to content, the browser uses them to create a document outline for the
page.
• The example below shows the markup for four heading levels and the corresponding document
outline.
Thematic
• <hr>
Breaks (Horizontal rule)
• To indicate one topic has completed and another one is beginning, “paragraph level thematic
break” can be used with the hr element.
• The element adds a logical divider between sections of a page or paragraphs.
• Is an empty element.
E.g. The example below shows the usage of hr element.
N.B. Don’t use <br> interchangeably with <hr>. Br elements must be used only for line breaks that are
actually part of the content, as in poems or address it should not be used for separating thematic
groups in paragraph
Grouping Content
• According to HTML5 spec there are elements that are considered “grouping content” like
blockquote(long quotations), pre(preformatted text), and figure and figcaption(figures).
Additional grouping contents are p,hr, list elements, main, div elements etc ..
• This elements typically displayed as block elements.
• Long Quotations: if the document contains a long quotation, a testimonial, or a section of copy
from another source, mark the content using blockquote element.
• It is recommended that content within blockquote elements be contained in other elements,
such as paragraphs, headings, or lists, as shown in the example:
Cont’d[blockquote]
• There is also an inline element q for short quotation in the flow of text. In this case the browser
simply puts a quotation around the content inside the tag.
Cont’d[Grouping Content]
• Preformatted Text: The browsers ignore whitespaces such as line returns and character spaces
in the source document. But in some types of information white space is semantically significant
like code examples or certain poems .
• For content in which whitespace is semantically significant, use the preformatted text (pre)
element.
• It is a unique element in that it is displayed exactly as it is typed—including all the carriage
returns and multiple character spaces.
Inline elements
• Semantic meaning can be provided to phrases within the chunks by using what the HTML5
specification calls text-level semantic elements (inline elements).
• displayed in the flow of text by default and do not cause any line breaks.
• Emphasized text: <em> it is used to indicate which part of a sentence should be stressed or
emphasized.
• Emphasized text (em) elements nearly always display in italics by default. [it can be changed
using stylesheet]
• The placement of em elements affects how a sentence’s meaning is interpreted.
• E.g.
Cont’d [em]
• N.B Screen readers may use a different tone of voice to convey stressed content, which is
why you should use an em element only when it makes sense semantically, not just to
achieve italic text.
• Important text: The strong element indicates that a word or phrase is important, serious,
or urgent.
• the strong element identifies the portion of instructions that requires extra attention.
• The strong element doesn’t change the meaning of the sentence; it merely draws attention to
the important parts.
Cont’d [strong]
• Visual browsers typically display strong text elements in bold text by default.
• N.B Screen readers may use a distinct tone of voice for important content, so mark text as
strong only when it makes sense semantically, not just to make text bold.
b Keywords, product names, and other phrases that need to font-weight: bold
stand out from surrounding text without conveying added
meaning.
i Indicates text that is in a different voice or mood than the font-style: italic
surrounding text, such as a phrase from another language, a
technical term, or a thought.
s Indicates text that is no longer accurate or relevant (but that text-decoration: line-through
should not be deleted).
small Indicates an addendum or side note to the main text. font-size: 70%
Additional Inline Elements
• Abbreviations and acronyms: abbr element provides useful information for search engines,
screen readers, and other devices by marking up acronyms and abbreviations.
• Abbreviations are shortened versions of a word ending in a period (“Conn.” for “Connecticut,”
for example).
• Acronyms are abbreviations formed by the first letters of the words in a phrase (such as NASA
or USA).
• The title attribute provides the long version of the shortened term, as shown in below.
Cont’d [Additional inline elements]
Element Purpose Example
address it contains contact details for the author of the page. It can contain a
physical address, but it does not have to. For example, it may also
contain a phone number or email address.
Subscript & The subscript (sub) and superscript (sup) elements cause the
superscript selected text to display in a smaller size, positioned slightly below
(sub) or above (sup) the baseline.
Generic Elements (DIV and SPAN)
• The div element indicates a division of content, it is known as generic block-level element,
and span indicates a word or phrase for which no text-level element currently exists, it is
known as generic inline elements.
• The generic elements are given meaning and context with the id and class attributes.
• The div and span elements have no inherent presentation qualities of their own, but we can
use style sheets to format them however we like.
Divide it up with a div
• The div element is used to create a logical grouping of content or elements on the page. It
indicates that they belong together in a conceptual unit or should be treated as a unit by CSS
or JavaScript.
Cont’d
• In other words, we can give context to the elements in the grouping.
• The below example show the usage of div element. Here the div element is used as a
container to group an image and two paragraph.
• div also used to break a page into sections for layout purposes. In this example, a heading and
several paragraphs are enclosed in a div and identified as the “news” division:
Define a Phrase with span
• A span offers the same benefits as the div element, except it is used for phrase elements and
does not introduce line breaks.
• Because spans are inline elements, they may contain only text and other inline elements (in
other words, you cannot put headings, lists, content-grouping elements, and so on, in a span)
• For example, There is no telephone element, but we can use a span to give meaning to
telephone numbers. In this example each telephone number is marked up as a span and
classified as “tel”.
List
• HTML provides elements for marking up three types of list:
• All list elements (the list themselves and the items that go in them) are displayed as block elements by
default.
Unordered lists
( Collections of items that appears in no particular order).
Ordered lists
( lists in which the sequence of the items is important).
Description lists
( lists that consist of name and value pairs, including but not
limited to terms and definitions).
Unordered List (<ul> .. </ul>)
• By default, unordered lists display with a bullet before each list item, but can be changed that
with a style sheet.
• To identify an unordered list, mark it up as a ul element. The opening <ul> tag goes before the
first list item, and the closing tag </ul> goes after the last item. Then to mark up each item in
the list as a list item (li), enclose it in opening and closing li tags, as shown in this example.
• N.B. The only thing that is permitted within an unordered list is one or more list items. You
can’t put other elements in there, and there may not be any untagged text.
Ordered List (<ol> .. </ol>)
• Ordered lists are for items that occur in a particular order, such as step-by-step instructions or
driving directions.
• They work just like the unordered list but they are defined with the ol element. Instead of
bullets, the browser automatically inserts numbers before ordered list items.
• If we want a numbered list to start at a number other than 1, we can use the start attribute in
the ol element to specify another starting number. <ol start=“10”>
• You can use the list-style-type style sheet property to change the bullets and numbers for lists
Description List (<dl> .. </dl>)
• Description lists are used for any type of name/value pairs, such as terms and their definitions,
questions and answers, or other types of terms and their associated information.
• The whole description list is marked up as a dl element. The content of a dl is some number of
dt elements indicating the names, and dd elements for their respective values.
Cont’d (lists)
• Any list can be nested within another list, it is just to be placed within a list item. This example
show the structure of an ordered list nested in the second item of an ordered list.
• When you nest an unordered list within another unordered list, the browser automatically
changes the bullet style for the second-level list.
Inserting Special Characters (<dl> ..
</dl>)
• In HTML special characters are referred to as entities , and they are created by using codes
beginning with an ampersand (&), followed by entity name or an entity number.
• For example or   both render as a non-breaking space.
Link (<a> … </a>)
• The web is based on hyperlinks. Each webpage contains active links to other pages, which in
turn link to even more webpages.
• Your activate a hyperlink by clicking a designated bit of text or a graphic that, depending on
the link takes to a different location on the page.
opens a different webpage,
Start an email-message,
downloads a file,
lets you view a movie or listen to a sound clip etc.
• The <a> tag, which is used to create various types of hyperlinks. It is known as anchor element
(hypertext link).
• It starts with the <a> tag, and then uses href attribute which provides the URL or the path to
the destination.
Cont’d[Link]
• Nearly all graphical browsers display linked text as blue and underlined by default.
• Visited links generally display in purple opens a different webpage.
Example
• <a href="http://www.oreilly.com">Go to the O'Reilly Media site</a>
Cont’d[Link]
• href Attribute: provides the address of the page or resource (its URL) to the browser.
• The URL must always appear in quotation marks.
• In most case the URL points to HTML documents, but can point to other web resources, such as
images, audio and video files.
• There are two ways to specify the URL:
Absolute URLs
Relative URLs
• Absolute URLs: provide the full URL for the document, including the protocol (http:// or
https://), the domain name, and the path name as necessary. we need to use an absolute URL
when pointing to a document out on the web (i.e., not on our own server): This is known as
external link.
Cont’d[Link]
• Relative URLs: describe the pathname to a file relative to the current document.
• can be used when we are linking to another document on our own site (i.e., on the same
server)
• It doesn’t require the protocol or domain name—just the pathname:
• A relative pathname describes how to get to the linked document starting from the location of
the current document.
• In order to see the how relative URL works we use the following site structure.
• How Relative URL works (three scenarios)
Linking within a Directory
E.g. how to make a link from index.html to about.html
Soln = provide only the name of the file (its file name).
From index.html
<a href=“about.html”> About the site … </a>
Linking to a Lower Directory
E.g. how to make a link from index.html to a file in the
Recipes directory called salmon.html
Soln = The pathname in the URL tells the browser to
look in the current directory for a directory called
recipes, and then look for the file salmon.html
From index.html
<a href=“recipes/salmon.html”> Garlic Salmon </a>
• How Relative URL works (cont’d)
Linking to a higher Directory
E.g. how to make a link from salmon.html to back to
home page (index.html)
Soln = use dot-dot-slash (../), it is like telling “back up one
directory level up”
<a href=“../index.html”> [Back to home page] … </a>
• To make a link to specific destinations in pages on other sites by putting the fragment identifier
at the end of an absolute URL.
Cont’d
• Setting a target window
• By default, a hyperlink opens the referenced page in the same browser window. That means
the new page replaces the previous page in your browser. Usually this is fine, but in some
cases you might want to open in a new window.
• To direct the hyperlink to open a page in a new window, add the attribute target=“_blank” to
the <a> tag.
• N.B Before deciding whether to start a link in a new window, consider carefully the benefits
outweigh the potential drawbacks.
Cont’d
• Hyperlinking to an E-mail Address
• You can create e-mail hyperlinks, for example that start the user’s default e-mail program, create a
new message and enter the recipient’s address.
• <a href="mailto:[email protected]">Contact Us</a>
• Contact <a href="mailto:[email protected]">[email protected] </a>
• < a href="mailto:[email protected]?subject=Comment">Contact Us </a>
<a href="mailto:[email protected]" title="Please contact us with questions or comments"> [email protected] </a>
• Hyperlinking to Telephone
• Telephone links are the ones that you tap to call a number on phone-capable devices.
• The syntax uses the tel: protocol.
Image (<img>)
• Images appear on web pages in two ways: embedded in the inline content or as background
images.
• You can’t put just any image on a web page; it needs to be in one of the web-supported
formats.
• For images made up of grid of colored pixels PNG, JPEG or GIF file formats is used.
• For vector images, such as the kind of icons and illustrations created by Adobe illustrator SVG
format is used.
• The <img> element is used to add an inline image. It tells the browser “Place an image here”.
Images stay in flow of text, aligned with the baseline of the text, and do not cause any line
breaks. (HTML5 call this a phrasing element).
Cont’d
• E.g.
• When the browser sees the img element, it makes a request to the server and retrieves the
image file before displaying it on the page.
• The src and alt attributes shows in the examples are required. The src(source) attribute
provides the location of the image file(its URL). The alt attribute provides alternative text that
displays if the image is not available or for those who are not able to see it.
• The img element is an empty and inline element.
• The img element is what’s known as a replaced element because it is replaced by an external
file when the page is displayed.
Cont’d
• If an image does not add anything meaningful to the text content of the page, it is
recommended that you leave the value of the alt attribute empty (null).
• Width and Height: attributes indicates the dimensions of the image in number of pixels.
Browsers use the specified dimensions to hold the right amount of space in the layout while
the images are loading rather than reconstructing the page each time a new image arrives.
• we can be use image as a link. <a href=“” > <img src=“” alt=“”> </a>
• N.B These attributes have less useful in the age of modern web development. It is better to use
responsive image techniques.
• Reading Assignment (Responsive Image Markup)
Cont’d
• Image Map: You have seen how image can be used as a hyperlink, but sometimes you might want
different areas of the image to hyperlink to different locations. For example, suppose you have a map
of the United States, and you want the user to be able to click individual states to view a page
containing information specific to different location. In this case we must use image map.
• The <map> tag in HTML defines image mapping in HTML. The map is overlaid on the image. An
image map is clickable link area. The <area> tag is used along with the <map> tag to generate a
clickable link area(define the clickable area). Image map combine two different components:
• A map of defined linked area
• An image
• Syntax
<img src=“” usemap=“#map_name”>
<map name=“map_name”>
<area href=“link” coords=“coordinates of selected shape” shape=“circle/rect/poly”>
Table
• Html tables were created when we need to arrange data into rows and columns.
• Used to organize schedules, product comparisons, statistics, inventory or other types of
information.
• The data can be any sort of information including numbers, text elements, and even images
and multimedia objects.
• The intersections of rows and column which form cells. Each cell is a distinct area, into which
you can place text, graphics, or even other tables.
Creating and Formatting Table
• The <table> tag creates an HTML table. Within that tag, you include one or more <tr> tags, which
define the table’s rows, and within each <tr> tag, you define one or more <td> tags, which define
the cells. One of cells can be <th> tag, which define table headers. <th> element is like the <td>
element but its purpose is to represent the heading for either a column or rows. <th> element
helps scrren readers and improves the ablity for search engines to index the page.
Spanning Cells
• Streching of a cell to cover several rows or column.
• Allows to create complex table structure.
• rowspan and colspan is used to span cells and applied in the th or td elements.
• To merge a cell into adjacent cells to its right, use the colspan attribute and specify the number
of columns to be spanned, like this:
<th colspan=“2"> Fat </th>
• To merge a cell into adjacent cells below it, use the rowspan attribute and specify the number
of rows to be spanned, as shown in the following: