Bachelore of Computer Applications ST - Xavier'S College - Krupa Shah
Bachelore of Computer Applications ST - Xavier'S College - Krupa Shah
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
• The <!DOCTYPE> Declaration
Version Year
HTML 1991
HTML 2.0 1995
HTML 3.2 1997
HTML 4.01 1999
XHTML 2000
HTML5 2014
• Write HTML Using Notepad or TextEdit
• Web pages can be created and modified
by using professional HTML editors.
• However, for learning HTML we
recommend a simple text editor like
Notepad (PC) or TextEdit (Mac).
• We believe using a simple text editor is a
good way to learn HTML.
• HTML Documents
• All HTML documents must start with a document type
declaration: <!DOCTYPE html>.
• The HTML document itself begins with <html> and ends
with </html>.
• The visible part of the HTML document is
between <body> and </body>.
• Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
• HTML Headings
• HTML headings are defined with the <h1> to <h6> tags.
• <h1> defines the most important heading. <h6> defines the least
important heading:
• Example
• Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
• HTML Links
• HTML links are defined with the <a> tag:
• Example
<A HREF=“1.html">This is a link</A>
• Example
• <button>Click me</button>
• HTML Lists
• HTML lists are defined with
the <ul>(unordered/bullet list) or
the <ol>(ordered/numbered list) tag,
followed by <li>tags (list items):
• Example
• <ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
HTML Elements
• An HTML element usually consists of a start tag
and end tag, with the content inserted in between:
• <tagname>Content goes here...</tagname>
• The HTML element is everything from the start tag to the
end tag:
• <p>My first paragraph.</p>
• HTML elements with no content are called empty elements.
Empty elements do not have an end tag, such as the <br>
element (which indicates a line break).
</body>
</html>
• Example Explained
• The <html> element defines the whole document.
• It has a start tag <html> and an end tag </html>.
• The element content is another HTML element
(the <body> element).
• The <body> element defines the document body.
• It has a start tag <body> and an end tag </body>.
• The element content is two other HTML elements
(<h1> and <p>).
• The <h1> element defines a heading.
• It has a start tag <h1> and an end tag </h1>.
• The element content is: My First Heading.
• The <p> element defines a paragraph.
• It has a start tag <p> and an end tag </p>.
• The element content is: My first paragraph.
• 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
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
• HTML Text Color
• The color property defines the text color for an HTML
element:
• Example
• <h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
• HTML Fonts
• The font-family property defines the font to be used
for an HTML element:
• Example
• <h1 style="font-family:verdana;">This is a
heading</h1>
<p style="font-family:courier;">This is a
paragraph.</p>
• HTML Text Size
• The font-size property defines the text size for an
HTML element:
• Example
• <h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
• Note: Browsers display <strong> as <b>,
and <em> as <i>. However, there is a difference in the
meaning of these tags: <b> and <i> defines bold and
italic text, but <strong> and <em> means that the text
is "important".
• HTML <small> Element
• The HTML <small> element
defines smallertext:
• Example
• <h2>HTML<small>Small</small> Formatting</h2>
• Example
• <!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Remember to add more information here -->
• Comments are also great for debugging HTML,
because you can comment out HTML lines of code,
one at a time, to search for errors:
• Example
• <!-- Do not display this at the moment
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
• HTML Colors
• HTML colors are specified using predefined
color names, or RGB, HEX, HSL, RGBA, HSLA
values.
• Color Names
• In HTML, a color can be specified by using a
color name:
• Tomato
• Orange
• DodgerBlue
• MediumSeaGreen
• Gray
• SlateBlue
• Violet
• LightGray
• Background Color
• You can set the background color for HTML
elements:
• <h1 style="background-
color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">Lorem
ipsum...</p>
• Text Color
• You can set the color of text:
<h1 style="color:Tomato;">Hello World</h1>
<p style="color:DodgerBlue;">Lorem
ipsum...</p>
<p style="color:MediumSeaGreen;">Ut wisi
enim...</p>
• Border Color
• You can set the color of borders:
<h1 style="border:2px solid
Tomato;">Hello World</h1>
<h1 style="border:2px solid
DodgerBlue;">Hello World</h1>
<h1 style="border:2px solid
Violet;">Hello World</h1>
• Color Values
• In HTML, colors can also be specified using RGB
values, HEX values, HSL values, RGBA values,
and HSLA values:
• Same as color name "Tomato":
• rgb(255, 99, 71)
• #ff6347
• hsl(9, 100%, 64%)
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1>
<h1 style="background-color:rgba(255, 99, 71, 0.5);">...</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.5);">...</h1>
• RGB Value
• In HTML, a color can be specified as an RGB
value, using this formula:
• rgb(red, green, blue)
• Each parameter (red, green, and blue) defines
the intensity of the color between 0 and 255.
• For example, rgb(255, 0, 0) is displayed as red,
because red is set to its highest value (255)
and the others are set to 0.
• To display the color black, all color parameters
must be set to 0, like this: rgb(0, 0, 0).
• To display the color white, all color parameters
must be set to 255, like this: rgb(255, 255,
255).
• HEX Value
• In HTML, a color can be specified using a hexadecimal
value in the form: #rrggbb
• Where rr (red), gg (green) and bb (blue) are
hexadecimal values between 00 and ff (same as
decimal 0-255).
• For example, #ff0000 is displayed as red, because red
is set to its highest value (ff) and the others are set to
the lowest value (00).
• #ff0000
• #0000ff
• #3cb371
• #ee82ee
• #ffa500
• #6a5acd
• HSL Value
• In HTML, a color can be specified using hue,
saturation, and lightness (HSL) in the form:
• hsl(hue, saturation, lightness)
• Hue is a degree on the color wheel from 0 to 360. 0 is
red, 120 is green, and 240 is blue.
• Saturation is a percentage value, 0% means a shade of
gray, and 100% is the full color.
• Lightness is also a percentage, 0% is black, 50% is
neither light
• Saturation
• Saturation can be described as the intensity of a color.
• 100% is pure color, no shades of gray
• 50% is 50% gray, but you can still see the color.
• 0% is completely gray, you can no longer see the color.
• or dark, 100% is white
• Lightness
• The lightness of a color can be described
as how much light you want to give the
color, where 0% means no light (black),
50% means 50% light (neither dark nor
light) 100% means full lightness (white).
• Styling HTML with CSS
• CSS stands for Cascading Style Sheets.
• CSS describes how HTML elements are to be
displayed on screen, paper, or in other media.
• CSS saves a lot of work. It can control the
layout of multiple web pages all at once.
• CSS can be added to HTML elements in 3 ways:
• Inline - by using the style attribute in HTML
elements
• Internal - by using a <style> element in
the <head> section
• External - by using an external CSS file
• The most common way to add CSS, is to keep the
styles in separate CSS files. However, here we will use
inline and internal styling, because this is easier to
demonstrate, and easier for you to try it yourself.
• Inline CSS
• An inline CSS is used to apply a unique style to a single
HTML element.
• An inline CSS uses the style attribute of an HTML
element.
• This example sets the text color of the <h1>element to
blue:
• Example
• <h1 style="color:blue;">This is a Blue Heading</h1>
• Internal CSS
• An internal CSS is used to define a style for a single
HTML page.
• An internal CSS is defined in the <head>section of an
HTML page, within a <style>element:
• Example
• <!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
• External CSS
• An external style sheet is used to define
the style for many HTML pages.
• With an external style sheet, you can
change the look of an entire web site,
by changing one file!
• To use an external style sheet, add a link
to it in the <head> section of the HTML
page:
• <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
• An external style sheet can be written in
any text editor. The file must not contain
any HTML code, and must be saved with
a .css extension.
• Here is how the "styles.css" looks:
• body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
• CSS Fonts
• The CSS color property defines the text
color to be used.
• The CSS font-family property defines the
font to be used.
• The CSS font-size property defines the
text size to be used.
• CSS Border
• The CSS border property defines a border
around an HTML element:
• Example
• p {
border: 1px solid powderblue;
}
• CSS Padding
• The CSS padding property defines a padding
(space) between the text and the border:
• Example
• p {
border: 1px solid powderblue;
padding: 30px;
• CSS Margin
• The CSS margin property defines a
margin (space) outside the border:
• Example
• p {
border: 1px solid powderblue;
margin: 50px;
}
• The id Attribute
• To define a specific style for one special
element, add an id attribute to the element:
• <p id="p01">I am different</p>
• then define a style for the element with the
specific id:
• Example
• #p01 {
color: blue;
}
• Note: The id of an element should be
unique within a page, so the id selector
is used to select one unique element!
• The class Attribute
• To define a style for a special type of
elements, add a class attribute to the
element:
• <p class="error">I am different</p>
• then define a style for the elements with
the specific class:
• Example
• p.error {
color: red;
}
• External References
• External style sheets can be referenced
with a full URL or with a path relative to
the current web page.
• This example uses a full URL to link to a
style sheet:
• Example
• <link rel="stylesheet" href="https://www
.w3schools.com/html/styles.css">
• This example links to a style sheet
located in the html folder on the current
web site:
• Example
• <link rel="stylesheet" href="/html/styles.
css">
• This example links to a style sheet
located in the same folder as the current
page:
• Example
• <link rel="stylesheet" href="styles.css">
Tag Description