HTML Introduction
What is HTML?
HTML stands for Hyper text Markup language.
HTML is he standard markup language for creating web pages.
HTML describe the structure of a web page.
HTML consists of a series of elements .
HTML elements tell the browser how to display the content.
HTML elements label pieces of content such as “this is a heading”,”this is a paragraph”,”this is a ink” ,etc.
A simple HTML Document
The <!DOCTYPE html> Declaration define that this document is an HTM5 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 fro the HTML page (which is shown in the brewser’s title bar or in the page’s tab).
The <body>element define the document’s body,and is contain for all the visibe contents such as heading,paragraph,images,hyperlinks,tables,lists etc.
The <h1> elements defines a large heading.
The<p>elements defines a paragraph.
E.g:-
</html>
What is an HTML Element?
An HTML elements is defined by a Tag ,Some Content and an End tag:
<tagname>Content here...</tagname>
The html Element is everything from the start tag to the end tag.
<h1> Heading</h1>
<p> paragraph</p>
Start tag |
Element content |
End tag |
<h1> |
Heading |
</h1> |
<title> |
Title name(Bar ) |
</title> |
<body> |
Content |
</body> |
<p> |
Paragraph |
</p> |
<br> |
None |
- |
Learn HTML using Notepad or Text editor
Notepad++
Text edit(Atom)
HTML Documents
The HTML document itself begins with <html>
and ends with </html>
.
The visible part of the HTML document is between <body>
and </body>
.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Output:-
My First Heading
My first paragraph.
HTML Headings
HTML headings are defined with the <h1>
to <h6>
tags.
<h1>
defines the most important heading. <h6>
defines the least important heading:
Example
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
HTML Paragraphs
HTML paragraphs are defined with the <p>
tag:
Example
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
This is a paragraph.
This is another paragraph.
HTML Images
HTML images are defined with the <img>
tag.
The source file (src
), alternative text (alt
), width
, and height
are provided as attributes:
Example
<!DOCTYPE html>
<html>
<body>
<h2>HTML Images</h2>
<p>HTML images are defined with the img tag:</p>
<img src="1.jpg" alt="kangaru" width="104" height="142">
</body>
</html>
Output:-
HTML Images
HTML images are defined with the img tag:
HTML Styles
style
attribute is used to add styles to an element, such as color, font, size...Example
I am normal
I am red
I am blue
I am big
Background Color
The CSS background-color
property defines the background color for an HTML element.
Example
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Text Color
The CSS color
property defines the text color for an HTML element:
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>
Fonts
The CSS font-family
property defines the font to be used for an HTML element:
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
</body>
</html>
Text Size
The CSS font-size
property defines the text size for an HTML element:
Example
Text Alignment
The CSS text-align
property defines the horizontal text alignment for an HTML element:
Example
HTML Text Formatting
Example
HTML Formatting Elements
Formatting elements were designed to display special types of text:
<b>
- Bold text<strong>
- Important text<i>
- Italic text<em>
- Emphasized text<mark>
- Marked text<small>
- Smaller text<del>
- Deleted text<ins>
- Inserted text<sub>
- Subscript text<sup>
- Superscript text
Example
HTML Colors
Color Names
Example
<!DOCTYPE html>
<html>
<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>
Background Color
You can set the background color for HTML elements:
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p>
</body>
</html>
Text Color
You can set the color of text:
Example
<!DOCTYPE html>
<html>
<body>
<h3 style="color:Tomato;">Hello World</h3>
<p style="color:DodgerBlue;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p style="color:MediumSeaGreen;">Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
</body>
</html>
Border Color
You can set the color of borders:
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="border: 2px solid Tomato;">Hello World</h1>
<h1 style="border: 2px solid DodgerBlue;">Hello World</h1>
<h1 style="border: 2px solid Violet;">Hello World</h1>
</body>
</html>
Color Values
Example
HTML Links - Hyperlinks
HTML links are hyperlinks.
You can click on a link and jump to another document.
When you move the mouse over a link, the mouse arrow will turn into a little hand.
HTML Links - Syntax
The HTML <a>
tag defines a hyperlink. It has the following syntax:
<a href="url">link text</a>
Example
<!DOCTYPE html>
<html>
<body>
<h1>HTML Links</h1>
<p><a href="https://www.google.com/">Visit google.com!</a></p>
</body>
</html>
HTML Page Title
Every web page should have a page title to describe the meaning of the page.
Example
HTML Tables
Example
Table Cells
Each table cell is defined by a <td>
and a </td>
tag.
Example
<!DOCTYPE html>
<html>
<style>
table, th, td {
border:1px solid black;
}
</style>
<body>
<h2>TD elements define table cells</h2>
<table style="width:100%">
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
</table>
<p>To understand the example better, we have added borders to the table.</p>
</body>
</html>
Table Rows
Each table row starts with a <tr>
and ends with a </tr>
tag.
Example
Table Headers
Sometimes you want your cells to be table header cells. In those cases use the <th>
tag instead of the <td>
tag:
Example
<!DOCTYPE html>
<html>
<style>
table, th, td {
border:1px solid black;
}
</style>
<body>
<h2>TH elements define table headers</h2>
<table style="width:100%">
<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>
<p>To understand the example better, we have added borders to the table.</p>
</body>
</html>
HTML Table Borders
How To Add a Border
To add a border, use the CSS border
property on table
, th
, and td
elements:
|
Example
Collapsed Table Borders
To avoid having double borders like in the example above, set the CSS border-collapse
property to collapse
.
This will make the borders collapse into a single border:
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<h2>Collapsed Borders</h2>
<p>If you want the borders to collapse into one border, add the CSS border-collapse property.</p>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Style Table Borders
If you set a background color of each cell, and give the border a white color (the same as the document background), you get the impression of an invisible border:
|
Example
Round Table Borders
With the border-radius
property, the borders get rounded corners:
Example
HTML Lists
HTML Description Lists
Using The class Attribute
The class
attribute is often used to point to a class name in a style sheet. It can also be used by a JavaScript to access and manipulate elements with the specific class name.
In the following example we have three <div>
elements with a class
attribute with the value of "city". All of the three <div>
elements will be styled equally according to the .city
style definition in the head section:
<!DOCTYPE html>
<html>
<head>
<style>
.city {
background-color: tomato;
color: white;
border: 2px solid black;
margin: 20px;
padding: 20px;
}
</style>
</head>
<body>
<div class="city">
<h2>London</h2>
<p>London is the capital of England.</p>
</div>
<div class="city">
<h2>Paris</h2>
<p>Paris is the capital of France.</p>
</div>
<div class="city">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
</div>
</body>
</html>
Iframe - Set Height and Width
Use the height
and width
attributes to specify the size of the iframe.
The height and width are specified in pixels by default:
Example
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of the iframe:</p>
<iframe src="demo_iframe.htm" height="200" width="300" title="Iframe Example"></iframe>
</body>
</html>
Iframe - Remove the Border
By default, an iframe has a border around it.
To remove the border, add the style
attribute and use the CSS border
property:
Example
<!DOCTYPE html>
<html>
<body>
<h2>Remove the Iframe Border</h2>
<p>To remove the default border of the iframe, use CSS:</p>
<iframe src="demo_iframe.htm" style="border:none;" title="Iframe Example"></iframe>
</body>
</html>
HTML Layout Elements
HTML has several semantic elements that define the different parts of a web page:
header>
- Defines a header for a document or a section<nav>
- Defines a set of navigation links<section>
- Defines a section in a document<article>
- Defines an independent, self-contained content<aside>
- Defines content aside from the content (like a sidebar)<footer>
- Defines a footer for a document or a section<details>
- Defines additional details that the user can open and close on demand<summary>
- Defines a heading for the<details>
element you can read more about sematic element in our html semantics chapter.
Example
HTML <input type="radio">
Example
Example
Example
Example
Input Date value Property
Example
HTML <input type="month">
Example
HTML Styles - CSS
What is CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
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!
Example
<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>
CSS Colors, Fonts and Sizes
Here, we will demonstrate some commonly used CSS properties. You will learn more about them later.
The CSS color
property defines the text color to be used.
The CSS font-family
property defines the font to be used.
The CSS font-size
property defines the text size to be used.
Example
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Padding
The CSS padding property defines a padding (space) between the text and the border.
Example
<html>
<head>
<style>
p {
border: 2px solid powderblue;
padding: 30px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
The <input> Element
The HTML <input>
element is the most used form element.
An <input>
element can be displayed in many ways, depending on the type
attribute.
Here are some examples:
Type | Description |
---|---|
<input type="text"> | Displays a single-line text input field |
<input type="radio"> | Displays a radio button (for selecting one of many choices) |
<input type="checkbox"> | Displays a checkbox (for selecting zero or more of many choices) |
<input type="submit"> | Displays a submit button (for submitting the form) |
<input type="button"> | Displays a clickable button |
Example
<html>
<body>
<h2>Radio Buttons</h2>
<p>Choose your favorite Web language:</p>
<form>
<input type="radio" id="html" name="fav_language" value="HTML">
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label for="css">CSS</label><br>
<input type="radio" id="javascript" name="fav_language" value="JavaScript">
<label for="javascript">JavaScript</label>
</form>
</body>
</html>
Checkboxes
The <input type="checkbox">
defines a checkbox.
Example
<html>
<body>
<h2>Checkboxes</h2>
<p>The <strong>input type="checkbox"</strong> defines a checkbox:</p>
<form action="/action_page.php">
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
The Submit Button
The <input type="submit">
defines a button for submitting the form data to a form-handler.
Example
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Display a Reset Button
The textarea form attribute
HTML <input type="checkbox">
Definition and Usage
The <input type="checkbox">
defines a checkbox.
The checkbox is shown as a square box that is ticked (checked) when activated.
Checkboxes are used to let a user select one or more options of a limited number of choices.
Tip: Always add the <label>
tag for best accessibility practices!
Comments
Post a Comment