Module 1 HTML 5 and CSS Lecture 01 Introduction to HTML Introduction to HTML
Total Page:16
File Type:pdf, Size:1020Kb
Nagarjuna College of Engineering and Technology Information Science and Engineering Module 1 HTML 5 and CSS Lecture 01 Introduction to HTML Introduction to HTML Hypertext Markup Language (HTML) documents are simply text documents with a specific form ◦ Documents comprised of content and markup tags ◦ Content: actual information being conveyed ◦ The markup tags tell the Web browser how to display the page ◦ An HTML file must have an htm or html file extension ◦ An HTML file can be created using a simple text editor Lecture 02 Key components of HTML document Key components of HTML document An HTML document is composed of three parts: a line containing HTML version information, a declarative header section (delimited by the HEAD element), a body, which contains the document's actual content. The body may be implemented by the BODY element. An HTML page may contain Doctype, Comments, Elements or Tags, Attributes, Frames which may contain other HTML pages. DOCTYPE A Doctype declares the version of an HTML document. This needs to be the first thing in your document, before the <html> or <head> elements. Also, there is no closing tag. Doctype declaration: <!DOCTYPE html> OR <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> Comments We can add comments to your HTML source by using the following syntax: <!-- Write your comments here --> Comments are not displayed by the browser. Example: <!-- This is a comment --> <p>This is a paragraph.</p> <!-- Remember to add more information here --> Lecture 03 HTML elements, Headers, Linking, Images HTML Elements An HTML element usually consists of a start tag and an end tag, with the content inserted in between: <tagname>Content goes here...</tagname> The HTML element is everything from the start tag to the end tag: <p>My first paragraph.</p> Start tag Element content End tag <p> My first paragraph </p> Example: <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> •The <html> element defines the whole document. •It has a start tag <html> and an end tag </html>. •Inside the <html> element is the <body> element. •The <body> element defines the document body. •It has a start tag <body> and an end tag </body>. Inside the <body> element is two other HTML elements: <h1> and <p>. The <h1> element defines a heading. It has a start tag <h1> and an end tag </h1>. The element content is: My First Heading. The <p> element defines a paragraph. It has a start tag <p> and an end tag </p>. The element content is: My first paragraph HTML Attributes All HTML elements can have attributes Attributes provide additional information about an element Attributes are always specified in the start tag Attributes usually come in name/value pairs like: name="value" Headers Headings are defined with the <h1> to <h6> tags. <h1> defines the most important heading. <h6> defines the least important heading. Example: <h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6> HTML Horizontal Rules The <hr> tag defines a 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: Example: <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> HTML Links HTML links are hyperlinks. We can click on a link and jump to another document. A link does not have to be text. It can be an image or any other HTML element. Syntax: Hyperlinks are defined with the HTML <a> tag: <a href="url">link text</a> -The href attribute specifies the destination address of the link. -The link text is the visible part. Clicking on the link text will send us to the specified address. Example: <!DOCTYPE html> <html> <body> <h2>Local Links</h2> <p><a href="https://www.w3.org/">W3C</a> is a link to a website on the World Wide Web.</p> </body> </html> HTML Links - The target Attribute The target attribute specifies where to open the linked document. The target attribute can have one of the following values: _blank - Opens the linked document in a new window or tab _self - Opens the linked document in the same window/tab as it was clicked (this is default) _parent - Opens the linked document in the parent frame _top - Opens the linked document in the full body of the window <a href="https://www.w3schools.com/" target="_blank"> Visit W3Schools!</a> Images Images can improve the design and the appearance of a web page. We can insert any image in our web page by using <img> tag. Following is the simple syntax to use this tag. <img src = "Image URL" ... attributes-list/> Example: <!DOCTYPE html> <html> <body> <h2>Image Links</h2> <p>The image is a link. You can click on it.</p> <img src="smiley.gif" alt="HTML tutorial" width:42px height:42px"> </body> </html> The <img> tag is empty, it contains attributes only, and does not have a closing tag. The src attribute specifies the URL (web address) of the image The alt attribute provides an alternate text for an image, if the user for some reason cannot view it (because of slow connection, an error in the src attribute). If a browser cannot find an image, it will display the value of the alt attribute, We can use the width and height attributes to specify the width and height of an image and always defines the width and height of the image in pixels. HTML Links - Image as Link It is common to use images as links: <!DOCTYPE html> <html> <body> <h2>Image Links</h2> <p>The image is a link. You can click on it.</p> <a href="default.asp"> <img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0"> </a> </body> </html> Lecture 04 Unordered Lists, and Nested and ordered Lists LISTS HTML offers web authors three ways for specifying lists of information. All lists must contain one or more list elements. Lists may contain − <ul> − An unordered list. This will list items using plain bullets. <ol> − An ordered list. This will use different schemes of numbers to list your items. <dl> − A definition list. This arranges your items in the same way as they are arranged in a dictionary. HTML Unordered Lists An unordered list is a collection of related items that have no special order or sequence. This list is created by using HTML <ul> tag. Each item in the list is marked with a bullet. <!DOCTYPE html> <html> <head> <title>HTML Unordered List</title> </head> <body> <ul> <li>Beetroot</li> Output: <li>Ginger</li> <li>Potato</li> •Beetroot <li>Radish</li> •Ginger •Potato </ul> •Radish </body> </html> The type Attribute We can use type attribute for <ul> tag to specify the type of bullet to display. By default, it is a disc. Following are the possible options: <ul type = "square"> <ul type = "disc"> <ul type = "circle"> Example: <body> <ul type = "square"> <li>Beetroot</li> Output: <li>Ginger</li> <li>Potato</li> .Beetroot <li>Radish</li> .Ginger .Potato </ul> .Radish </body> HTML Ordered Lists If we are required to put the items in a numbered list instead of bulleted, then HTML ordered list will be used. This list is created by using <ol> tag. The numbering starts at one and is incremented by one for each successive ordered list element tagged with <li>. <!DOCTYPE html> <html> <head> <title>HTML Ordered List</title> </head> <body> <ol> Output: <li>Beetroot</li> <li>Ginger</li> 1. Beetroot <li>Potato</li> 2. Ginger <li>Radish</li> 3. Potato </ol> 4. Radish </body> </html> The type Attribute The type attribute can be used in <ol> tag to specify the type of numbering to display. By default, it is a number. Following are the possible options − <ol type = “1”> - Default-Case Numerals. <ol type = "I"> - Upper-Case Numerals. <ol type = "i"> - Lower-Case Numerals. <ol type = "A"> - Upper-Case Letters. <ol type = "a"> - Lower-Case Letters. HTML Description Lists HTML also supports description lists. A description list is a list of terms, with a description of each term. The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd> tag describes each term: <!DOCTYPE html> <html> <body> <h2>A Description List</h2> <dl> <dt>Coffee</dt> Output: <dd>- black hot drink</dd> <dt>Milk</dt> A Description List <dd>- white cold drink</dd> Coffee </dl> - black hot drink </body> Milk - white cold drink </html> Nested HTML Lists <!DOCTYPE html> <html> <body> <h2>A Nested List</h2> <p>List can be nested (lists inside lists):</p> <ol> <li>Coffee</li> <li>Tea Output: <ol> <li>Black tea</li> A Nested List <li>Green tea</li> List can be nested (lists </ol> inside lists): </li> 1.Coffee <li>Milk</li> 2.Tea </ol> 1.Black tea 2.Green tea </body> 3.Milk </html> Lecture 05 HTML Tables and Formatting HTML Tables An HTML table is defined with the <table> tag. Each table row is defined with the <tr> tag. A table header is defined with the <th> tag. By default, table headings are bold and centered. A table data/cell is defined with the <td> tag. The <td> elements are the data containers of the table. They can contain all sorts of HTML elements; text, images, lists, other tables, etc. <!DOCTYPE html> <html> <head> <title>HTML Tables</title> </head> <body> <table border = "1" > <tr> <td>Row 1, Column 1 </td> <td>Row 1, Column 2</td> </tr> <tr> <td>Row 2, Column 1 </td> <td>Row 2, Column 2</td> </tr> </table> </body> </html> the border is an attribute of <table> tag and it is used to put a border across all the cells.