(From W3 Schools) HTML is the standard markup language for creating Web pages.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Example explained:
<!DOCTYPE html>
declaration defines this document to be HTML5<html>
element is the root element of an HTML
page<head>
element contains meta information about the document<title>
element specifies a title for the document<body>
element contains the visible page content<h1>
element defines a large heading<p>
element defines a paragraphHTML tags are element names surrounded by angle brackets HTML tags normally come in pairs like <p> and </p> The first tag in a pair is the start tag, the second tag is the end tag The end tag is written like the start tag, but with a forward slash inserted before the tag name Only the content inside the <body> section (the white area in the image below) is displayed in a browser.
Below is a visualization of an HTML page structure:
An HTML element usually consists of a start tag and end tag, with the content inserted in between:
<tagname>Content goes here...</tagname>
The HTML element is everything from the start tag to the end tag:
<p>My first paragraph.</p>
Start tag | Element content | End tag |
---|---|---|
<h1> | My First Heading | </h1> |
<p> | My first paragraph. | </p> |
<br> |
HTML elements with no content are called empty elements. Empty elements do not have an end tag, such as the <br> element (which indicates a line break).
HTML elements can be nested (elements can contain elements). All HTML documents consist of nested HTML elements.
Attribute | Description |
---|---|
alt | Specifies an alternative text for an image, when the image cannot be displayed |
disabled | Specifies that an input element should be disabled |
href | Specifies the URL (web address) for a link |
id | Specifies a unique id for an element |
src | Specifies the URL (web address) for an image |
style | Specifies an inline CSS style for an element |
title | Specifies extra information about an element (displayed as a tool tip) |
A complete list of all attributes for each HTML element, is listed in: HTML Attribute Reference.
HTML also defines special elements for defining text with a special meaning.
HTML uses elements like <b> and <i> for formatting output, like bold or italic text.
<b>This text is bold.</b> <i> This text is italic.</i> <br>
This is <sub>subscript</sub> and <sup>superscript</sup>
This text is bold. This text is italic.
This is subscript and superscript
Tag | Description |
---|---|
<b> | Defines bold text |
<em> | Defines emphasized text |
<i> | Defines italic text |
<small> | Defines smaller text |
<strong> | Defines important text |
<sub> | Defines subscripted text |
<sup> | Defines superscripted text |
<ins> | Defines inserted text |
<del> | Defines deleted text |
<mark> | Defines marked/highlighted text |
HTML links are defined with the <a> tag The link's destination is specified in the href attribute. Destinations can be local or web-based (absolute URL) Attributes are used to provide additional information about HTML elements.
<a href="https://w3schools.com">This is a link<a/>
HTML images are defined with the <img> tag The source file (src), alternative text (alt), width, and height are provided as attributes The <img> tag is empty, it contains attributes only, and does not have a closing tag.
<img src="img_girl.jpg" alt="Girl in a jacket" </img>
HTML Headings
HTML Paragraphs
HTML Tables
HTML Lists
HTML Iframes
HTML Entities
CSS describes how HTML elements are to be displayed on screen, paper, or in other media. CSS saves a lot of work. It can control the layout of multiple web pages all at once. CSS can be added to HTML elements in 3 ways:
Inline - by using the style attribute in HTML elements
Internal - by using a <style> element in the <head> section
External - by using an external CSS file