Unit - I.docx
Unit - I.docx
Unit I
HTML
Introduction
● HTML stands for Hyper Text (i.e Text within Text) Markup Language. HTML is the
standard markup language for creating Web pages. HTML describes the structure of a
Web page.
● A markup language is a set of rules that defines how the layout and presentation of text
and images should appear in a digital document.
● The first version of HTML was written by Tim Berners-Lee in 1993.
Getting Started
Understanding HTML Tags
HTML tags are composed of an opening tag, content, and a closing tag. The opening tag
marks the beginning of an element, and the closing tag marks the end. The content is the
information or structure that falls between the opening and closing tags. Here's the basic
structure of an HTML tag:
Basic HTML Code - Example Program
<!DOCTYPE>: It defines the document type or it instruct the browser about the version of
HTML.
<html > :This tag informs the browser that it is an HTML document. Text between html tag
describes the web document. It is a container for all other elements of HTML except
<!DOCTYPE>
<head>: It should be the first element inside the <html> element, which contains the
metadata(information about the document). It must be closed before the body tag opens.
<title>: As its name suggested, it is used to add title of that HTML page which appears at the top
of the browser window. It must be placed inside the head tag and should close immediately.
(Optional)
<body> : Text between body tag describes the body content of the page that is visible to the end
user. This tag contains the main content of the HTML document.
<h1>: Text between <h1> tag describes the first level heading of the webpage.
<p>: Text between <p> tag describes the paragraph of the webpage.
HTML Uses:
1) Build Websites, 2) Customize Content (Allows you to edit web pages, emails, or templates
to fit your needs), 3) Understand How the Web Works (How web pages are structured), 4)
Employment Opportunities and 5) Learn Easily
Features of HTML
● It is easy to learn and easy to use.
● It is platform-independent.
● Images, videos, and audio can be added to a web page.
● Hypertext can be added to the text.
HTML layouts are the backbone of web pages, structuring content for user-friendly
navigation. They ensure organized presentation and enhance user experience. This guide
explores elements and techniques vital for crafting effective HTML layouts.
HTML Layout refers to the structure of a web page, achieved through elements
like <header>, <nav>, <main>, <article>, <section>, <aside> and <footer>. These elements help
organize content and define the page’s sections
Syntax:
<div class = "header"> Content... </div>
<div class = "section"> Content... </div>
<div class = "footer"> Content... </div>
Layout Components
Layouts Descriptions
The part of the front end which is used at the top of the page.
Header
<header> tag is used to add a header section on web pages.
The navigation bar is the same as the menu list. It is used to display the
Navigation bar content information using hyperlinks. <nav> tag is used to add the nav
section (nav elements) in web pages.
Content The content section is the central part where content is displayed.
Section <main> tag is used to add the main content of the webpages.
The footer section contains the contact information and other query
Footer related to web pages. The footer section is always put on the bottom of
the web pages. The <footer> tag sets the footer on web pages.
Example: In this example we define a page layout with a header, navigation menu, body
section, and footer. It includes CSS styling for elements like headings, menu, and footer,
enhancing visual appeal and user experience.
<html>
<head>
<title>Page Layout</title>
<style>
.head1 {
font-size: 40px;
color: #009900;
font-weight: bold;
}
.head2 {
font-size: 17px;
margin-left: 10px;
margin-bottom: 15px;
}
body {
margin: 0 auto;
background-position: center;
background-size: contain;
}
.menu {
position: sticky;
top: 0;
background-color: #009900;
padding: 10px 0px 10px 0px;
color: white;
margin: 0 auto;
overflow: hidden;
}
.menu a {
float: left;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
/* .menu-log class is used to position the login link
on the right side of the menu bar */
.menu-log {
right: auto;
float: right; /* Floats the login link to the right */
}
footer {
width: 100%;
bottom: 0px;
background-color: #000;
color: #fff;
position: absolute;
padding-top: 20px;
padding-bottom: 50px;
text-align: center;
font-size: 30px;
font-weight: bold;
}
.body_sec {
margin-left: 20px;
}
</style>
</head>
<body>
HTML Elements
The HTML element is everything from the start tag to the end tag:
<tagname>Content goes here...</tagname>
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Example
<em>This text is emphasized</em>
<small>This is some smaller text.</small>
<p>Do not forget to buy <mark>milk</mark> today.</p>
<p>My favorite color is <del>blue</del> red.</p>
<p>My favorite color is <del>blue</del> <ins>red</ins>.</p>
<p>This is <sub>subscripted</sub> text.</p>
<p>This is <sup>superscripted</sup> text.</p>
Hypertext Links
Hyperlink, or simply a link, is a digital reference to data that the user can follow or be
guided to by clicking or tapping. A hyperlink points to a whole document or to a specific
element within a document. Hypertext is text with hyperlinks. The text that is linked from is
known as anchor text.
The document containing a hyperlink is known as its source document. Hyperlinks are
often used to implement reference mechanisms such as tables of
contents, footnotes, bibliographies and indexes.
The HTML <a> tag defines a hyperlink. It has the following syntax:
● The most important attribute of the <a> element is the href attribute, which indicates the
link's destination.
● The link text is the part that will be visible to the reader.
● Clicking on the link text, will send the reader to the specified URL address.
Hyperlink Vs Hypertext
Hyperlink and hypertext are fundamental concepts in web technology. Hypertext refers
to text containing links to other text or media, enhancing navigation and information retrieval.
Hyperlinks are the actual links embedded in hypertext, directing users to different sections,
pages, or resources.
CSS:
Introduction:
HTML CSS
HTML is a markup language used to CSS is a style sheet language responsible
create static web pages and web for the presentation of documents written
applications. in a markup language.
HTML cannot be used in a CSS file. CSS can be used in an HTML file.
It is used to build the structure of the It is used to make web pages more
web pages. presentable.
In this example all <p> elements will be center-aligned, with a red text color:
p {
color: red;
text-align: center;
}
Example Explained
● p is a selector in CSS (it points to the HTML element you want to style: <p>).
CSS selectors are used to "find" (or select) the HTML elements you want to style.
The element selector selects HTML elements based on the element name.
Example
Here, all <p> elements on the page will be center-aligned, with a red text color:
p {
text-align: center;
color: red;
}
● The id of an element is unique within a page, so the id selector is used to select one
unique element!
● To select an element with a specific id, write a hash (#) character, followed by the id of
the element.
Example
The CSS rule below will be applied to the HTML element with id="para1":
#para1 {
text-align: center;
color: red;
}
● The class selector selects HTML elements with a specific class attribute.
● To select elements with a specific class, write a period (.) character, followed by the class
name.
Example
In this example all HTML elements with class="center" will be red and center-aligned:
.center {
text-align: center;
color: red;
}
Cascading in CSS
<html>
<head>
<style>
/* Internal Style */
.header {
color: blue;
}
</style>
</head>
<body>
<h1 class="header" style="color: red;">Hello, World!</h1>
</body>
</html>
Output:
The cascade takes an unordered list of declared values for a given property on a given
element, sorts them by their declaration's precedence, and outputs a single cascaded value. One
important benefit of cascading is that it offers development teams portability so they can move
existing applications without suffering the cost to rewrite them. Cascading applications run on
and can be ported between different platforms.
Style Attribute in CSS
The style attribute specifies an inline style for an element. The style attribute will
override any style set globally, e.g. styles specified in the <style> tag or in an external style
sheet.
The style attribute will override any style set globally, e.g. styles specified in the <style> tag or
in an external style sheet.
Applies to
The style attribute is part of the Global Attributes and can be used on any HTML element.
Example
Style Container
In web development and CSS (Cascading Style Sheets), "container" typically refers to an
HTML element or a CSS class used to group and structure content within a webpage. A "CSS
container" is not a specific term in CSS itself, but it generally refers to an HTML element or a
CSS class used to encapsulate and style content within a web page.
Containers are essential for creating organized and responsive web layouts. They help
control the placement and styling of elements within a webpage. Containers are a fundamental
concept in web design and development, as they allow you to structure and organize the layout
of your web page, apply consistent styling, and control how content is displayed.
● Block containers
● Inline containers
● Inline-block containers
Block containers take 100% width of their parent containers by default. We can set size of these
containers using width and height properties.
Ex: headings, paragraphs, div, nav, etc…
Inline containers won’t take space. They keep their size as small as possible (just wrapping
around the content inside). Web browsers treat these containers as text contents (words). We can
NOT set size of these containers.
● Structural Elements: Containers are HTML elements that serve as structural containers
for content. Common container elements include <div>, <section>, <header>, <footer>,
and <main>. These elements define sections or blocks of content within a webpage and
provide a structured way to group related elements.
● Styling and Layout Control: Containers often apply styling and layout properties to a
group of elements. You can define CSS classes or IDs for containers and apply styles to
them. This lets you control aspects such as width, height, margins, padding, background
colors, borders, and more.
● Responsive Design: Containers are crucial in creating responsive web designs that adapt
to different screen sizes and devices. By setting container widths as percentages or using
media queries, you can ensure that your content looks good on various devices, from
large desktop screens to small mobile devices.
● Nested Containers: You can nest containers within one another, creating a hierarchical
structure for your content. This allows you to organize content into multiple levels of
sections, each with its own styling and layout properties.
● Overflow Handling: Containers can control how content that exceeds their boundaries is
displayed. You can use properties like overflow to specify whether to add scrollbars, hide
the overflow, or expand the container to accommodate the content.
● Clearing Floats: When floating elements within containers, it's essential to clear floats
to prevent layout issues. You can use the clear property to ensure proper rendering.
CSS Properties:
Here are some commonly used CSS properties. A CSS property styles an aspect of an
HTML element. Here are a few examples:
<div style="border: 1px solid black;
font-size: 18px; "> Style This </div>
In this example, two CSS properties are applied to the div element: The border and the
font-size properties.
A CSS property declaration consists of a property name and a property value. The
property name comes first, then a colon, and then the value. Here is the general pattern a CSS
property declaration follows:
property-name: property-value
If you specify more than one CSS property, each name-value pair is separated by a
semicolon like this:
property1 : property-value1;
property2 : property-value2;
The last property declaration does not have to end with a semicolon, but it makes it easier
to add more CSS properties without forgetting to put in that extra semicolon.
There are many CSS properties you can specify for different HTML elements. These
CSS properties are covered in their own texts.
Background: Specifies the background color or image of an element.
● The color fills the space that is not covered by the image.
● url("/img/css/sunflowers.jpg") points to the background image.
● no-repeat specifies that the background image is not repeated.
● right places the background image to the right of the element.
Background color: Sets the background color.
.my-element {
background-color: #f1f1f1; }
Background-image: Sets the background image.
.my-element {
background-image: url('image.jpg'); }
Color: Sets the color of the text.
.my-element {
color: #333333; }
Typography: Controls the font properties.
Font-Family: Specifies the font family.
.my-element {
font-family: Arial, sans-serif;
}
Font Size: Sets the size of the font.
.my-element {
font-size: 16px;
}
Font-Weight: Sets the thickness of the font.
.my-element {
font-weight: bold;
}
Font-style: Applies italic or oblique style to the font.
.my-element {
font-style: italic;
}
Border: Sets the properties of an element's border.
Border-Width: Specifies the width of the border.
.my-element {
border-width: 2px;
}
Border-Color: Sets the color of the border.
.my-element {
border-color: #cccccc;
}
Border-Style: Determines the style of the border (e.g., solid, dashed, dotted).
.my-element {
border-style: dashed;
}
Padding: Specifies the space between an element's content and border. Padding-top,
padding-right, padding-bottom, padding-left: Sets the padding for each side of the element.
.my-element {
padding: 10px 20px 15px 5px;
}
Element Box:
In CSS, the term "box model" is used when talking about design and layout.
The CSS box model is essentially a box that wraps around every HTML element. It consists of:
content, padding, borders and margins. The image below illustrates the box model:
● Content - The content of the box, where text and images appear
The box model allows us to add a border around elements, and to define space between
elements.
1. Content Area
● The content area is the central part of the CSS box model, containing the main
content (e.g., text, images, videos, or elements like <p> or <span>).
The content edge refers to the four edges of the content area
2. Padding Area
● The padding area is the space between the content and the border of an element.
● It includes the areas highlighted in light green and skin color in the example.
● The distance between the content edge and the border is the padding.
● It works similarly with box-sizing: content-box and box-sizing: border-box, but with
slight calculation differences.
3. Border Area
● The area that marks the end of an element is called as the border it is the outer fencing
for the element.
● The default border properties are provided in CSS to control the thickness of this outer
fencing.
● The border area also add ‘s up to the complete height and width of the element.
● The more the border width the more will be the height or width of the element.
● In the above image the area marked with skin color is called the border area.
4. Margin Area
● The area outside the border of an element is called the margin area.
● The distance between the border of the parent element and the border of the child
element is called as the margin.
● CSS has provides certain margin properties to get control over this scenario.
Padding Property-Margin Property:
Understanding CSS padding and margin is fundamental for effective web design and
layout management. Both properties are essential for controlling the spacing and positioning of
elements on a webpage. In this article, we will explain the key differences between CSS padding
and margin, their respective uses, and how they can affect the layout and appearance of
elements.
What is Margin?
What is Padding?
Padding is the space between the element and the related content inside it. It determines
how elements look and sit within a container. Padding affects the container’s background around
the element and clears the area around the content. Increasing the padding size either grows the
element size or shrinks the content inside, with the element size increasing by default.
1. Margin
Margins are used when you need to adjust the spacing between elements. For example, to
center an element horizontally within a fixed-width container, you can use margin: auto. Margins
are also ideal for setting the distance between adjacent elements.
Note: Margins are used to add spaces between an image and the description of that image.
CSS Padding is used if we want to create a space between an element and the edge of the
container or the border. It is also useful in the requirement of changing the size of the element.
CSS code:
.center {
margin: auto;
background: lime;
width: 66%;
}
.outside {
margin: 3rem 0 0 -3rem;
background: cyan;
width: 66%;
}
Complete Code
<!DOCTYPE html>
<html>
<head>
<style>
.center {
margin: auto;
background: lime;
width: 66%;
}
.outside {
margin: 3rem 0 0 -3rem;
background: cyan;
width: 66%;
}
</style>
</head>
<body>
<h2 style="color:green">
WELCOME
</h2>
<p class="center">
This element is centered.
</p>
<p class="outside">
The element is positioned outside of its corner.
</p>
</body>
</html>
Output:
CSS Margins
The CSS margin properties are used to create space around elements, outside of any
defined borders.
With CSS, you have full control over the margins. There are properties for setting the
margin for each side of an element (top, right, bottom, and left).
CSS has properties for specifying the margin for each side of an element:
● margin-top
● margin-right
● margin-bottom
● margin-left
● inherit - specifies that the margin should be inherited from the parent element
Example
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
All CSS Margin Properties
2. Padding:
Padding is used to create space between the content of an element and its border. It is
useful when you want to control the internal spacing within an element and influence how the
element’s content sits within its container.
Note: When there is an increase in the padding value, the text will remain the same, but the
surrounding space will increase.
CSS code:
h4 {
background-color: lime;
padding: 20px 50px;
}
h3 {
background-color: cyan;
padding: 110px 50px 50px 110px;
}
Complete code:
<!DOCTYPE html>
<html>
<head>
<style>
h4 {
background-color: lime;
padding: 20px 50px;
}
h3 {
background-color: cyan;
padding: 110px 50px 50px 110px;
}
</style>
</head>
<body>
<h2 style="color:green">GeeksforGeeks</h2>
<h4>This element has moderate padding.</h4>
<h3>The padding is huge in this element!</h3>
</body>
</html>
Output:
Key Differences between Padding and Margin