Unit 1 HTML
Unit 1 HTML
5/9/2023
Unit - I
HTML
Introduction to web designing, difference between web applications and desktop applications, introduction to HTML, HTML
structure, elements, attributes, headings, paragraphs, styles, colours, HTML formatting, Quotations, Comments, images, tables, lists,
blocks and classes, HTML CSS, HTML frames, file paths, layout, symbols, HTML responsive.
What is HTML
HTML is an acronym which stands for Hyper Text Markup Language which is used for creating web pages and web applications.
Let's see what is meant by Hypertext Markup Language, and Web page.
Hyper Text: HyperText simply means "Text within Text." A text has a link within it, is a hypertext. Whenever you click on a link
which brings you to a new webpage, you have clicked on a hypertext. HyperText is a way to link two or more web pages (HTML
documents) with each other.
Markup language: A markup language is a computer language that is used to apply layout and formatting conventions to a text
document. Markup language makes text more interactive and dynamic. It can turn text into images, tables, links, etc.
Web Page: A web page is a document which is commonly written in HTML and translated by a web browser. A web page can be
identified by entering an URL. A Web page can be of the static or dynamic type. With the help of HTML only, we can create static
web pages.
Advantages
Disadvantages
Html Structure:
<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>
HTML Elements
An HTML file is made of elements. These elements are responsible for creating web pages and define content in that webpage. An
element in HTML usually consist of a start tag <tag name>, close tag </tag name> and content inserted between them. Technically,
an element is a collection of start tag, attributes, end tag, content between them.
Such as:
1. <p> Hello world!!! </p>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>WebPage</title>
5. </head>
6. <body>
7. <h1>This is my first web page</h1>
8. <h2> How it looks?</h2>
9. <p>It looks Nice!!!!!</p>
10. </body>
11. </html>
Test it Now
o All the content written between body elements are visible on web page.
HTML Attribute:
o HTML attributes are special words which provide additional information about the elements or attributes are the modifier of the
HTML element.
o Each element or tag can have attributes, which defines the behaviour of that element.
o Attributes should always be applied with start tag.
o The Attribute should always be applied with its name and value pair.
o The Attributes name and values are case sensitive, and it is recommended by W3C that it should be written in Lowercase only.
o You can add multiple attributes in one HTML element, but need to give space between two attributes.
Syntax
1. <element attribute_name="value">content</element>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h1> This is Style attribute</h1>
7. <p style="height: 50px; color: blue">It will add style property in element</p>
8. <p style="color: red">It will change the color of content</p>
9. </body>
10. </html>
Output:
The title attribute in HTML
Description: The title attribute is used as text tooltip in most of the browsers. It display its text when user move the cursor over a link
or any text. You can use it with any text or link to show the description about that link or text. In our example, we are taking this with
paragraph tag and heading tag.
Example
With <h1> tag:
1. <p title="This is paragraph tag">Move the cursor over the heading and paragraph, and you will see a description as a tooltip</p>
Code:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6.
7. <h1 title="This is heading tag">Example of title attribute</h1>
8. <p title="This is paragraph tag">Move the cursor over the heading and paragraph, and you will see a description as a tooltip</p>
9.
10. </body>
11. </html>
Output:
The href attribute in HTML
Description: The href attribute is the main attribute of <a> anchor tag. This attribute gives the link address which is specified in that
link. The href attribute provides the hyperlink, and if it is blank, then it will remain in same page.
Example
With link address:
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Heading elements</title>
5. </head>
6. <body>
7. <h1>This is main heading of page. </h1>
8. <p>h1 is the most important heading, which is used to display the keyword of page </p>
9. <h2>This is first sub-heading</h2>
10. <p>h2 describes the first sub heading of page. </p>
11. <h3>This is Second sub-heading</h3>
12. <p>h3 describes the second sub heading of page.</p>
13. <p>We can use h1 to h6 tag to use the different sub-heading with their paragraphs if
14. required.
15. </p>
16. </body>
17. </html>
HTML Paragraph
HTML paragraph or HTML p tag is used to define a paragraph in a webpage. Let's take a simple example to see how it work. It is a
notable point that a browser itself add an empty line before and after a paragraph. An HTML <p> tag indicates starting of new
paragraph.
See this example:
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h2> Use of line break with pragraph tag</h2>
7. <p><br>Papa and mama, and baby and Dot,
8. <br>Willie and me?the whole of the lot
9. <br>Of us all went over in Bimberlie's sleigh,
10. <br>To grandmama's house on Christmas day.
11. </p>
12. </body>
13. </html>
Test it Now
Output:
HTML Formatting
HTML Formatting is a process of formatting text for better look and feel. HTML provides us ability to format text without using
CSS. There are many formatting tags in HTML. These tags are used to make text bold, italicized, or underlined. There are almost 14
options available that how text appears in HTML and XHTML.
In HTML the formatting tags are divided into two categories:
o Physical tag: These tags are used to provide the visual appearance to the text.
o Logical tag: These tags are used to add some logical or semantic value to the text.
o Here, we are going to learn 14 HTML formatting tags. Following is the list of HTML formatting text.
Element name Description
<b> This is a physical tag, which is used to bold the text written between it.
<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)
<big> This tag is used to increase the font size by one conventional unit.
<small> This tag is used to decrease the font size by one unit from base font size.
1) 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.
See this example:
4) Underlined Text
If you write anything within <u>.........</u> element, is shown in underlined text.
See this example:
Output:
Write Your First Paragraph in underlined text.
5) Strike Text
Anything written within <strike>.......................</strike> element is displayed with strikethrough. It is a thin line which cross the
statement.
See this example:
6) Monospaced Font
If you want that each letter has the same width then you should write the content within <tt>.............</tt> element.
Note: We know that most of the fonts are known as variable-width fonts because different letters have different width. (for example:
'w' is wider than 'i'). Monospaced Font provides similar space among every letter.
See this example:
Output:
Hello Write Your First Paragraph in monospaced font.
7) 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.
See this example:
1. <p>Hello <sup>Write Your First Paragraph in superscript.</sup></p>
Output:
Hello Write Your First Paragraph in superscript.
8) Subscript Text
If you put the content within <sub>..............</sub> element, is shown in subscript ; means it is displayed half a character's height
below the other characters.
See this example:
9) Deleted Text
Anything that puts within <del>..........</del> is displayed as deleted text.
See this example:
Output:
Hello Write the paragraph in larger font.
12) 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.
See this example:
HTML Quotes:
HTML quotes are used to put a short quotation on your website. To do so, you need to use HTML q tag and HTML blockquote tag.
HTML q tag
HTML q tag is used to put small quotation. To do so, write your text within <q>.............</q> tag.
HTML Image
HTML img tag is used to display image on the web page. HTML img tag is an empty tag that contains attributes only, closing tags
are not used in HTML image element.
Let's see an example of HTML image.
It is a necessary attribute that describes the source or path of the image. It instructs the browser where to look for the image on the
server.
The location of image may be on the same directory or another server.
2) alt
The alt attribute defines an alternate text for the image, if it can't be displayed. The value of the alt attribute describe the image in
words. The alt attribute is considered good for SEO prospective.
3) width
It is an optional attribute which is used to specify the width to display the image. It is not recommended now. You should apply CSS
in place of width attribute.
4) height
It h3 the height of the image. The HTML height attribute also supports iframe, image and object elements. It is not recommended now.
You should apply CSS in place of height attribute.
HTML Table:
HTML table tag is used to display data in tabular form (row * column). There can be many columns in a row.
We can create a table to display data in tabular form, using <table> element, with the help of <tr> , <td>, and <th> elements.
In Each table, table row is defined by <tr> tag, table header is defined by <th>, and table data is defined by <td> tags.
HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body content, footer section etc. But it is
recommended to use div tag over table to manage the layout of the page .
HTML Table Tags
Tag Description
<col> It is used with <colgroup> element to specify column properties for each column.
Example:
1. <table>
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
1. <table border="1">
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain one or more list elements. There are three different types of
HTML lists:
1. <ol>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ol>
HTML Unordered List or Bulleted List
In HTML Unordered list, all the list items are marked with bullets. It is also known as bulleted list also. The Unordered list starts with
<ul> tag and list items start with the <li> tag.
1. <ul>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ul>
HTML Description List or Definition List
HTML Description list is also a list style which is supported by HTML and XHTML. It is also known as definition list where entries
are listed like a dictionary or encyclopedia.
The definition list is very appropriate when you want to present glossary, list of terms or other name-value list.
The HTML definition list contains following three tags:
Multiple Classes
You can use multiple class names (more than one) with HTML elements. These class names must be separated by a space.
Example:
Let's style elements with class name "fruit" and also with a class name "center".
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .fruit {
5. background-color: orange;
6. color: white;
7. padding: 10px;
8. }
9.
10. .center {
11. text-align: center;
12. }
13. </style>
14. <body>
15.
16. <h2>Multiple Classes</h2>
17. <p>All three elements have the class name "fruit". In addition, Mango also have the class name "center", which center-
aligns the text.</p>
18.
19. <h2 class="fruit center">Mango</h2>
20. <h2 class="fruit">Orange</h2>
21. <h2 class="fruit">Apple</h2>
22.
23. </body>
24. </html>
HTML frames
Attributes Description
cols It specifies how many columns are to be contained in the frameset and the size of each column.
(Columns)
rows It works like the 'cols' attribute and takes the same values, but it is used to specify the number of rows in the
frameset.
border It specifies the width of the border of each frame in pixels. For example; border = “5”. A value of zero means no
border.
frame It specifies whether a three-dimensional border should be displayed between frames. It takes value either 1 (Yes)
or 0 (No). For example; frameborder = “0” specifies 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.
2. <frame> tag
<frame> tag is used to define a frame within a <frameset> tag.
A frame should be used within a <frameset> tag.
Syntax:<frame src=”frm1.htm”>
Attributes Description
src It is used to give the file name that should be located in the frame. Its value can be any URL, for example, src=
“/html/abc.html”
name It allows to give a name to a frame. This attribute is used to indicate that a document should be loaded into a
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”
Example: HTML Frame
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames Example</title>
</head>
<frameset cols="50%,50%">
<frame src="http://www.careerride.com/test-login.aspx" >
<frame src="http://careerride.com/" >
</frameset>
</html>
Output:
Create Vertical frames:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Frame tag</title>
5. </head>
6. <frameset cols="25%,50%,25%">
7. <frame src="frame1.html" >
8. <frame src="frame2.html">
9. <frame src="frame3.html">
10. </frameset>
11. </html>
Output:
Frame1.html
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div{
6. background-color: #7fffd4;
7. height: 500px;
8. }
9. </style>
10. </head>
11. <body>
12. <div>
13. <h2>This is first frame</h2>
14. </div>
15. </body>
16. </html>
Frame2.html
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div{
6. background-color: #2f4f4f;
7. height: 500px;
8.
9. }
10. </style>
11. </head>
12. <body>
13. <div>
14. <h2>This is Second frame</h2>
15. </div>
16. </body>
17. </html>
Frame3.html
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div{
6. background-color: #c1ffc1;
7. height: 500px;
8. }
9. </style>
10. </head>
11. <body>
12. <div>
13. <h2>This is Third frame</h2>
14. </div>
15. </body>
16. </html>
Example 2:
Create Horizontal frames:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Frame tag</title>
5. </head>
6. <frameset rows="30%, 40%, 30%">
7. <frame name="top" src="frame1.html" >
8. <frame name="main" src="frame2.html">
9. <frame name="bottom" src="frame3.html">
10. </frameset>
11. </html>
Output:
Attribute
Tag-specific attribute
frameborder 0 It specifies whether to display a border around the frame or not, and its default value is 1
1
longdsec URL It specifies a page which contains the long description of the content of the frame.
marginheight pixels It specifies the top and bottom margins of the frame.
scrolling yes It specifies the existence of the scrollbar for overflowing content.
no
auto
src URL It specifies the URL of the document which we want to display in a frame.
1. <img src="picture.jpg"> It specifies that picture.jpg is located in the same folder as the current page.
2. <img src="images/picture.jpg"> It specifies that picture.jpg is located in the images folder in the current folder.
3. <img src="/images/picture.jpg"> It specifies that picture.jpg is located in the images folder at the root of the current web.
4. <img src="../picture.jpg"> It specifies that picture.jpg is located in the folder one level up from the current folder.
File paths are used on webpages to link external files like:
1. Web pages
2. Images
3. Style sheets
4. JavaScript
There are two types of File Paths:
1. Absolute File Paths
2. Relative File Paths
Absolute File Paths
Absolute file path specifies full URL address.
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Full URL File Path</h2>
5. <img src="https://www.javatpoint.com/images/nature-1.jpg" alt="image" style="width:300px">
6. </body>
7. </html>
Relative File Paths
The relative file path specifies to a file which is related to the location of current page.
Example:
Let's take an example to see how the file path points to a file in the images folder located at the root of the current web.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="/images/nature-2.jpg" alt="Mountain" style="width:300px">
6. </body>
7. </html>
HTML Layouts
HTML layouts provide a way to arrange web pages in well-mannered, well-structured, and in responsive form or we can say that
HTML layout specifies a way in which the web pages can be arranged.
Web-page layout works with arrangement of visual elements of an HTML document.
Web page layout is the most important part to keep in mind while creating a website so that our website can appear professional
with the great look.
You can also use CSS and JAVASCRIPT based frameworks for creating layouts for responsive and dynamic website designing.
Every website has a specific layout to display content in a specific manner.
Following are different HTML5 elements which are used to define the different parts of a webpage.
HTML <nav>
The <nav> elements is a container for the main block of navigation links. It can contain links for the same page or for other pages.
Example:
1. <nav style="background-color:#bcdeef;">
2. <h1 style="text-align: center;">Navgation Links</h1>
3. <ul>
4. <li><a href="#">link1</a></li>
5. <li><a href="#">link2</a></li>
6. <li><a href="#">link3</a></li>
7. <li><a href="#">link4</a></li>
8. </ul>
9. </nav>
HTML <section>
HTML <section> elements represent a separate section of a web page which contains related element grouped together. It can contain:
text, images, tables, videos, etc.
Example:
1. <section style="background-color:#ff7f50; width: 100%; border: 1px solid black;">
2. <h2>Introduction to HTML</h2>
3. <p>HTML is a markup language which is used for creating attractive web pages with the help of styling, and which looks in a nice
format on a web browser..</p>
4. </section>
HTML <article>
The HTML
tag is used to contain a self-contained article such as big story, huge article, etc.
Example:
1. <article style="width: 100%; border:2px solid black; background-color: #fff0f5;">
2. <h2>History of Computer</h2>
3. <p>Write your content here for the history of computer</p>
4. </article>
HTML <aside>
HTML <aside> define aside content related to primary content. The <aside> content must be related to the primary content. It can
function as side bar for the main content of web page.
Example:
1. <aside style="background-color:#e6e6fa">
2. <h2>Sidebar information</h2>
3. <p>This conatins information which will represent like a side bar for a webpage</p>
4. </aside>
HTML <footer>
HTML <footer> element defines the footer for that document or web page. It mostly contains information about author, copyright,
other links, etc.
Example:
1. <footer style="background-color: #f0f8ff; width: 100%; text-align: center;">
2. <h3>Footer Example</h3>
3. <p>© Copyright 2018-2020. </p>
4. </footer>
HTML <details>
HTML <details> element is used to add extra details about the web page and use can hide or show the details as per requirement.
Example:
1. <details style="background-color: #f5deb3">
2. <summary>This is visible section: click to show other details</summary>
3. <p>This section only shows if user want to see it. </p>
4. </details>
HTML <summary>
HTML <summary> element is used with the <details> element in a web page. It is used as summary, captions about the content of
<details> element.
Example:
1. <details>
2. <summary>HTML is acronym for?</summary>
3. <p style="color: blue; font-size: 20px;">Hypertext Markup Language</p>
4. </details>
HTML Symbols
There are many mathematical, technical and currency symbols which are not present on a normal keyboard. We have to use HTML
entity names to add such symbols to an HTML page.
If there no entity name exists, you can use an entity number, a decimal, or hexadecimal reference.
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h3>The Currency Symbols</h3>
5. <p>This is Indian Rupee symbol <b>₹<b></p>
6. <p>This is Euro symbol <b>€</b></p>
7. <p> This is Dollar symbol <b>#36;</b></p>
8. </body>
9. </html>
HTML Responsive
Responsive Web design
Responsive web design is used to make your web page look appropriate, good, and well placedon all devices (desktop, tablet,
smartphone etc.)
Responsive web design uses HTML and CSS to resize, hide, shrink, enlarge, or move the content. It makes the content look good on
any screen.
Set the viewport
Let's see how to set the viewport.
how to set the viewport
Responsive Images
Images which can be scaled nicely to fit any browser size are known as responsive images.
How to make Image Responsive?
By using the width property
Set the CSS width property to 100% to make the image responsive and scale up and down.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Responsive Image</h2>
6. <p>When we set the CSS width property to 100%, it makes the image responsive.
7. Resize the browser window to see the effect.</p>
8. <img src="img_girl.jpg" style="width:100%;">( change image)
9. </body>
10. </html>