Professional Documents
Culture Documents
• Introduction to HTML
• What is HTML and Where did it come from?
• HTML Syntax
• Semantic Markup
• Structure of HTML Documents
• Quick Tour of HTML Elements
• HTML5 Semantic Structure Elements
• Introduction to CSS
• What is CSS
• CSS Syntax
• Location of Styles
• Selectors
• The Cascade: How Styles Interact
• The Box Model
• CSS Text Styling
06/01/2023 Ms karthiga G 18CS63 1
What is HTML and Where did it come from?
A Brief History
• Advanced Research Projects Agency Network (ARPANET)
XHTML
Stands for EXtensible HyperText Markup Language.
Developed by W3C.
XHTML was developed by W3C because HTML 4.01 was not purely created by
them.
Main reason for creation of XHTML was the lenient nature of web browsers
towards HTML.
XHTML standard forced the web developers to create web pages without
syntax errors.
06/01/2023 Ms karthiga G 18CS63 11
What is HTML and Where did it come from?
In order to make the transition from HTML to XHTML easier for web
developers, 2 versions of XHTML were created. They were,
• XHTML 1.0 Transitional
• XHTML 1.0 Strict
HTML validators were used to test and certify that a website follows XHTML
standards.
In mid 2000s, a draft for XHTML 2.0 was presented by W3C.
HTML 5
As the specifications for XHTML 2.0 was being developed, a group within
W3C was formed.
The members of this group were developers from Opera and Mozilla.
The main reason for the formation of WHATWG was the dissatisfaction with
strict XHTML 2.0 specifications and its imposition on web developers.
WHATWG announced
“The Web Hypertext Applications Technology working group therefore intends
to address the need for one coherent development environment for Web
applications, through the creation of technical specifications that are intended to
be implemented in mass-market Web browsers.”
This forced W3C to stop work on XHTML 2.0 and adopt the WHATWG
standard.
Every tag has an element name enclosed within angular brackets, i.e.,
<element_name>
For example,
<element_name> content </element_name>
<p> Welcome</p>
Example
Opening tag Closing tag
Example
The <head> and <body> elements are used to represent the head and body
sections.
Head Section:
The Head sections contains elements that describe the HTML document.
We will now have a look at all the elements that are present within the
<head> in our example.
<head lang=“en”>
<meta charset=“utf-8” />
<title>Share your travels - - New York - - Central Park</title>
<link rel=“stylesheet” href=“css/main.css” />
<script src=“js/html5shiv.js”></script>
</head>
lang
It is an attribute that tells the browser what natural language is being used
for the textual content in the HTML document.
In our example, the language used is English.
<script src=“js/html5shiv.js”></script>
The <script> element is used to refer to a JavaScript file.
Common uses for JavaScript are image manipulation, form validation, and
dynamic changes of content.
06/01/2023 Ms karthiga G 18CS63 26
STRUCTURE OF HTML DOCUMENTS
Body Section:
This section contains contents that will be displayed by the browser.
The body can contain both HTML elements and regular text.
<body>
<h1> Main Heading goes here</h1>
…………………………
…………………………
</body>
Headings
There are 6 levels of headings in HTML(h1, h2, …, h6).
A paragraph is a Container.
Inline HTML elements are those that do not cause a paragraph break.
The inline elements used in this document are <a> and <strong>.
In order to give extra space between words, we use   (non breaking
space) between the words.
To display text in multiple lines, we use the <br> line break tag.
Another alternative to achieve this is using the <pre> Preformatted text element.
It is also possible to create divisions or sections in a HTML document using the
<div> element.
The <div> tag is also a container that contains text and also other container
elements like <p>.
This tag has no visual effect on the text by its own. It’ll have its effect when used
in combination with CSS.
Simple Division example
Links
Links are an essential feature of all web pages.
• The URL of the page the link goes to, is specified as the value to href.
• The Label of a link is the text representing the link that appears on the
browser window.
Links that are instructions to the browser to start the user’s email program.
• Link to email
<a href="mailto:person@somewhere.com">Someone</a>
On the other hand, Relative referencing is used when the resource is in the
same server as our HTML document.
The URL will not have “http://” if the resource is in the same server as the html
document.
Hence, this is an indication for the browser to request the resource from the
current server.
Also if all resources for the site are placed in the same directory, then the
resources can be accessed by just specifying the file name.
But in most cases, all resources are not stuffed in one location.
1. Same Directory
To link to a file within the same folder, simply
use the file name.
<a href="example.html">
2. Child Directory
To link to a file within a subdirectory, use the
name of the subdirectory and a slash before the
file name.
<a href="images/logo.gif">
3. Grandchild/Descendant Directory
To link to a file that is multiple subdirectories
below the current one, construct the full path by
including each subdirectory name (separated by
slashes) before the file name.
<a href="css/images/background.gif">
4. Parent/Ancestor Directory
Use “../” to reference a folder above the
current one. If trying to reference a file
several levels above the current one,
simply string together multiple “../”.
<a href="../about.html“>
5. Sibling Directory
Use “../” to move up to the appropriate
level, and then use the same technique as
for child or grandchild directories.
<a href="../images/logo.gif">
6. Root Reference
An alternative approach for ancestor and
sibling references is to use the so-called
root reference approach. In this approach,
begin the reference with the root reference
(the “/”) and then use the same technique
as for child or grandchild directories.
<a href="/about.html">
7. Default Document
Web servers allow references to directory
names without file names. In such a case,
the web server will serve the default
document, which is usually a file called
index.html (Apache) or default.html
(IIS).
<a href="members">
As already seen, inline elements are those that do not disrupt the flow of the text in the
document.
Images
Images are included in a HTML document using the <img> tag.
Where
alt – an alternative text that appears if the image does not get displayed
due to problems like poor connection.
title – this string appears when we place the cursor on the image.
Character Entities
Some characters cannot be typed straightway using the keyboard like the
copyright symbol, trademark symbol etc.
There are also characters whose meaning is reserved in HTML like ‘<’, ‘>’.
If we use the less than (<) or greater than (>) signs in our text, the browser
might mix them with tags.
Lists
HTML provides three types of lists:
Unordered lists
This list is a collection of items that are not in order.
By default, these items are displayed as bulleted items.
Ordered lists
This list is a collection of items that are in order.
By default, these items are displayed as numbered items.
Definition lists
Collection of name and definition pairs
Tag Description
<ul> Defines an unordered list
<ol> Defines an ordered list
<li> Defines a list item
<dl> Defines a description list
<dt> Defines a term in a description list
<dd> Describes the term in a description list
These elements reduced the complexity that was involved with the
extensive use of <div> element.
These elements do not have any visual impact on the contents of the
HTML document.
The header and footer sections are created in a HTML document using the
<header> and <footer> tags respectively.
<footer>
<p><small>Author: Randy Conolly, Ricardo Hoar</small></p>
<p><a href="mailto:conolly@example.com">Contact Mail</a></p>
</footer>
</article>
06/01/2023 Ms karthiga G 18CS63 57
HTML5 Semantic Structure Elements
Heading Groups
All headings within a header can be grouped together using the <hgroup> element.
<header>
<hgroup>
<h1>Chapter Two: HTML 1</h1>
<h2>An Introduction</h2>
</hgroup>
</header>
Navigation
The <nav> tag defines a set of navigation links.
These links could be links to other pages or to other parts within the same page.
<nav role="navigation">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="browse.html">Browse</a></li>
</ul>
</nav>
<section>
<h3> Chennai Super Kings </h3>
<p> The Chennai Super Kings (CSK) are a franchise cricket team based in Chennai, Tamil
Nadu, which plays in the Indian Premier League (IPL). Founded in 2008, the team plays its
home matches at the M. A. Chidambaram Stadium in Chennai. </p>
</section>
<section>
<h3>Royal Challengers Bengaluru </h3>
<p><The Royal Challengers Bangalore (often abbreviated as RCB) are a franchise cricket
team based in Bangalore, Karnataka, that plays in the Indian Premier League (IPL). It was
founded in 2008 by United Spirits . </p>
</section>
This means, if there are contents in a HTML document that are referred
from other source, then such contents are enclosed in the <article> tag.
The label for the content of <figure> tag is given using the <figcaption> tag.
<p>This photo was taken on October 22, 2011 with a Canon EOS
30D camera.</p>
<figure>
<img src="images/central-park.jpg" alt="Central Park" /><br/>
<figcaption>Conservatory Pond in Central Park</figcaption>
</figure>
Aside
<aside> element is used to represent content that is related to the content that
surrounds this element.
A popular example is the related videos for a YouTube video that gets
displayed on the right side of the browser window.
We need to keep in mind that, just by wrapping contents within the aside tag,
the contents do not get to the side of the window.
Such positioning can be done with the support of CSS. <aside> is just a
semantic structural element.
Benefits of CSS
Improved control over formatting
Improved site maintainability
Improved accessibility
Improved page download speed
Improved output flexibility(Responsive Design)
CSS Versions
Several style sheet standards were proposed in the early 90s.
As work was going on with CSS 2.1, another group in W3C were
working on CSS3 in parallel.
Out of the various modules of CSS3, only the following have been
officially adopted by W3C:
• CSS Selectors
• CSS Namespaces
• CSS Media Queries
• CSS Color.
The declarations within a block can be mentioned in a single line or spread across
multiple lines.
Declaration
Declaration Block
p{
em { color: red; } margin: 5px 0 10px 0;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
Selectors
Selectors are a pattern that is used by the browser to select the HTML
elements that will receive the style.
CSS ID Selector
* {
text-align: center;
color: blue;
}
[attribute] {
declaration 1;
declaration 2; }
Attribute Selectors
Some pseudo selectors are listed below. Pseudo element selector example
• Contextual Selectors
These selectors are also called as Combinators.
Properties
Each CSS declaration block is made up of several property-value pairs.
Fonts
Fonts is a property type. It contains several properties as listed below:
Property Description Possible Values
Family-name - times, arial
font-family Specifies the font for an element. Generic-family - serif, sans-
serif
font-size Sets the size of a font. small, 20px, 150%
font-style Specifies the font style for a text. normal, italic, oblique
font-weight Sets how thick or thin characters bold, light, 100, 400, 700, 900
in text should be displayed.
Font is another property that belongs to the Fonts property type. It is a shorthand that
represents all the above properties.
Fonts example
background- Sets the starting position of a background left, right top, 50% 50%,
position image. 100px 100px
repeat, no-repeat, repeat-
background- Sets if/how a background image will be
x, repeat-y, space, round
repeat repeated.
red, #000000,
color Specifies the color of text. rgb(0,255,0),
06/01/2023 Ms karthiga G 18CS63 86
CSS SYNTAX
Borders
Property Description Possible Values
red, #000000,
border-color Used to set the color of the four borders. rgb(0,0,0)
border-width Specifies the width of the four borders. thick, medium, 5px
dotted, dashed, solid,
border-style Specifies what kind of border to display. double
Sets all the top border properties in one { border-top: 4px dotted
border-top blue; }
declaration.
border-top- red, #000000,
Sets the color of an element's top border. rgb(0,0,0)
color
border-top-
Sets the width of an element's top border. thick, medium, 5px
width
Specifies the display behaviour (the type of rendering box) of block, inline, content
display
an element.
Specifies on which sides of an element floating elements are left, right, both
clear
not allowed to float.
Lists
Values
For instance, the color property can have a name(red, blue), RGB
combo(rgb(255,0,0)), hex values(#FF0000), RGBa
combo(rgb(255,0,0,0.5)), HSL combo(hsl(0,50%,100%)).
Relative (CSS2)
px Pixel. Absolute (CSS3)
Defined the size as number of times * the size of the Relative
em 2em, 0.5em
parent element.
Relative
% Defined the size as x% of the size of the parent element. 10%
Inline styles
These are style rules that are placed within a HTML element using the style attribute.
Such a style only affects the element within which it is defined in.
This styling is not advisable as it is a deviation from the concept of HTML being a
semantic markup.
Here, the style declaration is placed within the <style> element in the <head> section
of the HTML document.
Like inline styles, this approach is also discouraged as it violates the semantic markup
philosophy of a HTML document.
<head lang="en"><style>
h1 { font-size: 24pt; }
h2 { font-size: 18pt; font-weight: bold; }
</style></head>
<body>
<h1>Share Your Travels</h1>
<h2>New York - Central Park</h2>
Here the style rules are placed within an external text file with the .css extension.
To reference an external style sheet, we must use a <link> element within the <head>
element.
Each linked style sheet will require its own <link> element.
<head lang="en">
<title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="styles.css" />
</head>
It is possible that multiple style rules are defined for the same HTML
element.
Hence, there must be provisions that can handle such rule conflicts.
Cascade is the mechanism that controls which rule applies when there is
such a conflict.
When two rules apply to the same element, the one that comes last
in the CSS is the one that will be used.
There are 3 cascade principles that CSS uses to deal with conflicts:
• Inheritance
• Specificity
• Location
Inheritance
There are several CSS properties that not only affect the element on
which they are applied, but also the descendants of the element.
Properties like Font, color, text properties are inheritable while layout,
sizing, border, background and spacing properties are not.
Three special universal property values are provided by CSS for controlling
inheritance. They are:
Inherit
Sets the property value applied to a selected element to be the same as that of
its parent element.
Initial
Sets the property value applied to a selected element to the initial/default
value of that property defined by the browser.
Unset
Resets the property to its natural value, which means that if the property is
naturally inherited it acts like inherit, otherwise it acts like initial.
Inheritance Example
06/01/2023 Ms karthiga G 18CS63 100
THE CASCADE: HOW STYLES INTERACT
Inheritance Example
Inheritance Example
Specificity
Specificity decides which style rule takes precedence when multiple
rules are applied to the same element.
One way by which the browser accomplishes this is, it assigns weights
to the style rules.
When multiple rules clash on one element, the rule with the highest
weight gets the priority and is applied.
Specificity Example
Specificity algorithm
Location
If there are multiple rules that have the same specificity, then the latest
rule will be given more weightage.
It is possible that multiple style rules are defined for the same HTML
element.
Hence, there must be provisions that can handle such rule conflicts.
Cascade is the mechanism that controls which rule applies when there is
such a conflict.
When two rules apply to the same element, the one that comes last
in the CSS is the one that will be used.
There are 3 cascade principles that CSS uses to deal with conflicts:
• Inheritance
• Specificity
• Location
Inheritance
There are several CSS properties that not only affect the element on
which they are applied, but also the descendants of the element.
Properties like Font, color, text properties are inheritable while layout,
sizing, border, background and spacing properties are not.
Three special universal property values are provided by CSS for controlling
inheritance. They are:
Inherit
Sets the property value applied to a selected element to be the same as that of
its parent element.
Initial
Sets the property value applied to a selected element to the initial/default
value of that property defined by the browser.
Unset
Resets the property to its natural value, which means that if the property is
naturally inherited it acts like inherit, otherwise it acts like initial.
Inheritance Example
06/01/2023 Ms karthiga G 18CS63 111
THE CASCADE: HOW STYLES INTERACT
Inheritance Example
Inheritance Example
Specificity
Specificity decides which style rule takes precedence when multiple
rules are applied to the same element.
One way by which the browser accomplishes this is, it assigns weights
to the style rules.
When multiple rules clash on one element, the rule with the highest
weight gets the priority and is applied.
Specificity Example
Specificity algorithm
Location
If there are multiple rules that have the same specificity, then the latest
rule will be given more weightage.
Background
Background Repeat
Background Position
Borders
Borders provide a way to visually separate elements.
When the vertical margins of two elements touch, only the largest
margin value of the elements will be displayed.
Box Dimensions
In this section, we find out how to determine the actual size of a HTML element.
For any given element, its height and width correspond to the size of the content in that
element.
For instance, size of a textual element is determined by the font size and font face of
the text in it.
For images, the width and height of the actual image in pixels is the size of the element.
An element could also have padding, borders and margins defined.
Since these additions are also part of an element, the size of an element
should also take into account the margins and paddings.
Hence, the total size of an element is equal to the size of its content area
plus the sum of its padding, borders, and margins.
For instance, we may define the height of a <p> as 100px while the contents of the
paragraph might require 200px height to be accommodated.
In such cases, the extra contents of the box are said to overflow the box.
Box Overflow
Font Properties
Font Family
There is a possibility that a font used for some text in the HTML document is not
available at the console of all the users accessing the document.
Hence it is always a good practice to provide a Web Font Stack to the Font
Family property.
Web Font Stack is a series of alternate fonts to use, in case the original font
choice is not on the user’s computer.
There is no real limit to the number of fonts that one can specify with the
font-family property.
The values for the property follow this order: ideal, alternative, common
and then generic.
Font Sizes
In this section we will see how relative units like em and percentages will work
on font sizes.
One complication that can occur with relative font size values is, if nested elements
have relative font sizes.
Another relative font size unit is presented here. The unit is rem.