HTML and CSS
HTML and CSS
</body>
</html>
Explanation of an Example
● The <!DOCTYPE html> This statement specifies that the content of the document is
5HTML.
● The <html> is the main component of an HTML page is an element.
● The <head> element carries meta-data regarding the HTML page.
● The <title> element defines an HTML page header (which appears within the browser's
title bar or in the header of the page's window).
● The <body> element specifies the body of a file and serves as a receptacle for each of the
viewable items consisting of headings, paragraphs, graphics, hyperlinks, tables, lists, and
others.
● The <h1> element specifies a huge heading
● The <p> element explains an article
Please keep in mind that some HTML components do not include content (such as the <br>
element). They are known as empty elements. There is no ending tag for empty elements!
HTML Elements That Are Nested
HTML elements are capable of being nested, which means they may include other elements
within them.
>DGDO<
1
Every HTML document is made up of nested HTML elements.
Four HTML elements are used in this particular sample (<html>, <body>, <h1> and <p>):
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
</body>
The <body> element describes the body of the document.
It has a beginning tag <body> as well as an end tag </body>.
Then, within the <body> element, there are additionally two more
components: <h1> and <p>:
<h1>My first-ever heading</h1>
<p>This is my very first paragraph.</p>
The <h1> element describes a heading.
It has a beginning tag <h1> as well as an end tag </h1>:
<h1>My first-ever heading</h1>
The <p> element describes a paragraph.
It has a beginning tag <p> as well as an end tag </p>:
<p>This is my very first paragraph.</p>
Web browsers
A web browser (Chrome, Edge, Firefox, or Safari) reads HTML documents and displays them
appropriately.
The HTML tags aren't displayed by the browser; however, they are used to figure out how to
show the document.
>DGDO<
2
Structure of an HTML Page
An example of an HTML page structure is shown below:
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is my heading</h1>
<p>This is my paragraph.</p>
<p>This is my other paragraph.</p>
</body>
</html>
Please keep in mind that the information included within the <body> is going to show the
section. The information contained within the <title> element will appear in the browser's title
bar or the page's tab.
HTML Evolution
It is believed that there have been multiple releases of HTML since the very beginning of the
World Wide Web:
Year Version
>DGDO<
3
Windows 7 and older:
Navigate to Start > Programs > Accessories > Notepad.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
You are going to utilize the .htm or .html filename extensions. It seems that there isn't any
distinction; it is entirely up to you.
Step 4: Open the HTML Page in your web browser.
Load the saved HTML file in the browser of your choice (double-click or right-click and select
"Open with").
The final outcome will appear somewhat like the following:
>DGDO<
4
Documents in HTML
Each HTML file must begin with a statement of the document format: <!DOCTYPE html>.
The HTML document starts with <html> and concludes with </html>.
The viewable component of the HTML content is located between <body> and as </body>.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The <!DOCTYPE> Declaration
The <!DOCTYPE> declaration defines the document format and assists browsers in
accurately displaying web pages.
It is limited to appearing directly on the page, at the top of the page (before any HTML tags).
The <!DOCTYPE> The statement is not concerned about the case.
The <!DOCTYPE> declaration for 5HTML is: <!DOCTYPE html>
Headings in HTML
HTML heads are specified using the <h1> to <h6> tags.
<h1> particularly significant heading is defined. <h6>describes the least significant heading:
Example
<h1>This is my heading 1</h1>
<h2>This is my heading 2</h2>
<h3>This is my heading 3</h3>
Paragraphs in HTML
The HTML paragraph is specified by the <p> tag:
Example
<p>This is my paragraph.</p>
<p>This is my other paragraph.</p>
Links in HTML
HTML links are created using the <a> tag:
Example
<a href="https://www.google.com">This is what I link</a>
The href attribute specifies the link's destination.
Attributes are employed to add extra details to HTML elements.
>DGDO<
5
View HTML Source Code:
Right-click an HTML document and choose "View Page Source" (in Chrome), "View Source"
(in Edge), or anything similar across all browsers. Clicking opens a window with the page's
HTML source code.
Example
I am Red
I am Blue
I am Big
The HTML Attribute Style
The style attribute may be used to change the appearance of an HTML element.
The syntax that is used for the HTML style attribute is as follows:
<tagname style="property:value;">
The property is a CSS property. The value is a CSS value.
Background Color
The CSS background-color property specifies the color of an HTML element's background.
Example
Set a page's background color to powder blue:
<body style="background-color:powderblue;">
<h1>This is my heading</h1>
<p>This is my paragraph./p>
</body>
Example
Set the background color into two different elements:
<body>
</body>
Text Color
The CSS color property describes the text color for an HTML element:
Example
<h1 style="color:pink;">This is my heading</h1>
<p style="color:orange;">This is my paragraph.</p>
Fonts
The CSS font-family property describes the font to be utilized for an HTML element:
Example
<h1 style="font-family:arial;">This is my heading</h1>
<p style="font-family:calibri;">This is my paragraph.</p>
Text Size
The CSS font-size property describes the text size for an HTML element:
>DGDO<
6
Example
<h1 style="font-size:350%;">This is my heading</h1>
<p style="font-size:150%;">This is my paragraph.</p>
Text Alignment
The CSS text-align property describes the horizontal text alignment of an HTML element.
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:justify;">Justified paragraph.</p>
Example
This text is bold
This text is in italics.
This is subscript and superscript
Example
<p>My favorite color is <del>red</del> <ins>blue</ins>.</p>
Color Codes
A color can be determined in HTML through the use of a color label:
Red
Orange
DodgerBlue
MediumSeaGreen
Gray
SlateBlue
>DGDO<
8
Violet
LightGray
Color of the Background
Users can change the background color of HTML components as follows:
Hello Philippines
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod
tincidunt ut laoreet dolore magna aliquam erat volutpat.
Example
<h1 style="background-color:SlateBlue;">Hello Philippines</h1>
<p style="background-color:Orange;">Lorem.....</p>
Values of Color
Colors are able to be given in HTML using RGB values, HEX values, HSL values, RGBA values,
and HSLA values.
Each of the three preceding <div> background colors of components is specified using RGB,
HEX, and HSL values:
>DGDO<
9
CSS = Styles and Colors
Manipulate Text
Colors and Boxes
CSS Implementation
There are three techniques to include CSS in HTML documents:
● Inline: Applying the style property within HTML elements
● Internal: by employing a <style> component of the <head> section
● External: by utilizing a <link> to navigate to an outside CSS element
The most usual way of adding CSS is to preserve the styles in separate CSS files.
Inline CSS
Inline CSS is employed to give a distinct style to a particular HTML element.
Inline CSS takes advantage of an HTML element's style attribute.
The preceding instance alters the color of the content in the <h1> blue element, and the text
color of the <p> element to red:
Example
<h1 style="color:blue;">A Blue Title</h1>
CSS Internal
A single HTML page's style is defined using internal CSS.
This defines the internal CSS <head> construction of an HTML page within
a <style> element.
The preceding instance alters the color of ALL the text <h1> elements (on a particular page)
to blue, as well as the text color of EVERYTHING <p> components to red. Furthermore, the
page is going to be shown with a "powder-blue" background
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powder-blue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is my heading</h1>
<p>This is my paragraph.</p>
</body>
</html>
>DGDO<
10
CSS External
Several HTML pages employ an external style sheet to set up their style.
If you want to employ an external style sheet, include an address to it in the <head> every
HTML page's section:
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is my heading</h1>
<p>This is my paragraph.</p>
</body>
</html>
Every text editor is used to create the external style sheet. The file needs to be stored having a
.css extension and not include any HTML code.
The "styles.css" file appears to be this:
"styles.css":
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
Use an external style sheet to modify the appearance of a full website by modifying only a
single file!
>DGDO<
11
<h1>This is my heading</h1>
<p>This is my paragraph.</p>
</body>
</html>
Border CSS
CSS border specifies a boundary surrounding an HTML element.
Someone may set a border to almost any HTML element.
Example
CSS border property usage:
p{
border: 2px solid powderblue;
}
Padding in CSS
The CSS padding property specifies the amount of space (padding) across the text as well as
the border.
Example
CSS border, as well as padding attributes, are used:
p{
border: 2px solid powderblue;
padding: 30px;
}
CSS Margin
The CSS margin property specifies a margin (space) on the outside of the border.
Example
CSS border as well as margin properties:
p{
border: 2px solid powderblue;
margin: 50px;
}
Example
<img src="pic1.jpg" alt="Picture 2">
Example
<img src="pic2.jpg" alt="Picture 3">
Example
<img src="pic3.jpg" alt="Picture 1">
>DGDO<
12
invalid link indicator. If the browser cannot find the image, the incorrect link icon and alt text
are displayed.
Example
<img src="pic1.jpg" alt="Picture 2">
Example
<img src="pic1.jpg" alt="Picture 2">
Whenever a browser fails to identify a picture, it will show the alt attribute value:
Example
<img src="pic3.gif" alt="Picture 2">
A screen reader is a piece of software that interprets HTML code and lets the person using
it "listen" to the data. Individuals who have vision problems or are mentally handicapped
can benefit from device readers.
Example
<img src="pic1.jpg" alt="Picture 1" style="width:600px;height:700px;">
Everyone can also utilize the width and height attributes:
Example
<img src="pic1.jpg" alt="Picture 2" width="600" height="700">
The width and height attributes consistently indicate the dimension of the picture in pixels.
Definitely give the image's dimensions. The web page may flash while the image appears if
width and height aren't provided.
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 100%;
}
</style>
</head>
<body>
<img src="5html.gif" alt="5HTML Icon" width="130" height="130">
<img src="5html.gif" alt="5HTML Icon" style="width:130px;height:130px;">
</body>
</html>
>DGDO<
13
Example
<img src="/images/5html.gif" alt="5HTML Icon" style="width:130px;height:130px;">
Example
<img src="https://www.google.com/images/google_pink.jpg" alt="Google.com">
Remarks on external photos: External pictures may be protected by copyright. Some of you
might be in breach of copyright laws when you don't ask for permission to employ it.
Furthermore, you have no control over external photos; these can be deleted or modified at
any time.
Animated Pictures
HTML supports animated GIFs.
Example
<img src="flies.gif" alt="Flies Man" style="width:50px;height:50px;">
Image as a Links
Insert the image as a hyperlink in the <img> tag within the <a> tag:
Example
<a href="default.asp">
<img src="heart.gif" alt="Python Tutorial" style="width:50px;height:50px;">
</a>
>DGDO<
14