Introduction to HTML
Introduction to HTML
HTML, or HyperText Markup Language, is the standard language used to create and design web pages. It
forms the structure of a webpage, defining elements such as text, images, links, and more.
Understanding HTML is crucial for creating and editing web content, especially in the context of IGCSE
Edexcel O Level ICT practical exams.
An HTML editor is a tool used to write and edit HTML code. These editors provide a convenient interface
for writing code and often include features like syntax highlighting, code suggestions, and error checking.
Popular HTML editors include Notepad++ (free and lightweight), Sublime Text, Visual Studio Code, and
online editors like CodePen.
Basics of HTML
HTML uses tags to structure and format content. Tags are enclosed in angle brackets, like `<tagname>`.
Most HTML elements have an opening tag `<tagname>` and a closing tag `</tagname>`, with content in
between.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<!-- Content goes here -->
</body>
</html>
- `<!DOCTYPE html>`: Declares the document type as HTML5.
- `<head>`: Contains meta-information about the document, such as its title and links to stylesheets.
- `<title>`: Specifies the title of the webpage (appears in the browser tab).
For example, `<p>` defines a paragraph, `<h1>` defines a heading, and `<a>` defines a link.
- Attributes: Provide additional information about elements. They are added inside the opening tag.
For example, In `<a href="https://example.com" >` href is an attribute and sets the link's
destination.
1. Headings: Defined with `<h1>` to `<h6>` tags, where `<h1>` is the largest heading and `<h6>` is the
smallest.
```
<h1>Main Heading</h1>
<h2>Sub Heading</h2>
```
```
<p>This is a paragraph.</p>
```
3. Links: Defined using the `<a>` tag with the `href` attribute to specify the URL.
```
```
4. Images: Defined using the `<img>` tag with the `src` attribute to specify the image source and the `alt`
attribute for alternative text.
```
```
5. Videos: Defined using the `<video>` tag with `src`, `controls`, and other attributes.
```
```
CSS (Cascading Style Sheets) is used to style HTML elements. There are three types of CSS:
1. Inline CSS: Styles are applied directly within an HTML element using the `style` attribute.
```
```
2. Internal CSS: Styles are defined within the `<style>` tag inside the `<head>` section of the HTML
document.
```
<style>
p{
color: blue;
font-size: 14px;
</style>
```
3. External CSS: Styles are defined in a separate file (e.g., `styles.css`) and linked to the HTML document
using the `<link>` tag.
```
```
Tables are defined using the `<table>` tag. Each table row is defined with `<tr>`, table headers with
`<th>`, and table cells with `<td>`.
```
<table border="1">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>
```
Links and Anchors
- Use the `<a>` tag to create hyperlinks. The `href` attribute specifies the URL.
```
```
```
```
HTML provides various ways to format text and modify the attributes of tables, images, and videos.
These modifications help enhance the appearance and functionality of web content.
Text Formatting
HTML offers several tags to format text, making it bold, italic, underlined, or changing its size and
color:
```
<b>Bold Text</b>
```
```
<i>Italic Text</i>
```
```
<u>Underlined Text</u>
```
- Font Size and Color: Use the `style` attribute to change the size and color of the text.
```
```
- Font Family: Change the typeface of text using the `font-family` property.
```
```
- Text Alignment: Align text to the left, right, center, or justify it using the `text-align` property.
```
```
Width and Height: Adjust the dimensions of tables, images, and videos using the `width`
and `height` attributes.
- Image Example:
```
<img src="image.jpg" width="200" height="150" alt="Description">
```
- Table Example:
```
</table>
```
- Video Example:
```
```
Background Color: Change the background color of text, tables, or cells using the `style`
attribute with the `background-color` property.
- Table Example:
```
<tr>
<td>Cell 2</td>
</tr>
</table>
```
Borders: Add or modify borders around tables, cells, images, or videos using the `border`
attribute or `style` property.
- Table Example:
```
<tr>
<td>Cell 2</td>
</tr>
</table>
```
- Image Example:
```
```
Padding and Margin: Add space around elements using `padding` (inside an element)
and `margin` (outside an element).
```
```
```
```
Text Decoration: Remove or add text decorations such as underlines with the `text-
decoration` property.
```
<a href="https://example.com" style="text-decoration: none;">Link without
underline</a>
```
Opacity: Adjust the transparency of images and videos using the `opacity` property.
```
```
Hover Effects: Change the appearance of elements when the mouse hovers over them
using the `:hover` CSS pseudo-class.
```
<style>
img:hover {
opacity: 0.7;
</style>
```
Responsive Design: Use percentages or viewport units (`vw`, `vh`) for width and height
to make elements responsive, adapting to different screen sizes.
```
```