HTML Basics and Coding Guide
HTML Basics and Coding Guide
Notepad
A simple text editor that can be used to learn HTML
TextEdit
A simple text editor for Mac that can be used to learn HTML
Sublime Text
An advanced editor that can be used to write HTML programs
Notepad++
An open-source editor that can be used to edit HTML code
Opening Closing
Content
Tag Tag
Esoft Metro College - Kuliyapitiya
HTML Colors
Color Names
In HTML, a color
can be specified
by using a color
name
➢ <head> - </head>
This controls the header section of a web page.
➢ <title> - </title>
You can type any text with in this tag which will display on the title bar.
➢ <body> - </body>
All the content of the web page must be placed with in this tag.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Designing</title>
</head>
<body>
This is my first web page
</body>
</html>
Output :
<html lang="en">
<head>
<title>Web Designing</title>
</head>
<body>
</body>
</html>
<html lang="en">
<head>
<title>Web Designing</title>
</head>
<body>
<p> First paragraph </p>
<p> Second paragraph </p>
</body>
</html>
<html lang="en">
<head>
<title>Web Designing</title>
</head>
<body>
<h1> First paragraph </h1>
<h2> Second paragraph </h2>
<h3> Third paragraph </h3>
<h4> Fourth paragraph </h4>
<h5> Fifth paragraph </h5>
<h6> Sixth paragraph </h6>
</body>
</html>
<html lang="en">
<head>
<title>Web Designing</title>
</head>
<body>
ESOFT Metro College<br>
Kuliyapitiya
</body>
</html>
<html lang="en">
<head>
<title>Web Designing</title>
</head>
<body>
<pre>
Esoft Metro College
hissa Mawatha
Kuliyapitiya
</pre>
</body>
</html>
<pre>
<b>Bold Text </b>
<i>Italic Text </i>
<u>Underline Text </u>
<strong> Strong Text </strong>
<small> Smaller Text </small>
<mark>Esoft</mark>
<del> Esoft </del>
4<sup>th</sup> of December
H<sub>2</sub>O
<pre> Esoft Metro College - Kuliyapitiya
Progress bar | <progress>….</progress>
HTML Source Code
<progress> value="22" max="100"></progress>
Output
<body>
<marquee>Esoft </marquee>
</body>
<ul> <ol>
<li> Ditec </li> <li> HND </li>
<li> DiE </li> <li> BIT </li>
<li> DiSE </li> <li> TOP-UP </li>
<li> DiNW </li> <li> MSc </li>
</ul> </ol>
For and example if you want to show paragraph description in right side
of the web page. You need to use these attribute.
Attributes Value
</body>
</html>
</body>
</html>
1. Background Color
<body bgcolor="Blue">
<th>
<tr>
<td>
Esoft Metro College - Kuliyapitiya
<!DOCTYPE html>
HTML Table Code Example <html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>Table</title>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width: 40%;">
<tr>
<th>Frist Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
Esoft Metro College - Kuliyapitiya
<tr>
<td>Pathum</td>
<td>Samaranayaka</td>
<td>24</td>
</tr>
<tr>
<td>Piyumi</td>
<td>Hansika</td>
<td>32</td>
Output
</tr>
<tr>
<td>Viraj</td>
<td>Dharshana</td>
<td>35</td>
</tr>
</table>
</body>
</html>
Syntax
table, th, td {
border: 1px solid black;
Output
border-collapse: collapse;
}
Syntax
th, td { Output
padding: 20px;
}
Syntax Output
th {
text-align: left;
}
Border spacing specifies the space between the cells. To set the border-spacing for
a table, we must use the CSS border-spacing property.
Syntax
Output
table {
border-spacing: 5px;
}
th,
td {
padding: 5px;
text-align: center;
Esoft Metro College - Kuliyapitiya
}
</style>
</head>
<body>
<h2>Cell that spans two columns:</h2> <tr>
<table style="width: 40%;"> <td>Viraj</td>
<tr> <td>0714587452</td>
<th>Frist Name</th> <td>077857496</td>
<th colspan="2">Telephone</th> </tr>
</table>
</tr> </body>
<tr> </html>
<td>Pathum</td>
<td>0776585741</td>
<td>0718574851</td>
</tr>
<tr>
<td>Piyumi</td>
<td>0776154874</td>
<td>0748574852</td>
</tr>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
Output
content="width=device-width, initial-
scale=1.0">
<title>Table</title>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>0778574585</td>
</tr>
Syntax
Table,
Th,
td {
Output
background-color: #f2f2d1;
}
❑ Each declaration includes a CSS property name and a value, separated by a colon.
❑ Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by curly braces.
Internal CSS
Internal CSS is a method for defining CSS styles directly within an HTML document. It’s particularly
useful for applying unique styles to a single web page, and it’s embedded within the <style> element
located in the <head> section of the HTML file.
<html lang="en">
<head> p {
<title>Internal CSS</title> color: blue;
<style> font-size: 50px;
/* Internal CSS */ line-height: 1.5;
h1 { text-align: center;
color: green; }
font-size: 100px; </style>
text-align: center; </head>
} <body>
<h1>Esoft Metro Campus</h1>
<p>Shaping Lives, Creating Futures</p>
</body>
</html>
•Localized Styling: Keeps styles within the HTML file, avoiding conflicts with other pages and
making it easier to manage styles at the local level.
•Higher Specificity: Internal CSS has higher specificity than external CSS, allowing easier
overriding of external styles within the same HTML file.
•Ease of Implementation: Simple to use and implement, making it easy to quickly apply styles to
a single page.
•Repetition: Styles must be repeated in multiple HTML files if the same styles are needed across different
pages.
•Increased File Size: Embedding CSS in HTML increases the file size of the HTML document.
•Limited Management: Managing styles across multiple pages can become difficult without a centralized
stylesheet.
Since each id must be unique within the page, the #id selector allows you to target and style
individual elements with precision. The # character is used to indicate that the selector is an
id selector.
#para2 {
color: blue;
font-size: 50px;
line-height: 1.5;
text-align: center;
Syntax:
.class {
// CSS property
}
.class {
color: green;
</style>
font-size: 100px;
</head>
text-align: center;
<body>
}
<h1 class ="class">Esoft Metro Campus</h1>
<h2 class ="class1">Shaping Lives, Creating
.class1 {
Futures</h2>
color: yellow;
</body>
font-size: 50px;
</html>
font-style: italic;
text-align: center;
}
[Link] {
color: green;
font-size: 100px; </head>
text-align: center; <body>
} <h1 class ="class">Esoft Metro Campus</h1>
<p class ="class1">Shaping Lives, Creating
p.class1 { Futures</p>
color:red; </body>
font-size: 50px; </html>
font-style: italic;
text-align: center;
}
</style>
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
h1, h2, p {
color: red; text-align: center;
}
color: red;
p{ }
text-align: center;
color: red;
}
Esoft Metro College - Kuliyapitiya
Example :
<html lang="en">
<head>
<title>Class Selector</title>
<style>
h1,h2,p{
text-align: center;
color: brown;
}
</style>
</head>
<body>
<h1>Esoft Metro Campus</h1>
<h2>Shaping Lives, Creating
Futures</h2>
<p>This is a paragraph.</p>
</body>
</html>
Syntax:
<tag style = " "></tag>
<html lang="en">
<head>
<title>Inline css</title>
</head>
<body>
<h1 style="color: brown; font-size: 60px; text-align: center;">
Esoft Metro Campus
</h1>
• With an external style sheet, you can change the look of an entire website by
changing just one file.
• Each HTML page must include a reference to the external style sheet file inside
the <link> element, inside the head section.
Syntax:
<link rel="stylesheet" href="path/to/your/[Link]">
html lang="en">
<head>
<title>CSS Colors</title>
</head>
<body>
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-color:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-color:MediumSeaGreen;">MediumSeaGreen</h1>
<h1 style="background-color:Gray;">Gray</h1>
<h1 style="background-color:SlateBlue;">SlateBlue</h1>
<h1 style="background-color:Violet;">Violet</h1>
<h1 style="background-color:LightGray;">LightGray</h1>
</body>
</html>
Example
<html lang="en">
<head>
<title>CSS Colors</title>
</head>
<body>
<h1 style="border: 2px solid Tomato;">ESOFT</h1>
01 - CSS background-color
The background-color property specifies the background color of an element.
<html lang="en">
<head>
<style>
body{
background-color: lightblue;
}
</style>
</head>
<body>
<h1>Esoft Metro Campus</h1>
<p>This page has a light blue background color!</p>
</body>
</html>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
Other Elements
You can set the background color for any HTML elements:
<html lang="en">
<head>
<style>
h1 {
background-color: green;
}
div {
background-color: lightblue; <body>
} <h1>CSS background-color example!</h1>
<div>
p { This is a text inside a div element.
background-color: yellow; <p>This paragraph has its own background color.</p>
} We are still in the div element.
</style> </div>
</body>
</head> </html>
</body>
</html>
[Link] {
border-style: solid;
border-width: medium;
}
[Link] {
border-style: dotted;
border-width: 2px;
}
[Link] {
border-style: double;
border-width: 15px;
}
[Link] {
border-style: double;
border-width: thick;
}
</style>
</head>
<body>
<p class="one">Some text.</p> </body>
<p class="two">Some text.</p> </html>
<p class="three">Some text.</p>
<p class="four">Some text.</p>
<p class="five">Some text.</p>
<p class="six">Some text.</p>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
CSS Border Color
The border-color property is used to set the color of the four borders.
[Link] {
<html lang="en"> border-style: dotted;
<head> border-color: blue;
<title>The Boarder color</title> }
<style> </style>
[Link] { </head>
border-style: solid; <body>
border-color: red; <h2>The border-color Property</h2>
} <p>This property specifies the color of the
four borders:</p>
[Link] {
border-style: solid; <p class="one">A solid red border</p>
border-color: green; <p class="two">A solid green border</p>
} <p class="three">A dotted blue border</p>
</body>
</html>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
Specific Side Colors
<html lang="en">
<head>
<title>The Boarder color</title>
<style>
[Link] {
border-style: solid;
border-color: red green blue yellow; /* red top, green right, blue bottom and
yellow left */
}
</style>
</head>
<body>
<h2>The border-color Property</h2>
<p class="one">Esoft Metro Campus</p>
</body>
</html>
Example :
<html lang="en">
<head>
<title>The Boarder color</title>
<style>
p {
border: 5px solid red;
}
</style>
</head>
<body>
<p>Esoft Metro Campus</p>
</body>
</html>
<html lang="en">
<head>
<title>The Roundest border</title>
<style>
[Link] {
border: 2px solid red;
padding: 5px;
}
p.round1 {
border: 2px solid red;
border-radius: 5px;
padding: 5px;
}
p.round2 {
border: 2px solid red;
border-radius: 8px;
padding: 5px;
} Esoft Metro College - Kuliyapitiya
p.round3 {
border: 2px solid red;
border-radius: 12px;
padding: 5px;
}
</style>
</head>
<body>
<p class="normal">Normal border</p>
<p class="round1">Round border</p>
<p class="round2">Rounder border</p>
<p class="round3">Roundest border</p>
</body>
</html>
• margin-top
• margin-right
• margin-bottom
• margin-left
<html lang="en">
<head>
<title>The Roundest border</title>
<style>
div {
border: 1px solid black;
margin-top: 50px;
margin-bottom: 100px;
margin-right: 800px;
margin-left: 80px;
background-color: lightblue;
}
</style>
</head>
<body>
<h2>Using individual margin properties</h2>
<div>Esofr Metro Campus</div>
</body>
</html>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
CSS Padding
The CSS padding properties are used to generate space around an element's
content, inside of any defined borders.
CSS has properties for specifying the padding for each side of an element:
• padding-top
• padding-right
• padding-bottom
• padding-left
h1 {
color: green;
}
</style>
</head>
<body>
<h1>Esoft Metro Campus</h1>
<p>Shaping Lives, Creating Futures</p>
</body>
</html>
Esoft Metro College - Kuliyapitiya
Text Color and Background Color
<html lang="en">
<head>
<title>Text Color and Background Color</title>
<style>
body {
background-color: lightgrey;
color: blue;
}
<body>
h1 { <h1>This is a Heading</h1>
background-color: black; <p>This page has a grey background
color: white; color and a blue text.</p>
} <div>This is a div.</div>
</body>
div { </html>
background-color: blue;
color: white;
}
</style>
</head>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
Text Alignment
<html lang="en">
<head>
<title>Text Alignment</title>
<style>
h1 {
text-align: center; <body>
} <h1>Heading 1 (center)</h1>
<h2>Heading 2 (left)</h2>
h2 { <h3>Heading 3 (right)</h3>
text-align: left;
} <p>The three headings above are aligned
center, left and right.</p>
h3 { </body>
text-align: right; </html>
}
</style>
</head>
• text-decoration-line
• text-decoration-color
• text-decoration-style
• text-decoration-thickness
• text-decoration
h1 {
text-decoration: overline;
}
<body>
<h1>Overline text decoration</h1>
h2 {
<h2>Line-through text decoration</h2>
text-decoration: line-through;
<h3>Underline text decoration</h3>
}
<p class="ex">Overline and underline text
decoration.</p>
h3 {
text-decoration: underline;
<p><strong>Note:</strong> It is not
}
recommended to underline text that is not a
link, as this often confuses
[Link] {
the reader.</p>
text-decoration: overline underline;
</body>
}
</html>
</style>
</head>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
CSS Text Transformation
The text-transform property is used to specify uppercase and lowercase letters in a text.
<html lang="en">
<head>
<title>text-transform property</title>
<style>
[Link] {
text-transform: uppercase;
} <body>
<h1>Using the text-transform property</h1>
[Link] { <p class="uppercase">This text is transformed
text-transform: lowercase; to uppercase.</p>
} <p class="lowercase">This text is transformed
to lowercase.</p>
[Link] { <p class="capitalize">This text is
text-transform: capitalize; capitalized.</p>
}
</style> </body>
</head> </html>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
CSS Text Spacing
Text Indentation
<html lang="en">
<head>
<title>text-indent</title>
<style>
p {
text-indent: 50px;
}
</style>
</head>
<body>
<h1>Using text-indent</h1>
<p>In my younger and more vulnerable years my father gave me some advice that
I've been turning over in my mind ever since. 'Whenever you feel like criticizing
anyone,' he told me, 'just remember that all the people in this world haven't had
the advantages that you've had.'</p>
</body>
</html>
Esoft Metro College - Kuliyapitiya
Esoft Metro College - Kuliyapitiya
Letter Spacing
<html lang="en">
<head>
<title>letter-spacing</title>
<style>
h2 {
letter-spacing: 5px;
}
h3 {
letter-spacing: -2px;
}
</style>
</head>
<body>
<h1>Using letter-spacing</h1>
<html lang="en">
<head>
<title>Text Shadow</title>
<style>
h1 {
text-shadow: 2px 2px;
}
h3 {
letter-spacing: -2px;
}
</style>
</head>
<body>
<h1>Esoft Metro Campus</h1>
</body>
</html>
Esoft Metro College - Kuliyapitiya
2
<html lang="en">
<head>
<title>Text Shadow</title>
<style>
h1 {
text-shadow: 2px 2px red;
}
h3 {
letter-spacing: -2px;
}
</style>
</head>
<body>
<h1>Esoft Metro Campus</h1>
</body>
</html>
<html lang="en">
<head>
<title>Text Shadow</title>
<style>
h1 {
text-shadow: 2px 2px 5px red;
}
h3 {
letter-spacing: -2px;
}
</style>
</head>
<body>
<h1>Esoft Metro Campus</h1>
</body>
</html>
1. Serif fonts have a small stroke at the edges of each letter. They create a sense of formality and
elegance.
2. Sans-serif fonts have clean lines (no small strokes attached). They create a modern and
minimalistic look.
3. Monospace fonts - here all the letters have the same fixed width. They create a mechanical
look.
.p2 {
font-family: Arial, Helvetica, sans-serif;
}
.p3 {
font-family: "Lucida Console", "Courier New",
monospace;
}
h3 {
letter-spacing: -2px;
}
</style>
</head>
</body>
</html>
With CSS you can transform boring HTML menus into good-looking navigation bars.
<html lang="en">
<head>
<title>Vertical Navigation Bar</title> /* Change the link color on hover */
<style> li a:hover {
ul { background-color: #555;
list-style-type: none; color: white;
margin: 0; }
padding: 0; </style>
width: 200px; </head>
background-color: #f1f1f1; <body>
} <ul>
<li><a href="#home">Home</a></li>
li a { <li><a href="#news">News</a></li>
display: block; <li><a href="#contact">Contact</a></li>
color: #000; <li><a href="#about">About</a></li>
padding: 8px 16px; </ul>
text-decoration: none;
} </body>
</html>
.active {
background-color: #04AA6D;
color: white;
}
<html lang="en">
<head>
<title>Active/Current Navigation
Link</title>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
} Esoft Metro College - Kuliyapitiya
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
</style>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body>
Esoft Metro College - Kuliyapitiya
</html>
Esoft Metro College - Kuliyapitiya
Active/Current Navigation Link
<html lang="en">
<head>
<title>Active/Current Navigation
Link</title>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li {
float: left;
border-right:1px solid #bbb;
}
li:last-child {
border-right: none;
}
Esoft Metro College - Kuliyapitiya
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111; <ul>
} <li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
.active { <li><a href="#contact">Contact</a></li>
background-color: #04AA6D; <li style="float:right"><a
} href="#about">About</a></li>
</style> </ul>
</head>
<body> </body>
</html>
<html lang="en">
<head>
<title>Fixed Top Navigation Bar</title>
<style>
body {margin:0;}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #04AA6D;
}
</style>
</head>
Esoft Metro College - Kuliyapitiya
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
<div style="padding:20px;margin-top:30px;background-color:#1abc9c;height:1500px;">
<h1>Fixed Top Navigation Bar</h1>
<h2>Scroll this page to see the effect</h2>
<h2>The navigation bar will stay at the top of the page while scrolling</h2>
<html lang="en">
<head>
<title>Fixed Top Navigation Bar</title>
<style>
.dropbtn{
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
Esoft Metro College - Kuliyapitiya
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</body>
</html>
[Link]:hover {
border: 1px solid #777;
}
[Link] img {
width: 100%;
height: auto;
}
Esoft Metro College - Kuliyapitiya
[Link] {
padding: 15px;
text-align: center;
}
</style>
</head>
<body>
<div class="gallery">
<a target="_blank" href="[Link]">
<img src="[Link]" alt="Cinque Terre" width="600"
height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="amanda-frank-MvsjXlQtkCY-unsplash (1).jpg">
<img src="amanda-frank-MvsjXlQtkCY-unsplash (1).jpg" alt="Forest" width="600"
height="400">
</a>
<div class="gallery">
<a target="_blank" href="[Link]">
<img src="[Link]" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
<div class="gallery">
<a target="_blank" href="[Link]">
<img src="[Link]" alt="Mountains" width="600"
height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</body>
</html>
<html lang="en">
<head>
<title>CSS Form</title>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
Esoft Metro College - Kuliyapitiya
<body>
<h3>Using CSS to style an HTML Form</h3>
<div>
<form action="/action_page.php">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<label for="country">Country</label>
<select id="country" name="country">
<option value="australia">Sri Lanka</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
<form>
<input type="text" name="search"
placeholder="Search..">
</form>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Select Menus</title>
<style>
select {
width: 100%;
padding: 16px 20px;
border: none;
border-radius: 4px;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<form>
<select id="country" name="country">
<option value="au">Sri Lanka</option>
<option value="ca">Canada</option>
<option value="usa">USA</option>
</select>
</form>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Select Menus</title>
<style>
input[type=button], input[type=submit], input[type=reset] {
background-color: #04AA6D;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}