HTML 1
HTML 1
1. HTML Introduction
What is HTML?
Example
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
</body>
</html>
Example Explained
❖ The <!DOCTYPE html> declaration defines that this document is an HTML5
document
❖ The <html> element is the root element of an HTML page
❖ The <head> element contains meta information about the HTML page
❖ The <title> element specifies a title for the HTML page (which is shown in the
browser's title bar or in the page's tab)
❖ The <body> element defines the document's body, and is a container for all the visible
contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
❖ The <h1> element defines a large heading
❖ The <p> element defines a paragraph
1|Page
What is an HTML Element?
❖ An HTML element is defined by a start tag, some content, and an end tag:
❖ <tagname> Content goes here... </tagname>
❖ The HTML element is everything from the start tag to the end tag:
❖ <h1>My First Heading </h1>
❖ <p>My first paragraph. </p>
2. HTML Editors
Learn 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 that using a simple text editor is a good way to learn HTML.
Follow the steps below to create your first web page with Notepad or TextEdit.
Windows 8 or later:
Open the Start Screen (the window symbol at the bottom left on your screen). Type
Notepad.
Windows 7 or earlier:
Also change some preferences to get the application to save files correctly. In Preferences >
Format > choose "Plain Text"
Then under "Open and Save", check the box that says "Display HTML files as HTML code
instead of formatted text".
2|Page
Then open a new document to place the code.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Save the file on your computer. Select File > Save as in the Notepad menu.
Name the file "index.htm" and set the encoding to UTF-8 (which is the preferred encoding
for HTML files).
3|Page
Step 4: View the HTML Page in Your Browser
Open the saved HTML file in your favorite browser (double click on the file, or right-click -
and choose "Open with").
3. HTML Elements
HTML Headings
<h1> defines the most important heading. <h6> defines the least important heading:
Example
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
HTML Paragraphs
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
4|Page
HTML Links
Example
<a href="https://www.google.com">This is a link</a>
HTML Images
The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
<img src="google.jpg" alt="google image" width="104" height="142">
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
Example
Company Contact Country
5|Page
Table Cells
Everything between <td> and </td> are the content of the table cell.
Example
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
</table>
Table Rows
Each table row starts with a <tr> and ends with a </tr> tag.
Example
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
Table Headers
Sometimes you want your cells to be table header cells. In those cases, use the <th> tag
instead of the <td> tag:
6|Page
Example
<table>
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
7|Page
4. HTML RGB and RGBA Colors
This means that there are 256 x 256 x 256 = 16777216 possible colors!
8|Page
5. HTML Styles – CSS
What is CSS?
With CSS, you can control the color, font, the size of text, the spacing between elements,
how elements are positioned and laid out, what background images or background colors are
to be used, different displays for different devices and screen sizes, and much more!
Using CSS
Inline CSS
The following example sets the text color of the <h1> element to blue, and the text color of
the <p> element to red:
Example
<h1 style="color:blue;">A Blue Heading</h1>
Internal CSS
An internal CSS is defined in the <head> section of an HTML page, within a <style>
element.
The following example sets the text color of ALL the <h1> elements (on that page) to blue,
and the text color of ALL the <p> elements to red. In addition, the page will be displayed
with a "powderblue" background color:
9|Page
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.
To use an external style sheet, add a link to it in the <head> section of each HTML page:
<h1>This is a heading</h1>
<p>This is a paragraph. </p>
</body>
</html>
Now open notepad and paste the below code and then save it at styles.css. Note that you
should save the file in the same folder as your index file.
Code to be pasted in notepad:
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
10 | P a g e