Theory of HTML
Theory of HTML
Introduction
HTML is the standard markup language for creating Web pages.
What is HTML?
HTML stands for Hyper Text Markup Language
HTML is the standard markup language for creating Web pages
HTML describes 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 link", etc.
Example Explained
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
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="https://www.w3schools.com">This is a link</a>
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
<img src="image.jpg" alt="image.com" width="104" height="142">
Right-click in an HTML page and select "View Page Source" (in Chrome) or "View Source" (in
Edge), or similar in other browsers. This will open a window containing the HTML source code
of the page.
Right-click on an element (or a blank area), and choose "Inspect" or "Inspect Element" to see
what elements are made up of (you will see both the HTML and the CSS). You can also edit the
HTML or CSS on-the-fly in the Elements or Styles panel that opens.
HTML Attributes
HTML attributes provide additional information about HTML elements.
HTML Attributes
All HTML elements can have attributes
Attributes provide additional information about elements
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like: name="value"
Example
<a href="https://www.google.com">Visit google</a>
Example
<img src="img_girl.jpg">
2. Relative URL - Links to an image that is hosted within the website. Here, the URL does not
include the domain name. If the URL begins without a slash, it will be relative to the current
page. Example: src="img_girl.jpg". If the URL begins with a slash, it will be relative to the
domain. Example: src="/images/img_girl.jpg".
HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font, size, and
more.
Example
I am Red
I am Blue
I am Big
The HTML Style Attribute
Setting the style of an HTML element, can be done with the style attribute.
<tagname style="property:value;">
Background Color
The CSS background-color property defines the background color for an HTML element.
Text Color
The CSS color property defines the text color for an HTML element:
Fonts
The CSS font-family property defines the font to be used for an HTML element:
HTML Colors
HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA,
or HSLA values.
Color Names
In HTML, a color can be specified by using a color name:
RGB Color Values
In HTML, a color can be specified as an RGB value, using this formula:
rgb(red, green, blue)
Each parameter (red, green, and blue) defines the intensity of the color with a value between 0
and 255.
This means that there are 256 x 256 x 256 = 16777216 possible colors!
For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255), and
the other two (green and blue) are set to 0.
Another example, rgb(0, 255, 0) is displayed as green, because green is set to its highest value
(255), and the other two (red and blue) are set to 0.
To display black, set all color parameters to 0, like this: rgb(0, 0, 0).
To display white, set all color parameters to 255, like this: rgb(255, 255, 255).
#rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff (same as
decimal 0-255).
For example, #ff0000 is displayed as red, because red is set to its highest value (ff), and the other
two (green and blue) are set to 00.
Another example, #00ff00 is displayed as green, because green is set to its highest value (ff), and
the other two (red and blue) are set to 00.
To display black, set all color parameters to 00, like this: #000000.
To display white, set all color parameters to ff, like this: #ffffff.
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
Table Cells
Each table cell is defined by a <td> and a </td> tag.
Table Rows
Each table row starts with a <tr> and end with a </tr> tag.
Table Headers
Sometimes you want your cells to be headers, in those cases use the <th> tag instead of
the <td> tag:
HTML Block and Inline
Elements
Every HTML element has a default display value, depending on what type of element it is.
Block-level Elements
A block-level element always starts on a new line.
A block-level element always takes up the full width available (stretches out to the left and right
as far as it can).
A block level element has a top and a bottom margin, whereas an inline element does not.
Inline Elements
An inline element does not start on a new line.
HTML class Attribute
The HTML class attribute is used to specify a class for an HTML element.
Multiple HTML elements can share the same class.
HTML id Attribute
The HTML id attribute is used to specify a unique id for an HTML element.
You cannot have more than one element with the same id in an HTML document.
The id attribute is used to point to a specific style declaration in a style sheet. It is also used by
JavaScript to access and manipulate the element with the specific id.
The syntax for id is: write a hash character (#), followed by an id name. Then, define the CSS
properties within curly braces {}.
CSS Introduction
CSS is the language we use to style a Web page.
What is CSS?
CSS stands for Cascading Style Sheets
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
External stylesheets are stored in CSS files
CSS Selectors
A CSS selector selects the HTML element(s) you want to style.
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
The id of an element is unique within a page, so the id selector is used to select one unique
element!
To select an element with a specific id, write a hash (#) character, followed by the id of the
element.
To select elements with a specific class, write a period (.) character, followed by the class name.
CSS Borders
The CSS border properties allow you to specify the style, width, and color of an element's
border.
groove - Defines a 3D grooved border. The effect depends on the border-color value
ridge - Defines a 3D ridged border. The effect depends on the border-color value
inset - Defines a 3D inset border. The effect depends on the border-color value
outset - Defines a 3D outset border. The effect depends on the border-color value
CSS Margins
The CSS margin properties are used to create space around elements, outside of any defined
borders.
With CSS, you have full control over the margins. There are properties for setting the margin for
each side of an element (top, right, bottom, and left).
margin-top
margin-right
margin-bottom
margin-left
CSS Padding
The CSS padding properties are used to generate space around an element's content, inside of any
defined borders.
With CSS, you have full control over the padding. There are properties for setting the padding for
each side of an element (top, right, bottom, and left).
padding-top
padding-right
padding-bottom
padding-left
CSS Layout - Overflow
The CSS overflow property controls what happens to content that is too big to fit into an area.
CSS Overflow
The overflow property specifies whether to clip the content or to add scrollbars when the content
of an element is too big to fit in the specified area.
visible - Default. The overflow is not clipped. The content renders outside the element's
box
hidden - The overflow is clipped, and the rest of the content will be invisible
scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content
The CSS clear property specifies what elements can float beside the cleared element and on
which side.
none - The element does not float (will be displayed just where it occurs in the text). This
is default
inherit - The element inherits the float value of its parent
In its simplest use, the float property can be used to wrap text around images.