HTML Notes
HTML Notes
Example:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
Example Explained:
<!DOCTYPE html> declaration defines that this document is an HTML5
document.
- represents the document type and helps browsers to display web pages
correctly.
- must only appear once, at the top of the page (before any HTML tags).
- is not case sensitive.
<html> element is the root element of an HTML page.
<head> element contains meta information about the HTML page.
<title> element specifies a title for the HTML page (which is shown in the
browser's title bar or in the page's tab).
<body> element defines the document's body, and is a container for all the
visible contents, such as headings, paragraphs, images, hyperlinks, tables, lists,
etc.
<h1> element defines a large heading.
- <h1> defines the most important heading. <h6> defines the least important
heading.
<p> element defines a paragraph.
<a> defines HTML links.
- the link's destination is specified in the href attribute.
<img> defines HTML images
- the source file (src), alternative text (alt), width, and height are provided as
attributes
The content inside the <body> section will be displayed in a browser. The content inside
the <title> element will be shown in the browser's title bar or in the page's tab.
An HTML element is defined by a start tag, some content, and an end tag:
<start tag> Content goes here... </end tag>
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".
HTML Headings
HTML headings are titles or subtitles that are displayed on a webpage.
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading.
<h1 style="font-size:60px;">Heading 1</h1>
HTML Paragraphs
The HTML <p> element defines a paragraph.
A paragraph always starts on a new line, and browsers automatically add some white
space (a margin) before and after a paragraph.
The browser will automatically remove any extra spaces and lines when the page is
displayed.
Horizontal Rules
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as
a horizontal rule.
The <hr> element is used to separate content (or define a change) in an HTML page.
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
<pre> Element
The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and
it preserves both spaces and line breaks:
<pre>
My Bonnie lies over the ocean.
Background Color
The CSS background-color property defines the background color for an HTML
element.
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Text Color
The CSS color property defines the text color for an HTML element:
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
Fonts
The CSS font-family property defines the font to be used for an HTML element:
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
Text Size
The CSS font-size property defines the text size for an HTML element:
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
Text Alignment
The CSS text-align property defines the horizontal text alignment for an HTML element:
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
Hide Content
Comments can be used to hide content.
<p>This is a paragraph.</p>
<!-- <p>This is another paragraph </p> -->
<p>This is a paragraph too.</p>
<p>This is a paragraph.</p>
<!--
<p>Look at this cool image:</p>
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
<p>This is a paragraph too.</p>
Comments are also great for debugging HTML, because the user can comment out
HTML lines of code, one at a time, to search for errors.
Color Names
In HTML, a color can be specified by using a color name:
Background Color
Color Values
In HTML, colors can also be specified using RGB values, HEX values, HSL values,
RGBA values, and HSLA values.
The following three <div> elements have their background color set with RGB, HEX,
and HSL values:
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1>
Shades of Gray
Shades of gray are often defined using equal values for all three parameters:
RGBA Color Values
RGBA color values are an extension of RGB color values with an Alpha channel - which
specifies the opacity for a color.
An RGBA color value is specified with:
rgba(red, green, blue, alpha)
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not
transparent at all):
Example:
Shades of Gray
Shades of gray are often defined using equal values for all three parameters:
Saturation
Saturation can be described as the intensity of a color.
100% is pure color, no shades of gray.
50% is 50% gray, but you can still see the color.
0% is completely gray; you can no longer see the color.
Lightness
The lightness of a color can be described as how much light you want to give the color,
where 0% means no light (black), 50% means 50% light (neither dark nor light), and
100% means full lightness (white).
Shades of Gray
Shades of gray are often defined by setting the hue and saturation to 0, and adjusting
the lightness from 0% to 100% to get darker/lighter shades:
What is CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
The word cascading means that a style applied to a parent element will also apply to all
children elements within the parent.
Using CSS
CSS can be added to HTML documents in 3 ways:
Inline - by using the style attribute inside HTML elements
Internal - by using a <style> element in the <head> section
External - by using a <link> element to link to an external CSS file
The most common way to add CSS, is to keep the styles in external CSS files.
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text color
of the <p> element to red:
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>