1.1. HTML
1.1. HTML
• Hypertext Markup
Language is the
standard markup
language used to
develop web pages. It
has emerged over time
and has various
significant features that
allow web developers to
make web pages with
rich content and
functionality.
• We can put attributes after the element name in the opening tag only,
never in the closing tag.
• Most HTML attributes take values, which follow an equal sign (=). Some
attribute values take a single descriptive word.
• The SGML declaration. The SGML declaration specifies which characters and
delimiters may appear in the application.
• The document type definition (DTD). The DTD defines the syntax of markup constructs.
The DTD may include additional definitions such as numeric and named character
entities.
• Document instances containing data (contents) and markup. Each instance contains
a reference to the DTD to be used to interpret it.
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
</HEAD>
<BODY>
<h1>This is a heading</h1>
</BODY>
</HTML>
2/22/2024 Prepared By : Basanta Chapagain 35
Here's the anatomy/structure of a basic HTML 5
page:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
2/22/2024 Prepared By : Basanta Chapagain 36
Standard format of HTML Document
<!DOCTYPE html>
<html>
<head>
<title>Definition of HTML</title>
</head>
<body>
</body>
</html>
2/22/2024 Prepared By : Basanta Chapagain 37
Let’s learn individual element of HTML document
<!Doctype html>:
• Specifies that we're using HTML5 in this code. Before the
introduction of HTML5, you had to explicitly state which version of
HTML you were coding in with the <!Doctype> tag.
• For example, HTML4.0, 3.2, and so on. But now we no longer
need it. When “html” is written in the code, the browser
automatically assumes that you are coding in HTML5.
<html></html>:
• the root, or top-level element of every HTML document. Every
other element must be wrapped in it.
<html>
<head>
</head>
<body>
<h1>Welcome to my website!</h1>
</body>
</html>
Step 2: To save your page in Sublime Text editor, press Ctrl+S or go to File option ⤏ save.
Use .html or .htm extension to save your file. We recommend saving the file first, then write
the code because sublime editor will give you suggestions to write code after saving the
page.
• lists: UL and LI
• sections <section>
• Division <div>
• Form <form>
• Table <table>
<html>
<body>
<head>
<title>Block Element</title>
</head>
<h1>Hello</h1>
<p>This para will be displayed on new line because it is a block level element</p>
</body>
</html>
<html>
<body>
<head>
<title>Inline Element</title>
</head>
<span>Hello !!!</span>
<a href="https://www.google.com">Hello</a>
<a href="https://www.google.com">Hello</a>
</body>
</html>
• <b>
• <i>
• <em>
• <big>
• <strong>
• <small>
• <sup>
• <sub>
• <bdo>
• <u>
• <table>
• <caption>
• <th>
• <tr>
• <td>
• <thead>
• <tbody>
< <
> >
" "
' '
&
2/22/2024 &
Prepared By : Basanta Chapagain 68
Entity references: Including special
characters in HTML:Example
<p>In HTML, you define a paragraph using the <p> element.</p>
<p>In HTML, you define a paragraph using the <p> element.</p>
• In the above code, you can see that the first paragraph has gone
wrong. The browser interprets the second instance of <p> as starting
a new paragraph. The second paragraph looks fine because it has
angle brackets with character references.
<strong> This is a logical tag, which tells the browser that the text is important.
<tt> This tag is used to appear a text in teletype. (not supported in HTML5)
<strike> This tag is used to draw a strikethrough on a section of text. (Not supported in HTML5)
<small> This tag is used to decrease the font size by one unit from base font size.
2/22/2024 Prepared By : Basanta Chapagain 83
Formatting Tags
Bold Text
• HTML<b> and <strong> formatting elements
• The HTML <b> element is a physical tag which display text in bold
font, without any logical importance. If you write anything within
<b>............</b> element, is shown in bold letters.
• The HTML <i> element is physical element, which display the enclosed
content in italic font, without any added importance. If you write
anything within <i>............</i> element, is shown in italic letters.
Output:
Superscript Text
• If you put the content within <sup>..............</sup> element, is
shown in superscript; means it is displayed half a character's height
above the other characters.
<p>Hello <sup>Write Your First Paragraph in superscript.</sup></p>
Deleted Text
• Anything that puts within <del>..........</del> is displayed as deleted
text.
<p>Hello <del>Delete your first paragraph.</del></p>
Larger Text
• If you want to put your font size larger than the rest of the text then
put the content within <big>.........</big>. It increase one font size
larger than the previous one.
<p>Hello <big>Write the paragraph in larger font.</big></p>
2/22/2024 Prepared By : Basanta Chapagain 91
Formatting Tags
Smaller Text
• If you want to put your font size smaller than the rest of the text
then put the content within <small>.........</small>tag. It reduces
one font size than the previous one.
<p>Hello <small>Write the paragraph in smaller font.</small></p>
Code tags:
• An HTML <code> </code> element is used to display the part of
computer code.
Address tag:
The <address> tag provides the contact information about the author of the content.
<address> You can ask your queries by contact us on <a href=" ">[email protected]</a>
</address>
2/22/2024 Prepared By : Basanta Chapagain 98
CSS(Cascading Stylesheet)
• CSS (Cascading Stylesheet) is used to apply the style on the
web page which is made up of HTML elements. It creates the
look of the webpage.
• CSS provides different style properties such as background color,
padding, margin, border-color, etc, to style a webpage.
• Three different ways to apply CSS (Types )
– Inline CSS
– Internal or Embedded CSS
– External CSS
color: #f08080;}
p{font-size: 20px;}
</body>
<head>
</head>
<body>
</body>
2/22/2024 Prepared By : Basanta Chapagain 105
CSS- External CSS
p{
body{
font-size: 20px;
background- }
color:lavender; .blue{
text-align: center; color: blue;
}
}
.red{
h2{ color: red;
}
font-style: italic;
.green{
size: 30px; color: green;
color: #f08080;
}
*{
property: value;
You can use the universal selector to reset the browser's default padding and margin to zero at the
top of the file before you add any other styles:
*{
padding: 0;
margin: 0;
}
2/22/2024 Prepared By : Basanta Chapagain 109
CSS Type Selector
• The CSS type selector selects all HTML elements of the specified
type.
• To use it, mention the name of the HTML element.
• For example, if you wanted to apply a style to every single
paragraph in the HTML document, you would specify the p
element:
p{
property: value;
}
• The code above matches and selects all p elements within the
document and styles them.
2/22/2024 Prepared By : Basanta Chapagain 110
CSS Class Selector
• The class selector matches and selects HTML elements based on the value of
their given class. Specifically, it selects every single element in the document
with that specific class name.
• With the class selector, you can select multiple elements at once and style them
the same way without copying and pasting the same styles for each one
separately.
• Classes are reusable, making them a good option for practicing DRY
development. DRY is a programming principle and is short for 'Don't Repeat
Yourself'. As the name suggests, the aim is to avoid writing repetitive code
whenever possible.
property: value;
}
2/22/2024 Prepared By : Basanta Chapagain 115
CSS Attribute Selectors
a[attr] {
property: value;
}
• In the example above, a elements with the attr attribute name are selected,
regardless of the value of attr.
• You can be more specific with your styling.
• The [attribute="value"] Selector
• You can specify the value of the attribute using the following syntax:
element[attribute="value"]
• They were built on top of each other with better adaptability and
more features.
• Each one had issues that were solved by the next standard.
• CSS got major adaptability issues with multiple web browsers
coming up all these years starting from Internet Explorer, Opera,
Firefox, Chrome and Edge.
• RGB colors have three values that represent: red, green, and blue
<a name="Content"></a>Content
In the first code sample, you link from the bottom of a page back to the beginning, so users can
quickly get to the top of the page without having to scroll for a long time. In the second example,
users can directly access a part of the page, for example a subdivision point. By clicking, users are
guided via name attribute directly to the subject.
<a href="#Content">Content</a>
By simply setting a hash tag (#) at the anchor name, the browser can identify a jump within the
page.
You can also link to a specific location on another page internally. This would be defined as follows:
<a href="anotherpage.html#name">Linktext</a>
_self Opens the linked document in the same frame as it was clicked (this is default)
_top Opens the linked document in the full body of the window
• If the user hovers with the mouse over a link reference, the title text, which
was defined in the attribute, will be displayed. This can be a tool tip, or
description of the resource to which the link directs. The data from the title
attribute makes the site more user-friendly.
• The title attribute can also be used for images and graphic files to give a brief
description of what is shown in the picture.
The title attribute for Anchor Tags generally has no direct effect on
SEO. However, the use of title attributes and elements on links or
images can increase the click-through rate and thus indirectly
affect the user signals that Google receives from the website.
2/22/2024 Prepared By : Basanta Chapagain 169
<a> tag Style
When referencing the special attributes of the anchor tag, such
as link, visited, hover, and active.
• link- This references the text of the link itself. Note that there are 2 ways in
CSS in which we can modify the text of a link. We can either just directly
reference the class name of the link. Referencing the attribute link is the
same as referencing the class name directly. (.classname { } and
.classname:link{ } both reference the same text of the link.
• visited- This refers to a link on a page after the user has clicked on it. After
the user clicks on a link, the link is said to be visited. After this link is visited,
you can change its appearance to anything you want it to be. Most of
the times, simply the color is changed, so that the user visiting a site can
know that s/he has already clicked on that link.
a :visited {color:green;}
a:hover {color:yellow;}
a:active {color:red;}
a[href^="http"] {
padding-right: 19px;
}
<a href="#">Top It Center in Nepal</a>
Syntax:
OR
border-style
border-color: red;
The border sub-properties and property can also be applied to an individual side of a
web element.
border-left: green;
border-top: pink;
border-right: blue;
border-bottom: skyblue;
left
Defines the alignment of the
right
image in reference to
align top
surrounding elements.
bottom
Not supported in HTML5.
middle
Specifies the URL address with a detailed description of the image (For a short
longdesc URL description of the image, use the alt attribute.
Not supported in HTML5.
Specifies a link to the <map> element, which contains the coordinates for the
usemap #mapname
client map image.
img {
object-fit: cover;
• https://sharkcoder.com/blocks/list
• https://learn.shayhowe.com/html-css/creating-lists/
• https://developer.mozilla.org/en-US/docs/Web/CSS/list-style
• The background color property can be applied to various HTML elements, such as <body>,
<div>, <p>, <span>, etc. Here's the basic syntax:
selector {
background-color: value;
• The selector is the HTML element or class/id selector to which you want to apply the
background color. The value represents the desired color for the background.
Example
p{
background-color: yellow;
selector {
background-image: url("path/filename");
In the example above, replace "path/filename" with the actual path to your image file.
You can also specify additional properties to control how the background image is displayed,
such as background-repeat, background-size, and background-position. Here's an example
that includes some of these properties:
Example
body {
background-image: url(“image.png”);
• repeat-x: The background image is repeated only horizontally. It will be displayed in a row,
repeating horizontally to cover the width of the element. The image is not repeated
vertically.
• no-repeat: The background image is not repeated. It is displayed only once and will not be
repeated in any direction. If the image is smaller than the element, it may be cropped or
not fully displayed.
• space: This value is similar to repeat, but it adds space between the repeated images. The
space is distributed evenly between the repeated images, creating gaps between them. If
there is extra space left after distributing it evenly, it will be added at the ends.
• round: This value is also similar to repeat, but it resizes the repeated images to fit the
background area without distorting them. It scales the images up or down proportionally so
that they cover the entire background area. If the images cannot be resized evenly, they
will be repeated with the remaining space distributed as evenly as possible.
<col> Used with the <colgroup> element to define column characteristics for each column.
border It specifies the width of the border of each frame in pixels. For example; border = “5”.
A value of zero means no border.
framespacing It specifies the amount of space between frames in a frameset. It can take any integer
value. For example; framespacing = “10” means there should be 10 pixels spacing
between each frame.
frameborder It specifies whether or not the borders of that frame are shown. This attribute overrides the value given in the
frameborder attribute on the <frameset> tag if one is given. This can take values either 1 (Yes) or 0 (No).
marginwidth It allows to specify the width of the space between the left and right of the frame's border and the content. The value is
given in pixels. For example; marginwidth = “10”.
marginheight It allows to specify the height of the space between the top and bottom of the frame's borders and its contents. The
value is given in pixels. For example; marginheight = “10”.
noresize By default, a user can resize any frame by clicking and dragging on the borders of a frame. It prevents a user from
being able to resize the frame. For example; noresize = “noresize”.
scrolling It controls the appearance of the scrollbars that appear on the frame. It takes values either “Yes”, “No” or “Auto”. For
example; scrolling = “no” means it should not have scroll bars.
longdesc It allows to provide a link to another page which contains a long description of the contents of the frame. For example;
longdesc = “framedescription.html”
marginwidth It sets the left and right margin of the content of an iframe. Its values can be in pixels.
longdesc It specifies the link of a page that contains a long description of the content of an iframe.
• It defines a data input field for the user. It plays important part in Html Forms.
• none: the element is not moved down to clear past floating elements
• both: the element is moved down to clear past both left and right floats
• inline-start: the element is moved down to clear floats on the start side of its containing
block; that is, the left floats on left-to-right scripts and the right floats on right-to-left
scripts
• inline-end: the element is moved down to clear floats on the end side of its containing
block; that is, the right floats on left-to-right scripts and the left floats on right-to-left
scripts
2/22/2024 Prepared By : Basanta Chapagain 273
CSS float,clear Property Example
https://tutorial.techaltum.com/css-layout-using-float.html
• What is HTML list? Explain different types of HTML list with example
• What is semantic tag in HTML? Why semantic tags are important for web development.
• What is Image Map? Difference between client side and server side image map.
• Explain different types of client side imagemap shape with proper example.
• What is HTML table? Explain importance of html table with pros and cons.
• List and explain html table tags and attributes with example.
• What is HTML frame? Why frame layout is important for web site.
Thank you.