With HTML you can create your own Web site. This tutorial teaches you everything about HTML.

Similar documents
Programmazione Web a.a. 2017/2018 HTML5

INFORMATICA GENERALE 2014/2015 LINGUAGGI DI MARKUP CSS

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM Advanced Internet Technology Lab.

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

INTRODUCTION TO WEB USING HTML What is HTML?

Appendix D CSS Properties and Values

Reading 2.2 Cascading Style Sheets

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

CSS CSS how to display to solve a problem External Style Sheets CSS files CSS Syntax

CMPT 165 INTRODUCTION TO THE INTERNET AND THE WORLD WIDE WEB

Comp-206 : Introduction to Software Systems Lecture 23. Alexandre Denault Computer Science McGill University Fall 2006

BIM222 Internet Programming

HTML TAG SUMMARY HTML REFERENCE 18 TAG/ATTRIBUTE DESCRIPTION PAGE REFERENCES TAG/ATTRIBUTE DESCRIPTION PAGE REFERENCES MOST TAGS

Study Guide 2 - HTML and CSS - Chap. 6,8,10,11,12 Name - Alexia Bernardo

HTML/XML. HTML Continued Introduction to CSS

Assignments (4) Assessment as per Schedule (2)

CSS. Lecture 16 COMPSCI 111/111G SS 2018

COSC 2206 Internet Tools. CSS Cascading Style Sheets

Introduction to using HTML to design webpages

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

Web Design 101. What is HTML? HTML Tags. Web Browsers. <!DOCTYPE html> <html> <body> <h1>my First Heading</h1> <p>my first paragraph.

CSS Lecture 16 COMPSCI 111/111G SS 2018

Parashar Technologies HTML Lecture Notes-4

ICT IGCSE Practical Revision Presentation Web Authoring

Html basics Course Outline

Review Question 1. Which tag is used to create a link to another page? 1. <p> 2. <li> 3. <a> 4. <em>

Introduction to Web Design CSS Reference

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Introduction to Web Design CSS Reference

Chapter 1 Self Test. LATIHAN BAB 1. tjetjeprb{at}gmail{dot}com. webdesign/favorites.html :// / / / that houses that information. structure?

HTML TUTORIAL ONE. Understanding What XHTML is Not

CSS: The Basics CISC 282 September 20, 2014

- The CSS1 specification was developed in CSSs provide the means to control and change presentation of HTML documents

3.1 Introduction. 3.2 Levels of Style Sheets. - HTML is primarily concerned with content, rather than style. - There are three levels of style sheets

11. HTML5 and Future Web Application

Web Designing HTML5 NOTES

As we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.

ICT IGCSE Practical Revision Presentation Web Authoring

CSS means Cascading Style Sheets. It is used to style HTML documents.

- HTML is primarily concerned with content, rather than style. - However, tags have presentation properties, for which browsers have default values

Markup Language SGML: Standard Generalized Markup Language. HyperText Markup Language (HTML) extensible Markup Language (XML) TeX LaTeX

COPYRIGHTED MATERIAL. Contents. Chapter 1: Creating Structured Documents 1

CHAPTER 2 MARKUP LANGUAGES: XHTML 1.0

Web Technologies - by G. Sreenivasulu Handout - 1 UNIT - I

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

Index. CSS directive, # (octothorpe), intrapage links, 26

Web Publishing Basics I

CSS Selectors. element selectors. .class selectors. #id selectors

HTML Images - The <img> Tag and the Src Attribute

What is CSS? NAME: INSERT OPENING GRAPHIC HERE:

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

HTML and CSS COURSE SYLLABUS

**Method 3** By attaching a style sheet to your web page, and then placing all your styles in that new style sheet.

The building block of a CSS stylesheet. A rule consists of a selector and a declaration block (one or more declarations).

HTML Hyperlinks (Links)

Hyper Text Markup Language HTML: A Tutorial

Deccansoft Software Services

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2)

CSS. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

CSS Cascading Style Sheets

Chapter 3 Style Sheets: CSS

Adding CSS to your HTML

It is possible to create webpages without knowing anything about the HTML source behind the page.

Web Page Creation Part I. CS27101 Introduction to Web Interface Design Prof. Angela Guercio

ADDING CSS TO YOUR HTML DOCUMENT. A FEW CSS VALUES (colour, size and the box model)

Cascading Style Sheet Quick Reference

Web Publishing with HTML

Lab 4 CSS CISC1600, Spring 2012

HTML & CSS. SWE 432, Fall 2017 Design and Implementation of Software for the Web

3.1 Introduction. 3.2 Levels of Style Sheets. - The CSS1 specification was developed in There are three levels of style sheets

- The CSS1 specification was developed in CSS2 was released in CSS2.1 reflects browser implementations

CSS for Styling CS380

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

Methods for configuring Cascading Style Sheets. Applying style to element name selectors. Style Rule Basics. CMPT 165: Cascading Style Sheets

Unit 5 Web Publishing Systems Page 1 of 13 Part 4 HTML Part 4

7300 Warden Avenue, Suite 503 Markham, Ontario Canada L3R 9Z6. Phone: Toll Free: Fax:

Table Basics. The structure of an table

Using Dreamweaver. 6 Styles in Websites. 1. Linked or Imported Stylesheets. 2. Embedded Styles. 3. Inline Styles

ID1354 Internet Applications

CSS stands for Cascading Style Sheets Styles define how to display HTML elements

Table of Contents Chapter 9. Working with Cascading Style Sheets ... 1

Creating Web Pages with SeaMonkey Composer

By Ryan Stevenson. Guidebook #2 HTML

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

Lecture B3 Style : Algorithmic Thinking. Computing and Art : Nature, Power, and Limits CC 3.12: Fall 2007

The internet is a worldwide collection of networks that link millions of computers. These links allow the computers to share and send data.

CSS.

A HTML document has two sections 1) HEAD section and 2) BODY section A HTML file is saved with.html or.htm extension

Controlling Appearance the Old Way

CMPT 165: More CSS Basics

Introduction to Web Tech and Programming

Fundamentals: Client/Server

Dreamweaver Basics. Planning your website Organize site structure Plan site design & navigation Gather your assets

Using Dreamweaver CS6

CSS: Cascading Style Sheets

CSI 3140 WWW Structures, Techniques and Standards. Markup Languages: XHTML 1.0

Web Programming HTML CSS JavaScript Step by step Exercises Hans-Petter Halvorsen

INTRODUCTION TO HTML5! HTML5 Page Structure!

CSC 121 Computers and Scientific Thinking

Transcription:

CHAPTER ONE

With HTML you can create your own Web site. This tutorial teaches you everything about HTML.

Example Explained The DOCTYPE declaration defines the document type The text between <html> and </html> describes the web page The text between <body> and </body> is the visible page content The text between <h1> and </h1> is displayed as a heading The text between <p> and </p> is displayed as a paragraph What is HTML? HTML is a language for describing web pages. HTML stands for Hyper Text Markup Language HTML is a markup language A markup language is a set of markup tags The tags describe document content HTML documents contain HTML tags and plain text HTML documents are also called web pages

HTML Tags HTML markup tags are usually called HTML tags HTML tags are keywords (tag names) surrounded by angle brackets like <html> HTML tags normally come in pairs like <b> and </b> 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, with a forward slash before the tag name Start and end tags are also called opening tags and closing tags

HTML Elements "HTML tags" and "HTML elements" are often used to describe the same thing. But strictly speaking, an HTML element is everything between the start tag and the end tag, including the tags: HTML Element:

Web Browsers The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox, Safari) is to read HTML documents and display them as web pages. The browser does not display the HTML tags, but uses the tags to interpret the content of the page:

HTML Page Structure Below is a visualization of an HTML page structure:

HTML Versions Since the early days of the web, there have been many versions of HTML: Version Year HTML 1991 HTML+ 1993 HTML 2.0 1995 HTML 3.2 1997 HTML 4.01 1999 XHTML 1.0 2000 HTML5 2012 XHTML5 2013

The <!DOCTYPE> Declaration The <!DOCTYPE> declaration helps the browser to display a web page correctly. There are many different documents on the web, and a browser can only display an HTML page 100% correctly if it knows the HTML type and version used. Common Declarations HTML5 HTML 4.01 XHTML 1.0

HTML Editors Writing HTML Using Notepad or TextEdit HTML can be edited by using a professional HTML editor like: Adobe Dreamweaver Microsoft Expression Web However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac). We believe using a simple text editor is a good way to learn HTML. Follow the 4 steps below to create your first web page with Notepad.

Step 1: Start Notepad To start Notepad go to: Start All Programs Accessories Notepad Step 2: Edit Your HTML with Notepad Type your HTML code into your Notepad:

Step 3: Save Your HTML Select Save as.. in Notepad's file menu. When you save an HTML file, you can use either the.htm or the.html file extension. There is no difference, it is entirely up to you. Save the file in a folder that is easy to remember, like w3schools. Step 4: Run the HTML in Your Browser Start your web browser and open your html file from the File, Open menu, or just browse the folder and double-click your HTML file. The result should look much like this:

HTML Elements HTML documents are defined by HTML elements. HTML Elements An HTML element is everything from the start tag to the end tag: Start tag * Element content End tag * <p> This is a paragraph </p> <a href="default.htm"> This is a link </a> <br> * The start tag is often called the opening tag. The end tag is often called the closing tag.

HTML Element Syntax An HTML element starts with a start tag / opening tag An HTML element ends with an end tag / closing tag The element content is everything between the start and the end tag Some HTML elements have empty content Empty elements are closed in the start tag Most HTML elements can have attributes Nested HTML Elements Most HTML elements can be nested (can contain other HTML elements). HTML documents consist of nested HTML elements.

HTML Document Example The example above contains 3 HTML elements.

HTML Example Explained The <p> element: The <p> element defines a paragraph in the HTML document. The element has a start tag <p> and an end tag </p>. The element content is: This is my first paragraph. The <body> element: The <body> element defines the body of the HTML document. The element has a start tag <body> and an end tag </body>. The element content is another HTML element (a p element).

The <html> element: The <html> element defines the whole HTML document. The element has a start tag <html> and an end tag </html>. The element content is another HTML element (the body element). Don't Forget the End Tag Some HTML elements might display correctly even if you forget the end tag: The example above works in most browsers, because the closing tag is considered optional. Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag.

Empty HTML Elements HTML elements with no content are called empty elements. <br> is an empty element without a closing tag (the <br> tag defines a line break). Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br />, is the proper way of closing empty elements in XHTML (and XML). HTML Tip: Use Lowercase Tags HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use uppercase HTML tags. W3Schools use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML.

HTML Attributes Attributes provide additional information about HTML elements. HTML Attributes HTML elements can have attributes Attributes provide additional information about an element Attributes are always specified in the start tag Attributes come in name/value pairs like: name="value" Always Quote Attribute Values Attribute values should always be enclosed in quotes. Double style quotes are the most common, but single style quotes are also allowed. Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use single quotes: name='john "ShotGun" Nelson'

HTML Tip: Use Lowercase Attributes Attribute names and attribute values are case-insensitive. However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation. Newer versions of (X)HTML will demand lowercase attributes.

HTML Headings Headings are important in HTML documents. HTML Headings Headings are defined with the <h1> to <h6> tags. <h1> defines the most important heading. <h6> defines the least important heading. Note: Browsers automatically add some empty space (a margin) before and after each heading.

Headings Are Important Use HTML headings for headings only. Don't use headings to make text BIG or bold. Search engines use your headings to index the structure and content of your web pages. Since users may skim your pages by its headings, it is important to use headings to show the document structure. H1 headings should be used as main headings, followed by H2 headings, then the less important H3 headings, and so on.

HTML Lines The <hr>tag creates a horizontal line in an HTML page. The hr element can be used to separate content:

HTML Comments Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed. Comments are written like this: Note: There is an exclamation point after the opening bracket, but not before the closing bracket. HTML Tip - How to View HTML Source Have you ever seen a Web page and wondered "Hey! How did they do that?" To find out, right-click in the page and select "View Source" (IE) or "View Page Source" (Firefox), or similar for other browsers. This will open a window containing the HTML code of the page.

HTML Paragraphs HTML documents are divided into paragraphs. HTML Paragraphs Paragraphs are defined with the <p> tag. Note: Browsers automatically add an empty line before and after a paragraph.

Don't Forget the End Tag Most browsers will display HTML correctly even if you forget the end tag: The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce unexpected results or errors. Note: Future version of HTML will not allow you to skip end tags.

HTML Line Breaks Use the <br> tag if you want a line break (a new line) without starting a new paragraph: The <br> element is an empty HTML element. It has no end tag. HTML Output - Useful Tips You cannot be sure how HTML will be displayed. Large or small screens, and resized windows will create different results. With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code. The browser will remove extra spaces and extra lines when the page is displayed. Any number of lines count as one line, and any number of spaces count as one space.

HTML TUTORIAL

HTML Text Formatting

HTML Formatting Tags HTML uses tags like <b> and <i> for formatting output, like bold or italictext. These HTML tags are called formatting tags (look at the bottom of this page for a complete reference). Often <strong> renders as <b>, and <em> renders as <i>. However, there is a difference in the meaning of these tags: < b> or <i> defines bold or italic text only. < strong> or <em> means that you want the text to be rendered in a way that the user understands as "important". Today, all major browsers render strong as bold and em as italics. However, if a browser one day wants to make a text highlighted with the strong feature, it might be cursive for example and not bold!

HTML Links Links are found in nearly all Web pages. Links allow users to click their way from page to page. HTML Hyperlinks (Links) The HTML <a> tag defines a hyperlink. A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document. When you move the cursor over a link in a Web page, the arrow will turn into a little hand. The most important attribute of the <a> element is the href attribute, which indicates the link s destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue A visited link is underlined and purple An active link is underlined and red

HTML Link Syntax The HTML code for a link is simple. It looks like this: The href attribute specifies the destination of a link. Example which will display like this:visit W3Schools Clicking on this hyperlink will send the user to W3Schools' homepage. Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.

HTML Links - The target Attribute The target attribute specifies where to open the linked document. The example below will open the linked document in a new browser window or a new tab:

HTML <head> The HTML <head> Element The <head> element is a container for all the head elements. Elements inside <head> can include scripts, instruct the browser where to find style sheets, provide meta information, and more. The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>, <noscript>, and <base>. The HTML <title> Element The <title> tag defines the title of the document. The <title> element is required in all HTML/XHTML documents. The <title> element: defines a title in the browser toolbar provides a title for the page when it is added to favorites displays a title for the page in search-engine results

A simplified HTML document: The HTML <base> Element The <base> tag specifies the base URL/target for all relative URLs in a page:

The HTML <link> Element The <link> tag defines the relationship between a document and an external resource. The <link> tag is most used to link to style sheets: The HTML <style> Element The <style> tag is used to define style information for an HTML document. Inside the <style> element you specify how HTML elements should render in a browser:

The HTML <style> Element The <style> tag is used to define style information for an HTML document. Inside the <style> element you specify how HTML elements should render in a browser:

The HTML <meta> Element Metadata is data (information) about data. The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parsable. Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata. The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services. <meta> tags always goes inside the <head> element.

<meta> Tags - Examples of Use Define keywords for search engines: Define a description of your web page: Define the author of a page: Refresh document every 30 seconds:

The HTML <script> Element The <script> tag is used to define a client-side script, such as a JavaScript. The <script> element will be explained in a later chapter. HTML head Elements Tag <head> <title> <base> <link> <meta> <script> <style> Description Defines information about the document Defines the title of a document Defines a default address or a default target for all links on a page Defines the relationship between a document and an external resource Defines metadata about an HTML document Defines a client-side script Defines style information for a document

HTML Images HTML Images - The <img> Tag and the Src Attribute In HTML, images are defined with the <img> tag. The <img> tag is empty, which means that it contains attributes only, and has no closing tag. To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display. Syntax for defining an image: The URL points to the location where the image is stored. An image named "boat.gif", located in the "images" directory on "www.w3schools.com" has the URL: http://www.w3schools.com/images/boat.gif. The browser displays the image where the <img> tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph.

HTML Images - The Alt Attribute The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The value of the alt attribute is an author-defined text: The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

HTML Images - Set Height and Width of an Image The height and width attributes are used to specify the height and width of an image. The attribute values are specified in pixels by default: Tip: It is a good practice to specify both the height and width attributes for an image. If these attributes are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image. The effect will be that the page layout will change during loading (while the images load).

Basic Notes - Useful Tips Note: If an HTML file contains ten images - eleven files are required to display the page right. Loading images takes time, so my best advice is: Use images carefully. Note: When a web page is loaded, it is the browser, at that moment, that actually gets the image from a web server and inserts it into the page. Therefore, make sure that the images actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image.

HTML Tables Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc. Table Example How the HTML code above looks in a browser:

HTML Tables and the Border Attribute If you do not specify a border attribute, the table will be displayed without borders. Sometimes this can be useful, but most of the time, we want the borders to show. To display a table with borders, specify the border attribute:

HTML Table Headers Header information in a table are defined with the <th> tag. All major browsers display the text in the <th> element as bold and centered. How the HTML code above looks in your browser

HTML Table Tags Tag <table> <th> <tr> <td> <caption> <colgroup> <col> <thead> <tbody> <tfoot> Description Defines a table Defines a header cell in a table Defines a row in a table Defines a cell in a table Defines a table caption Specifies a group of one or more columns in a table for formatting Specifies column properties for each column within a <colgroup> element Groups the header content in a table Groups the body content in a table Groups the footer content in a table

HTML Lists The most common HTML lists are ordered and unordered lists:

How the HTML code above looks in a browser: Coffee Milk

HTML Ordered Lists An ordered list starts with the <ol> tag. Each list item starts with the <li> tag. The list items are marked with numbers. How the HTML code above looks in a browser: 1. Coffee 2. Milk

HTML Definition Lists A definition list is a list of items, with a description of each item. The <dl> tag defines a definition list. The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes the item in the list): How the HTML code above looks in a browser: Coffee - black hot drink Milk - white cold drink

HTML List Tags Tag <ol> <ul> <li> <dl> <dt> <dd> Description Defines an ordered list Defines an unordered list Defines a list item Defines a definition list Defines an item in a definition list Defines a description of an item in a definition list

HTML <div> and <span> HTML elements can be grouped together with <div> and <span>. HTML Block Elements Most HTML elements are defined as block level elements or as inline elements. Block level elements normally start (and end) with a new line when displayed in a browser. Examples: <h1>, <p>, <ul>, <table> HTML Inline Elements Inline elements are normally displayed without starting a new line. Examples: <b>, <td>, <a>, <img>

The HTML <div> Element The HTML <div> element is a block level element that can be used as a container for grouping other HTML elements. The <div> element has no special meaning. Except that, because it is a block level element, the browser will display a line break before and after it. When used together with CSS, the <div> element can be used to set style attributes to large blocks of content. Another common use of the <div> element, is for document layout. It replaces the "old way" of defining layout using tables. Using tables is not the correct use of the <table> element. The purpose of the <table> element is to display tabular data. <div style="color:#0000ff"> <h3>this is a heading</h3> <p>this is a paragraph.</p> </div>

The HTML <span> Element The HTML <span> element is an inline element that can be used as a container for text. The <span> element has no special meaning. When used together with CSS, the <span> element can be used to set style attributes to parts of the text. <p>my mother has <span style="color:blue">blue</span> eyes.</p> HTML Grouping Tags Tag <div> <span> Description Defines a section in a document (block-level) Defines a section in a document (inline)

http://www.tizag.com/ https://www.w3schools.com/

HTML TUTORIAL

HTML Layouts Web page layout is very important to make your website look good. Design your webpage layout very carefully. Website Layouts Most websites have put their content in multiple columns (formatted like a magazine or newspaper). Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages. Even though it is possible to create nice layouts with HTML tables, tables were designed for presenting tabular data - NOT as a layout tool!

HTML Layouts - Using <div> Elements The div element is a block level element used for grouping HTML elements. The following example uses five div elements to create a multiple column layout, creating the same result as in the previous example:

The HTML code above will produce the following result: HTML Layouts - Using Tables A simple way of creating layouts is by using the HTML <table> tag. Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages. Using <table> to create a nice layout is NOT the correct use of the element. The purpose of the <table> element is to display tabular data!

The following example uses a table with 3 rows and 2 columns - the first and last row spans both columns using the colspan attribute:

The HTML code above will produce the following result:

HTML Layout - Useful Tips Tip: The biggest advantage of using CSS is that, if you place the CSS code in an external style sheet, your site becomes MUCH EASIER to maintain. You can change the layout of all your pages by editing one file. To learn more about CSS, study our CSS tutorial. Tip: Because advanced layouts take time to create, a quicker option is to use a template. Search Google for free website templates (these are pre-built website layouts you can use and customize). HTML Layout Tags Tag <div> <span> Description Defines a section in a document (block-level) Defines a section in a document (inline)

HTML Forms and Input HTML Forms are used to select different kinds of user input. HTML Forms HTML forms are used to pass data to a server. An HTML form can contain input elements like text fields, checkboxes, radiobuttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. The <form> tag is used to create an HTML form:

HTML Forms - The Input Element The most important form element is the <input> element. The <input> element is used to select user information. An <input> element can vary in many ways, depending on the type attribute. An <input> element can be of type text field, checkbox, password, radio button, submit button, and more. The most common input types are described below.

Text Fields <input type="text"> defines a one-line input field that a user can enter text into: How the HTML code above looks in a browser: First name : Last name : Note: The form itself is not visible. Also note that the default width of a text field is 20 character

Password Field <input type="password"> defines a password field: How the HTML code above looks in a browser: Password : Note: The characters in a password field are masked (shown as asterisks or circles(.

Radio Buttons <input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE of a limited number of choices: How the HTML code above looks in a browser: Male Female

Checkboxes <input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number of choices. How the HTML code above looks in a browser: I have a bike I have a car

Submit Button <input type="submit"> defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input: How the HTML code above looks in a browser: Username : If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input.

HTML Form Tags New tags in HTML5 Tag <form> <input> <textarea> <label> <fieldset> <legend> <select> <optgroup> <option> <button> <datalist>new <keygen>new <output>new Description Defines an HTML form for user input Defines an input control Defines a multiline input control (text area) Defines a label for an <input> element Groups related elements in a form Defines a caption for a <fieldset> element Defines a drop-down list Defines a group of related options in a drop-down list Defines an option in a drop-down list Defines a clickable button Specifies a list of pre-defined options for input controls Defines a key-pair generator field (for forms) Defines the result of a calculation

HTML Iframes Syntax for adding an iframe: The URL points to the location of the separate page. Iframe - Set Height and Width The height and width attributes are used to specify the height and width of the iframe. The attribute values are specified in pixels by default, but they can also be in percent (like "80%").

Iframe - Remove the Border The frameborder attribute specifies whether or not to display a border around the iframe. Set the attribute value to "0" to remove the border: Use iframe as a Target for a Link An iframe can be used as the target frame for a link. The target attribute of a link must refer to the name attribute of the iframe: HTML iframe Tag

HTML Colors Colors are displayed combining RED, GREEN, and BLUE light. Color Values HTML colors are defined using a hexadecimal notation (HEX) for the combination of Red, Green, and Blue color values (RGB). The lowest value that can be given to one of the light sources is 0 (in HEX: 00). The highest value is 255 (in HEX: FF). HEX values are specified as 3 pairs of two-digit numbers, starting with a # sign.

16 Million Different Colors The combination of Red, Green, and Blue values from 0 to 255, gives more than 16 million different colors (256 x 256 x 256). If you look at the color table below, you will see the result of varying the red light from 0 to 255, while keeping the green and blue light at zero. To see the full list of color mixes when RED varies from 0 to 255, click on one of the HEX or RGB values below.

Shades of Gray Gray colors are created by using an equal amount of power to all of the light sources. To make it easier for you to select the correct shade, we have created a table of gray shades for you:

Web Safe Colors? Some years ago, when computers supported max 256 different colors, a list of 216 "Web Safe Colors" was suggested as a Web standard, reserving 40 fixed system colors. The 216 cross-browser color palette was created to ensure that all computers would display the colors correctly when running a 256 color palette. This is not important today, since most computers can display millions of different colors. Anyway, here is the list:

HTML Color Names Color Names Supported by All Browsers 147 color names are defined in the HTML and CSS color specification (16 basic color names plus 130 more). The table below lists them all, along with their hexadecimal values. Tip: The 16 basic color names are: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. Click on a color name (or a hex value) to view the color as the backgroundcolor along with different text colors:

Sorted by Color Name Same list sorted by hex values

HTML Scripts JavaScripts make HTML pages more dynamic and interactive. The HTML <script> Tag The <script> tag is used to define a client-side script, such as a JavaScript. The <script> element either contains scripting statements or it points to an external script file through the src attribute. The required type attribute specifies the MIME type of the script. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content. The script below writes Hello World! to the HTML output:

The HTML <noscript> Tag The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn t support clientside scripting. The <noscript> element can contain all the elements that you can find inside the <body> element of a normal HTML page. The content inside the <noscript> element will only be displayed if scripts are not supported, or are disabled in the user s browser:

A Taste of JavaScript (From Our JavaScript Tutorial) Here are some examples of what JavaScript can do: HTML Script Tags

HTML Entities Reserved characters in HTML must be replaced with character entities. HTML Entities Some characters are reserved in HTML. It is not possible to use the less than (<) or greater than (>) signs in your text, because the browser will mix them with tags. To actually display reserved characters, we must use character entities in the HTML source code. A character entity looks like this: To display a less than sign we must write: < or <

Tip: The advantage of using an entity name, instead of a number, is that the name is easier to remember. However, the disadvantage is that browsers may not support all entity names (the support for entity numbers is very good). Non-breaking Space A common character entity used in HTML is the non-breaking space ( ). Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them, before displaying the page. To add spaces to your text, you can use the character entity.

HTML Useful Character Entities Note: Entity names are case sensitive!

HTML Uniform Resource Locators A URL is another word for a web address. A URL can be composed of words, such as "w3schools.com", or an Internet Protocol (IP) address: 192.68.20.50. Most people enter the name of the website when surfing, because names are easier to remember than numbers. URL - Uniform Resource Locator Web browsers request pages from web servers by using a URL. When you click on a link in an HTML page, an underlying <a> tag points to an address on the world wide web. A Uniform Resource Locator (URL) is used to address a document (or other data) on the world wide web. A web address, like this: http://www.w3schools.com/html/default.asp follows these syntax rules:

Explanation: scheme - defines the type of Internet service. The most common type is http host - defines the domain host (the default host for http is www) domain - defines the Internet domain name, like w3schools.com port - defines the port number at the host (the default port number for http is 80) path - defines a path at the server (If omitted, the document must be stored at the root directory of the web site) filename - defines the name of a document/resource

Common URL Schemes The table below lists some common schemes:

URL Encoding URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding converts characters into a format that can be transmitted over the Internet. URL encoding replaces non ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.

URL Encoding Examples

QuickTime - Play WAV Audio

How to Convert from HTML to XHTML Add an XHTML <!DOCTYPE> to the first line of every page Add an xmlns attribute to the html element of every page Change all element names to lowercase Close all empty elements Change all attribute names to lowercase Quote all attribute values

CSS Tutorial

A Few Advantages Of CSS Over Tables

CSS Tutorial

What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to solve a problem External Style Sheets can save a lot of work External Style Sheets are stored in CSS files

CSS Syntax A CSS rule has two main parts: a selector, and one or more declarations: The selector is normally the HTML element you want to style. Each declaration consists of a property and a value. The property is the style attribute you want to change. Each property has a value.

CSS Example A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets: To make the CSS more readable, you can put one declaration on each line, like this:

CSS Comments Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. A CSS comment begins with "/*", and ends with "*/", like this:

CSS Id and Class The id and class Selectors In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class". The id Selector The id selector is used to specify a style for a single, unique element. The id selector uses the id attribute of the HTML element, and is defined with a "#". The style rule below will be applied to the element with id= para1 ;

Do NOT start an ID name with a number! It will not work in Mozilla/Firefox.

The class Selector The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements. This allows you to set a particular style for many HTML elements with the same class. The class selector uses the HTML class attribute, and is defined with a.. In the example below, all HTML elements with class="center" will be center-aligned:

You can also specify that only specific HTML elements should be affected by a class. In the example below, all p elements with class="center" will be center-aligned: Do NOT start a class name with a number! This is only supported in Internet Explorer.

CSS How To... When a browser reads a style sheet, it will format the document according to it. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style sheet Inline style

External Style Sheet An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section: An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a.css extension. An example of a style sheet file is shown below: Do not add a space between the property value and the unit (such as margin-left:20 px). The correct way is: margin-left:20px

Internal Style Sheet An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly! To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:

What is... <body bgcolor="#ff0000"> 1 <body style="background-color: #FF0000;"> 2 <head> <title>example<title> <style type="text/css"> body {background-color: #FF0000;} </style> </head> 3 <head> <title>my document</title> <link rel="stylesheet" type="text/css" href="style/style.css" /> </head> <body> 4

Multiple Style Sheets If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. For example, an external style sheet has these properties for the h3 selector: And an internal style sheet has these properties for the h3 selector: If the page with the internal style sheet also links to the external style sheet the properties for h3 will be: The color is inherited from the external style sheet and the textalignment and the font-size is replaced by the internal style sheet.

Multiple Styles Will Cascade into One Styles can be specified: inside an HTML element, inside the head section of an HTML page, in an external CSS file Tip: Even multiple external style sheets can be referenced inside a single HTML document. Cascading order Cascading Order What style will be used when there is more than one style specified for an HTML element? Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number one has the highest priority: 1. Inline style (inside an HTML element) 2. External and internal style sheets (in the head section) 3. Browser default So, an inline style (inside a specific HTML element) has the highest priority, which means that it will override a style defined inside the <head> tag, or in an external style sheet, or a browser

CSS Background Background Color The background-color property specifies the background color of an element. The background color of a page is defined in the body selector:

With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red"

Background Image The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this: Below is an example of a bad combination of text and background image. The text is almost not readable:

Background Image - Repeat Horizontally or Vertically By default, the background-image property repeats an image both horizontally and vertically. Some images should be repeated only horizontally or vertically, or they will look strange, like this: If the image is repeated only horizontally (repeat-x), the background will look better:

Background Image - Set position and norepeat When using a background image, use an image that does not disturb the text. Showing the image only once is specified by the background-repeat property:

Background - Shorthand property As you can see from the examples above, there are many properties to consider when dealing with backgrounds. To shorten the code, it is also possible to specify all the properties in one single property. This is called a shorthand property. The shorthand property for background is simply "background": When using the shorthand property the order of the property values is: background-color background-image background-repeat background-attachment background-position It does not matter if one of the property values is missing, as long as the ones that are present are in this order.

All CSS Background Properties

CSS Text Text Color The color property is used to set the color of the text. With CSS, a color is most often specified by: a HEX value - like "#ff0000" an RGB value - like "rgb(255,0,0)" a color name - like "red"

The default color for a page is defined in the body selector. For W3C compliant CSS: If you define the color property, you must also define the background-color property.

Text Alignment The text-align property is used to set the horizontal alignment of a text. Text can be centered, or aligned to the left or right, or justified. When text-align is set to "justify", each line is stretched so that every line has equal width, and the left and right margins are straight (like in magazines and newspapers).

Text Decoration The text-decoration property is used to set or remove decorations from text. The text-decoration property is mostly used to remove underlines from links for design purposes: It can also be used to decorate text: It is not recommended to underline text that is not a link, as this often confuses users.

Text Transformation The text-transform property is used to specify uppercase and lowercase letters in a text. It can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word.

Text Indentation The text-indentation property is used to specify the indentation of the first line of a text.

CSS Font CSS font properties define the font family, boldness, size, and the style of a text. On computer screens, sans-serif fonts are considered easier to read than serif fonts.

CSS Font Families In CSS, there are two types of font family names: generic family - a group of font families with a similar look (like "Serif" or "Monospace") font family - a specific font family (like "Times New Roman" or "Arial")

Font Family The font family of a text is set with the font-family property. The font-family property should hold several font names as a "fallback" system. If the browser does not support the first font, it tries the next font. Start with the font you want, and end with a generic family, to let the browser pick a similar font in the generic family, if no other fonts are available. Note: If the name of a font family is more than one word, it must be in quotation marks, like font-family: "Times New Roman". More than one font family is specified in a commaseparated list:

Font Style The font-style property is mostly used to specify italic text. This property has three values: normal - The text is shown normally italic - The text is shown in italics oblique - The text is "leaning" (oblique is very similar to italic, but less supported)

Font Size The font-size property sets the size of the text. Being able to manage the text size is important in web design. However, you should not use font size adjustments to make paragraphs look like headings, or headings look like paragraphs. Always use the proper HTML tags, like <h1> - <h6> for headings and <p> for paragraphs. The font-size value can be an absolute, or relative size. Absolute size: Sets the text to a specified size Does not allow a user to change the text size in all browsers (bad for accessibility reasons) Absolute size is useful when the physical size of the output is known Relative size: Sets the size relative to surrounding elements Allows a user to change the text size in browsers If you do not specify a font size, the default size for normal text, like paragraphs, is 16px (16px=1em).

Set Font Size With Pixels Setting the text size with pixels gives you full control over the text size: The example above allows Internet Explorer 9, Firefox, Chrome, Opera, and Safari to resize the text. Note: The example above does not work in IE, prior version 9. The text can be resized in all browsers using the zoom tool (however, this resizes the entire page, not just the text).

Set Font Size With Em To avoid the resizing problem with older versions of Internet Explorer, many developers use em instead of pixels. The em size unit is recommended by the W3C. 1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px. The size can be calculated from pixels to em using this formula: pixels/16=em In the example above, the text size in em is the same as the previous example in pixels. However, with the em size, it is possible to adjust the text size in all browsers. Unfortunately, there is still a problem with older versions of IE. The text becomes larger than it should when made larger, and smaller than it should when made smaller.

Use a Combination of Percent and Em The solution that works in all browsers, is to set a default font-size in percent for the <body> element: Our code now works great! It shows the same text size in all browsers, and allows all browsers to zoom or resize the text!

CSS Links Links can be styled in different ways. Styling Links Links can be styled with any CSS property (e.g. color, font-family, background, etc.). Special for links are that they can be styled differently depending on what state they are in. The four links states are: a:link - a normal, unvisited link a:visited - a link the user has visited a:hover - a link when the user mouses over it a:active - a link the moment it is clicked When setting the style for several link states, there are some order rules: a:hover MUST come after a:link and a:visited

Common Link Styles In the example above the link changes color depending on what state it is in. Lets go through some of the other common ways to style links: Text Decoration The text-decoration property is mostly used to remove underlines from links:

Background Color The background-color property specifies the background color for links:

CSS Lists The CSS list properties allow you to: Set different list item markers for ordered lists Set different list item markers for unordered lists Set an image as the list item marker List In HTML, there are two types of lists: unordered lists - the list items are marked with bullets ordered lists - the list items are marked with numbers or letters With CSS, lists can be styled further, and images can be used as the list item marker.

Different List Item Markers The type of list item marker is specified with the liststyle-type property: Some of the values are for unordered lists, and some for ordered lists.

An Image as The List Item Marker To specify an image as the list item marker, use the list-styleimage property:

List - Shorthand property It is also possible to specify all the list properties in one, single property. This is called a shorthand property. The shorthand property used for lists, is the list-style property: When using the shorthand property, the order of the values are: list-style-type list-style-position (for a description, see the CSS properties table below) list-style-image It does not matter if one of the values above are missing, as long as the rest are in the specified order.

All CSS List Properties

CSS Tables The look of an HTML table can be greatly improved with CSS:

Table Borders To specify table borders in CSS, use the border property. The example below specifies a black border for table, th, and td elements: Notice: that the table in the example above has double borders. This is because both the table and the th/td elements have separate borders. To display a single border for the table, use the border-collapse property.

Notice: that the table in the example above has double borders. This is because both the table and the th/td elements have separate borders. To display a single border for the table, use the border-collapse property. Collapse Borders

Table Width and Height Width and height of a table is defined by the width and height properties. The example below sets the width of the table to 100%, and the height of the th elements to 50px:

Table Text Alignment The text in a table is aligned with the text-align and vertical-align properties. The text-align property sets the horizontal alignment, like left, right, or center: The vertical-align property sets the vertical alignment, like top, bottom, or middle:

Table Padding To control the space between the border and content in a table, use the padding property on td and th elements:

Table Color The example below specifies the color of the borders, and the text and background color of th elements:

CSS Box Model The CSS Box Model All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout. The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content. The box model allows us to place a border around elements and space elements in relation to other elements. The image below illustrates the box model:

Content - The content of the box, where text and images appear In order to set the width and height of an element correctly in all browsers, you need to know Explanation of the different parts: Margin - Clears an area around the border. The margin does not have a background color, it is completely transparent Border - A border that goes around the padding and content. The border is affected by the background color of the box Padding - Clears an area around the content. The padding is affected by the background color of the box

Width and Height of an Element Important: When you set the width and height properties of an element with CSS, you just set the width and height of the content area. To calculate the full size of an element, you must also add the padding, borders and margins. The total width of the element in the example below is 300px: Let's do the math: 250px (width) + 20px (left + right padding) + 10px (left + right border) + 20px (left + right margin) = 300px

Assume that you had only 250px of space. Let's make an element with a total width of 250px: The total width of an element should be calculated like this: Total element width = width + left padding + right padding + left border + right border + left margin + right margin The total height of an element should be calculated like this: Total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin

Browsers Compatibility Issue IE8 and earlier versions of IE, included padding and border in the width property. To fix this problem, add a <!DOCTYPE html> to the HTML page.

CSS Border Border Style The border-style property specifies what kind of border to display. None of the border properties will have ANY effect unless the border-style property is set!

border-style values: none: Defines no border

Border Width The border-width property is used to set the width of the border. The width is set in pixels, or by using one of the three predefined values: thin, medium, or thick. Note: The "border-width" property does not work if it is used alone. Use the "border-style" property to set the borders first.

Border Color The border-color property is used to set the color of the border. The color can be set by: name - specify a color name, like "red" RGB - specify a RGB value, like "rgb(255,0,0)" Hex - specify a hex value, like "#ff0000" You can also set the border color to "transparent". Note: The "border-color" property does not work if it is used alone. Use the "border-style" property to set the borders first.

Border - Individual sides In CSS it is possible to specify different borders for different sides: The example above can also be set with a single property:

The border-style property can have from one to four values. border-style:dotted solid double dashed; top border is dotted right border is solid bottom border is double left border is dashed border-style:dotted solid double; top border is dotted right and left borders are solid bottom border is double border-style:dotted solid; top and bottom borders are dotted right and left borders are solid border-style:dotted; all four borders are dotted The border-style property is used in the example above. However, it

Border - Shorthand property As you can see from the examples above, there are many properties to consider when dealing with borders. To shorten the code, it is also possible to specify all the individual border properties in one property. This is called a shorthand property. The border property is a shorthand for the following individual border properties: border-width border-style (required) border-color

CSS Outlines An outline is a line that is drawn around elements (outside the borders) to make the element "stand out". The outline properties specify the style, color, and width of an outline.

CSS Outline An outline is a line that is drawn around elements (outside the borders) to make the element "stand out". However, the outline property is different from the border property. The outline is not a part of an element's dimensions; the element's total width and height is not affected by the width of the outline.

All CSS Outline Properties The number in the "CSS" column indicates in which CSS version the property is defined (CSS1 or CSS2).

CSS Margin The CSS margin properties define the space around elements. Margin The margin clears an area around an element (outside the border). The margin does not have a background color, and is completely transparent. The top, right, bottom, and left margin can be changed independently using separate properties. A shorthand margin property can also be used, to change all margins at once. Possible Values It is possible to use negative values, to overlap content.

Margin - Individual sides In CSS, it is possible to specify different margins for different sides:

Margin - Shorthand property To shorten the code, it is possible to specify all the margin properties in one property. This is called a shorthand property. The shorthand property for all the margin properties is "margin":

The margin property can have from one to four values. margin:25px 50px 75px 100px; top margin is 25px right margin is 50px bottom margin is 75px left margin is 100px margin:25px 50px 75px; top margin is 25px right and left margins are 50px bottom margin is 75px margin:25px 50px; top and bottom margins are 25px right and left margins are 50px margin:25px; all four margins are 25px

CSS Padding The CSS padding properties define the space between the element border and the element content. Padding The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element. The top, right, bottom, and left padding can be changed independently using separate properties. A shorthand padding property can also be used, to change all paddings at once. Possible Values

Padding - Individual sides In CSS, it is possible to specify different padding for different sides:

Padding - Shorthand property To shorten the code, it is possible to specify all the padding properties in one property. This is called a shorthand property. The shorthand property for all the padding properties is "padding":

The padding property can have from one to four values. padding:25px 50px 75px 100px; top padding is 25px right padding is 50px bottom padding is 75px left padding is 100px padding:25px 50px 75px; top padding is 25px right and left paddings are 50px bottom padding is 75px padding:25px 50px; top and bottom paddings are 25px right and left paddings are 50px padding:25px; all four paddings are 25px

CSS Grouping and Nesting Selectors Grouping Selectors In style sheets there are often elements with the same style. To minimize the code, you can group selectors. Separate each selector with a comma.

In the example below we have grouped the selectors from the code above:

Nesting Selectors It is possible to apply a style for a selector within a selector. In the example below, one style is specified for all p elements, one style is specified for all elements with class="marked", and a third style is specified only for p elements within elements with class="marked":

CSS Display - Block and Inline Elements A block element is an element that takes up the full width available, and has a line break before and after it. Examples of block elements: <h1> <p> <div> An inline element only takes up as much width as necessary, and does not force line breaks. Examples of inline elements: <span> <a>

Changing How an Element is Displayed Changing an inline element to a block element, or vice versa, can be useful for making the page look a specific way, and still follow web standards. The following example displays list items as inline elements: The following example displays span elements as block elements: Note: Changing the display type of an element changes only how the element is displayed, NOT what kind of element it is. For example: An inline element set to display:block is not allowed to have a block element nested inside of it.

CSS Positioning Positioning The CSS positioning properties allow you to position an element. It can also place an element behind another, and specify what should happen when an element's content is too big. Elements can be positioned using the top, bottom, left, and right properties. However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method. There are four different positioning methods.

Static Positioning HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page. Static positioned elements are not affected by the top, bottom, left, and right properties. Fixed Positioning An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled: Note: IE7 and IE8 support the fixed value only if a!doctype is specified. Fixed positioned elements are removed from the normal flow. The document and other elements behave like the fixed positioned

Fixed positioned elements can overlap other elements. Relative Positioning A relative positioned element is positioned relative to its normal position. The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow.

Relatively positioned elements are often used as container blocks for absolutely positioned elements.

Absolute Positioning An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>: Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist. Absolutely positioned elements can overlap other elements.

Overlapping Elements When elements are positioned outside the normal flow, they can overlap other elements. The z-index property specifies the stack order of an element (which element should be placed in front of, or behind, the others). An element can have a positive or negative stack order: An element with greater stack order is always in front of an element with a lower stack order. Note: If two positioned elements overlap, without a z-index specified, the element positioned last in the HTML code will be shown on top.

CSS Float What is CSS Float? With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it. Float is very often used for images, but it is also useful when working with layouts.

How Elements Float Elements are floated horizontally, this means that an element can only be floated left or right, not up or down. A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element. The elements after the floating element will flow around it. The elements before the floating element will not be affected. If an image is floated to the right, a following text flows around it, to the left:

Floating Elements Next to Each Other If you place several floating elements after each other, they will float next to each other if there is room. Here we have made an image gallery using the float property:

Turning off Float - Using Clear Elements after the floating element will flow around it. To avoid this, use the clear property. The clear property specifies which sides of an element other floating elements are not allowed. Add a text line into the image gallery, using the clear property:

CSS Horizontal Align Aligning Block Elements A block element is an element that takes up the full width available, and has a line break before and after it. Examples of block elements: <h1> <p> <div>

Center Aligning Using the margin Property Block elements can be aligned by setting the left and right margins to "auto". Note: Using margin:auto will not work in IE8 and earlier, unless a!doctype is declared. Setting the left and right margins to auto specifies that they should split the available margin equally. The result is a centered element: Tip: Aligning has no effect if the width is 100%.

Left and Right Aligning Using the position Property One method of aligning elements is to use absolute positioning: Note: Absolute positioned elements are removed from the normal flow, and can overlap elements.

Crossbrowser Compatibility Issues When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element. This is to avoid visual differences in different browsers. There is a problem with IE8 and earlier, when using the position property. If a container element (in our case <div class="container">) has a specified width, and the!doctype declaration is missing, IE8 and earlier versions will add a 17px margin on the right side. This seems to be space reserved for a scrollbar. Always set the!doctype declaration when using the position property:

Left and Right Aligning Using the float Property One method of aligning elements is to use the float property:

Crossbrowser Compatibility Issues When aligning elements like this, it is always a good idea to predefine margin and padding for the <body> element. This is to avoid visual differences in different browsers. There is a problem with IE8 and earlier when using the float property. If the!doctype declaration is missing, IE8 and earlier versions will add a 17px margin on the right side. This seems to be space reserved for a scrollbar. Always set the!doctype declaration when using the float property:

CSS Pseudo-classes CSS pseudo-classes are used to add special effects to some selectors. Syntax The syntax of pseudo-classes: CSS classes can also be used with pseudo-classes:

Anchor Pseudo-classes Links can be displayed in different ways in a CSSsupporting browser: Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective!! Note: a:active MUST come after a:hover in the CSS definition in order to be effective!! Note: Pseudo-class names are not case-sensitive.

Pseudo-classes and CSS Classes Pseudo-classes can be combined with CSS classes: If the link in the example above has been visited, it will be displayed in red.

CSS - The :first-child Pseudo-class The :first-child pseudo-class matches a specified element that is the first child of another element. Note: For :first-child to work in IE8 and earlier, a <!DOCTYPE> must be declared. Match the first <p> element In the following example, the selector matches any <p> element that is the first child of any element:

Match the first <i> element in all <p> elements In the following example, the selector matches the first <i> element in all <p> elements:

Match all <i> elements in all first child <p> elements In the following example, the selector matches all <i> elements in <p> elements that are the first child of another element:

CSS - The :lang Pseudo-class The :lang pseudo-class allows you to define special rules for different languages. Note: IE8 supports the :lang pseudo-class only if a <!DOCTYPE> is specified. In the example below, the :lang class defines the quotation marks for q elements with lang="no":

The :first-line Pseudo-element The "first-line" pseudo-element is used to add a special style to the first line of a text. In the following example the browser formats the first line of text in a p element according to the style in the "first-line" pseudo-element (where the browser breaks the line, depends on the size of the browser window):

Note: The "first-line" pseudo-element can only be used with block-level elements. Note: The following properties apply to the "first-line" pseudo-element: font properties color properties background properties word-spacing letter-spacing text-decoration vertical-align text-transform line-height clear

The :first-letter Pseudo-element The "first-letter" pseudo-element is used to add a special style to the first letter of a text:

Note: The "first-letter" pseudo-element can only be used with blocklevel elements. Note: The following properties apply to the "first-letter" pseudoelement: font properties color properties background properties margin properties padding properties border properties text-decoration vertical-align (only if "float" is "none") text-transform line-height float clear

Pseudo-elements and CSS Classes Pseudo-elements can be combined with CSS classes: The example above will display the first letter of all paragraphs with class="article", in red.

CSS - The :before Pseudo-element The ":before" pseudo-element can be used to insert some content before the content of an element. The following example inserts an image before each <h1> element:

CSS - The :after Pseudo-element The ":after" pseudo-element can be used to insert some content after the content of an element. The following example inserts an image after each <h1> element:

All CSS Pseudo Classes/Elements

A navigation bar needs standard HTML as a base. In our examples we will build the navigation bar from a standard HTML list. A navigation bar is basically a list of links, so using the <ul> and <li> elements makes perfect sense: CSS Navigation Bar Demo: Navigation Bar Navigation Bars Having easy-to-use navigation is important for any web site. With CSS you can transform boring HTML menus into good-looking navigation bars. Navigation Bar = List of Links

Now let's remove the bullets and the margins and padding from the list: Example explained: list-style-type:none - Removes the bullets. A navigation bar does not need list markers Setting margins and padding to 0 to remove browser default settings The code in the example above is the standard code used in both vertical, and horizontal navigation bars.

Vertical Navigation Bar To build a vertical navigation bar we only need to style the <a> elements, in addition to the code above: Example explained: display:block - Displaying the links as block elements makes the whole link area clickable (not just the text), and it allows us to specify the width width:60px - Block elements take up the full width available by default.we want to specify a 60 px width

Note: Always specify the width for <a> elements in a vertical navigation bar. If you omit the width, IE6 can produce unexpected results. <!DOCTYPE html> <html> <head> <style> ul { list-style-type:none; margin:0; padding:0; } a:link,a:visited { display:block; font-weight:bold; color:#ffffff; background-color:#98bf21; width:120px; text-align:center; padding:4px; text-decoration:none; text-transform:uppercase; } a:hover,a:active { background-color:#7a991a; } </style> </head> <body> <ul> <li><a href="#home">home</a></li> <li><a href="#news">news</a></li> <li><a href="#contact">contact</a></li> <li><a href="#about">about</a></li> </ul> </body> </html>

Horizontal Navigation Bar There are two ways to create a horizontal navigation bar. Using inline or floating list items. Both methods work fine, but if you want the links to be the same size, you have to use the floating method. Inline List Items One way to build a horizontal navigation bar is to specify the <li> elements as inline, in addition to the "standard" code above: Example explained: display:inline; - By default, <li> elements are block elements. Here, we remove the line breaks before and after each list item, to display them on one line

Example explained: float:left - use float to get block elements to slide next to each other display:block - Displaying the links as block elements makes the whole link area clickable (not just the text), and it allows us to specify the width width:60px - Since block elements take up the full width available, they cannot float next to each other. We specify the width of the links to Floating List Items In the example above the links have different widths. For all the links to have an equal width, float the <li> elements and specify a width for the <a> elements

<!DOCTYPE html> <html> <head> <style> ul { list-style-type:none; margin:0; padding:0; overflow:hidden; } li { float:left; } a:link,a:visited { display:block; width:120px; font-weight:bold; color:#ffffff; background-color:#98bf21; text-align:center; padding:4px; text-decoration:none; text-transform:uppercase; } a:hover,a:active { background-color:#7a991a; } </style> </head> <body> <ul> <li><a href="#home">home</a></li> <li><a href="#news">news</a></li> <li><a href="#contact">contact</a></li> <li><a href="#about">about</a></li> </ul> </body> </html>

CSS Image Gallery CSS can be used to create an image gallery.

Image Gallery The following image gallery is created with CSS:

<html> <head> <style> div.img { margin:2px; border:1px solid #0000ff; height:auto; width:auto; float:left; text-align:center; } div.img img { display:inline; margin:3px; border:1px solid #ffffff; } div.img a:hover img { border:1px solid #0000ff; } div.desc { text-align:center; font-weight:normal; width:120px; margin:2px; } </style> </head> <body> <div class="img"> <a target="_blank" href="klematis_big.htm"> <img src="klematis_small.jpg" alt="klematis" width="110" height="90"> </a> <div class="desc">add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="klematis2_big.htm"> <img src="klematis2_small.jpg" alt="klematis" width="110" height="90"> </a> <div class="desc">add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="klematis3_big.htm"> <img src="klematis3_small.jpg" alt="klematis" width="110" height="90"> </a> <div class="desc">add a description of the image here</div> </div> <div class="img"> <a target="_blank" href="klematis4_big.htm"> <img src="klematis4_small.jpg" alt="klematis" width="110" height="90"> </a> <div class="desc">add a description of the image here</div> </div> </body> </html>

CSS Image Opacity / Transparency Creating transparent images with CSS is easy. Note: The CSS opacity property is a part of the W3C CSS3 recommendation. Example 1 - Creating a Transparent Image The CSS3 property for transparency is opacity. First we will show you how to create a transparent image with CSS. Regular image: The same image with transparency:

Look at the following CSS: IE9, Firefox, Chrome, Opera, and Safari use the property opacity for transparency. The opacity property can take a value from 0.0-1.0. A lower value makes the element more transparent. IE8 and earlier use filter:alpha(opacity=x). The x can take a value from 0-100. A lower value makes the element more transparent.

Example 2 - Image Transparency - Hover Effect Mouse over the images: The CSS looks like this:

The first CSS block is similar to the code in Example 1. In addition, we have added what should happen when a user hover over one of the images. In this case we want the image to NOT be transparent when the user hover over it. The CSS for this is: opacity=1. IE8 and earlier: filter:alpha(opacity=100). When the mouse pointer moves away from the image, the image will be transparent again.

Example 3 - Text in Transparent Box The source code looks like this:

First, we create a div element (class="background") with a fixed height and width, a background image, and a border. Then we create a smaller div (class="transbox") inside the first div element. The "transbox" div have a fixed width, a background color, and a border - and it is transparent. Inside the transparent div, we add some text inside a p element.

Image Sprites - Create a Navigation List We want to use the sprite image ("img_navsprites.gif") to create a navigation list. We will use an HTML list, because it can be a link and also supports a background image:

Example explained: #navlist{position:relative;} - position is set to relative to allow absolute positioning inside it #navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;} - margin and padding is set to 0, list-style is removed, and all list items are absolute positioned #navlist li, #navlist a{height:44px;display:block;} - the height of all the images are 44px Now start to position and style for each specific part: #home{left:0px;width:46px;} - Positioned all the way to the left, and the width of the image is 46px #home{background:url(img_navsprites.gif) 0 0;} - Defines the background image and its position (left 0px, top 0px) #prev{left:63px;width:43px;} - Positioned 63px to the right (#home width 46px + some extra space between items), and the width is 43px. #prev{background:url('img_navsprites.gif') -47px 0;} - Defines the background image 47px to the right (#home width 46px + 1px line divider) #next{left:129px;width:43px;}- Positioned 129px to the right (start of #prev is 63px + #prev width 43px + extra space), and the width is 43px. #next{background:url('img_navsprites.gif') no-repeat -91px 0;} - Defines the background image 91px to the right (#home width 46px +

CSS Media Types With media types a page can have one layout for screen, one for print, one for handheld devices, etc. Media Types Some CSS properties are only designed for a certain media. For example the "voice-family" property is designed for aural user agents. Some other properties can be used for different media types. For example, the "font-size" property can be used for both screen and print media, but perhaps with different values. A document usually needs a larger font-size on a screen than on paper, and sans-serif fonts are easier to read on the screen, while serif fonts are easier to read on paper.

The @media Rule The @media rule allows different style rules for different media in the same style sheet. The style in the example below tells the browser to display a 14 pixels Verdana font on the screen. But if the page is printed, it will be in a 10 pixels Times font. Notice that the font-weight is set to bold, both on screen and on paper: See it yourself! Print this page (or open Print Preview), and you will see that the paragraph under "Media Types" will be displayed in another font, and have a smaller font size than the rest of the text.

Other Media Types Note: The media type names are not case-sensitive.