3.2.1Web Technologies(Topic_06 HTML Advance)
3.2.1Web Technologies(Topic_06 HTML Advance)
HTML Doctypes
A Document Type Declaration, or DOCTYPE for short, is an instruction to the web browser
about the version of markup language in which a web page is written.
A DOCTYPE declaration appears at the top of a web page before all other elements. According
to the HTML specification or standards, every HTML document requires a valid document type
declaration to insure that your web pages are displayed the way they are intended to be
displayed.
The doctype declaration is usually the very first thing defined in an HTML document (even
before the opening <html> tag); however the doctype declaration itself is not an HTML tag.
<!DOCTYPE html>
Doctypes for earlier versions of HTML were longer because the HTML language was
SGML-based and therefore required a reference to a DTD, but they are obsolete now.
With HTML5 this is no longer the case and the doctype declaration is only needed to enable the
standard mode for documents written using the HTML syntax.
You can use the following markup as a template to create a new HTML5 document.
Example
Note: The doctype declaration refers to a Document Type Definition (DTD). It is an instruction
to the web browser about what version of the markup language the page is written in. The World
Wide Web Consortium (W3C) provides DTDs for all HTML versions.
Tip: Must add a doctype declaration when creating an HTML document. Also, use the W3C's
Validator to check your HTML for markup or syntax error before publishing online.
HTML Layout
HTML Layout
You have seen most websites on the internet usually display their content in multiple rows and
columns, formatted like a magazine or newspaper to provide the users a better reading and
writing environment. This can be easily achieved by using the HTML tags, such as <table>,
<div>, <header>, <footer>, <section>, etc. and adding some CSS styles to them.
The following layout is created using an HTML table with 3 rows and 2 columns — the first and
last row spans both columns using the table's colspan attribute:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body style="margin:0px;">
</table>
</body>
</html>
OUTPUT:
Using the <div> elements is the most common method of creating layouts in
HTML. The <div> (stands for division) element is used for marking out a block of
content, or set of other elements inside an HTML document. It can contain further
other div elements if required.
<!DOCTYPE html>
.nav, .section { float: left; padding: 20px; min-height: 170px; box-sizing: border-box; }
.clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
.footer { background: #acb3b9; text-align: center; padding: 5px; }
<h1>Tutorial Republic</h1>
OUTPUT:
HTML5 has introduced the new structural elements such as <header>, <footer>, <nav>,
<section>, etc. to define the different parts of a web page in a more semantic way.
You can consider these elements as a replacement for commonly used classes such as .header,
.footer, .nav, .section, etc. The following example uses the new HTML5 structural elements to
create the same layout that we have created in the previous examples.
<!DOCTYPE html>
<html lang="en">
nav, section { float: left; padding: 20px; min-height: 170px; box-sizing: border-box; }
section { width: 80%; } nav { width: 20%; background: #d4d7dc; }
.clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
</style>
</head>
</body>
</html>
OUTPUT:
Tag Description
HTML Head
The <head> element primarily is the container for all the head elements, which provide extra
information about the document (metadata), or reference to other resources that are required for
the document to display or behave correctly in a web browser.
The head elements collectively describes the properties of the document such as title, provide
meta information like character set, instruct the browser where to find the style sheets or scripts
that allows you to extend the HTML document in a highly active and interactive ways.
The HTML elements that can be used inside the <head> element are: <title>, <base>,
<link>, <style>, <meta>, <script> and the <noscript> element.
The title element is required in all HTML/XHTML documents to produce a valid document.
Only one title element is permitted in a document and it must be placed within the <head>
element. The title element contains plain text and entities; it may not contain other markup tags.
● To display a title in the browser title bar and in the task bar.
● To provide a title for the page when it is added to favorites or bookmarked.
● To displays a title for the page in search-engine results.
Example:
<!DOCTYPE html>
<html lang="en">
</body>
</html>
The HTML <base> element is used to define a base URL for all relative links contained in the
document, e.g. you can set the base URL once at the top of your page, and then all subsequent
relative links will use that URL as a starting point. Here's an example:
</head>
HTML Meta
● Defining Metadata
The <meta> tags are typically used to provide structured metadata such as a document's
keywords, description, author name, character encoding, and other metadata. Any number of
meta tags can be placed inside the head section of an HTML or XHTML document.
Metadata will not be displayed on the web page, but will be machine parsable, and can be used
by the browsers, search engines like Google or other web services.
The following section describes the use of meta tags for various purposes.
To set the character encoding inside a CSS document, the @charset at-rule is used.
Note: UTF-8 is a very versatile and recommended character encoding to choose. However, if
this is not specified, then the default encoding of the platform is used
Note: The name attribute of the meta tag defines the name of a piece of document-level
metadata, while the content attribute gives the corresponding value. The content attribute value
may contain text and entities, but it may not contain HTML tags.
<head>
</head>
HTML Script
Client-side scripting refers to the type of computer programs that are executed by the user's web
browser. JavaScript (JS) is the most popular client-side scripting language on the web.
The <script> element is used to embed or reference JavaScript within an HTML document to add
interactivity to web pages and provide a significantly better user experience.
Some of the most common uses of JavaScript are form validation, generating alert messages,
creating image gallery, show hide content, DOM manipulation, and many more.
JavaScript can either be embedded directly inside the HTML page or placed in an external script
file and referenced inside the HTML page. Both methods use the <script> element.
● Embedding JavaScript
To embed JavaScript in an HTML file, just add the code as the content of a <script> element.
The JavaScript in the following example write a string of text to a web page.
<head>
<meta charset="utf-8">
<title>Embedding JavaScript</title>
</head>
</body>
</html>
Tip: Ideally, script elements should be placed at the bottom of the page, before the closing body
tag i.e. </body>, because when browser encounters a script it pauses rendering the rest of the
page until it parses the script that may significantly impact your site performance.
You can also place your JavaScript code into a separate file (with a .js extension), and call that
file in your HTML document through the src attribute of the <script> tag.
This is useful if you want the same script available to multiple documents. It saves you from
repeating the same task over and over again and makes your website much easier to maintain.
Note: When the src attribute is specified, the <script> element must be empty. This simply
means that you cannot use the same <script> element to both embed the JavaScript and to link to
an external JavaScript file in an HTML document.
Tip: JavaScript files are normal text files with .js extension, such as "hello.js". Also, the external
JavaScript file contains only JavaScript statements; it does not contain the <script>...</script>
element like embedded JavaScript.
The <noscript> element is used to provide an alternate content for users that have either disabled
JavaScript in their browser or have a browser that doesn't support client-side scripting.
This element can contain any HTML elements, aside from <script>, that can be included in the
<body> element of a normal HTML page. Let's check out an example:
<!DOCTYPE html>
</head>
<body>
<noscript>
Note: The content inside the noscript element will only be displayed if the user's browser doesn't
support scripting, or scripting is disabled in the browser.
HTML Entities
● What is HTML Entity?
Some characters are reserved in HTML, e.g. you cannot use the less than (<) or greater than (>)
signs or angle brackets within your text, because the browser could mistake them for markup,
while some characters are not present on the keyboard like copyright symbol ©.
To display these special characters, they must be replaced with the character entities. Character
entity references, or entities for short, enable you to use the characters that cannot be expressed
in the document's character encoding or that cannot be entered by a keyboard.
You can use numeric character references, instead of entity names. A key benefit of using
numeric character references is that, they have stronger browser support, and can be used to
specify any Unicode character, whereas entities are limited to a subset of this.
Note: HTML entities names are case-sensitive! Please check out the HTML character entities
reference for a complete list of character entities of special characters and symbols.
Tip: Nonbreaking space ( ) is used to create a blank space between two items that cannot
be separated by a line break. They are also used to display multiple spaces since web browsers
display only one space if multiple spaces are created using the spacebar key.
HTML URL
● What is URL?
URL stands for Uniform Resource Locator is the global address of documents and other
resources on the World Wide Web. Its main purpose is to identify the location of a document and
other resources available on the internet, and specify the mechanism for accessing it through a
web browser.
https://www.tutorialrepublic.com/html-tutorial/html-url.php
— This is the URL of the web page you are viewing right now.
scheme://host:port/path?query-string#fragment-id
A URL has a linear structure and normally consists of some of the following:
● Scheme name — The scheme identifies the protocol to be used to access the resource on
the Internet. The scheme names followed by the three characters :// (a colon and two
slashes). The most commonly used protocols are http://, https://, ftp://, and mailto://.
● Host name — The host name identifies the host where resource is located. A hostname is
a domain name assigned to a host computer. This is usually a combination of the host's
local name with its parent domain's name. For example, www.tutorialrepublic.com
consists of host's machine name www and the domain name tutorialrepublic.com.
● Port Number — Servers often deliver more than one type of service, so you must also
tell the server what service is being requested. These requests are made by port number.
Well-known port numbers for a service are normally omitted from the URL. For example,
web service HTTP runs by default over port 80, HTTPS runs by default over port 443.
● Path — The path identifies the specific resource within the host that the user wants to
access. For example, /html/html-url.php, /news/technology/, etc.
● Query String — The query string contains data to be passed to server-side scripts,
running on the web server. For example, parameters for a search. The query string
preceded by a question mark (?), is usually a string of name and value pairs separated by
ampersand (&), for example, ?first_name=John&last_name=Corner, q=mobile+phone,
and so on.
● Fragment identifier — The fragment identifier, if present, specifies a location within the
page. Browser may scroll to display that part of the page. The fragment identifier
introduced by a hash character (#) is the optional last part of a URL for a document.
Note: Scheme and host components of a URL are not case-sensitive, but path and query string
are case-sensitive. Usually the whole URL is specified in lower case.
HTML Validation
To prevent this you can test or validate your HTML code against the formal guidelines and
standards set by the Wide Web Consortium (W3C) for HTML/XHTML web pages.
The World Wide Web Consortium provide a simple online tool (https://validator.w3.org/) that
automatically check your HTML code and point out any problems/errors your code might have,
such as missing closing tags or missing quotes around attributes.
There are several specific reasons for validating a web page, some of them are:
● It helps to create web pages that are cross-browser, cross-platform compatible. It also
likely to be compatible with the future version of web browsers and web standards.
● Standards compliant web pages increase the search engine spiders and crawlers visibility,
as a result your web pages will more likely be appear in search results.
● It will reduce unexpected errors and make your web pages more accessible to the visitor.
Note: Validation is important. It will ensure that your web pages are interpreted in the same way
(the way you want it) by the various web browsers, search engines etc.
To map the wide range of characters that is used worldwide, a two-step process is used: